forked from gitea/gitea
finish delete ssh key and delete account. all with confirm.
This commit is contained in:
parent
0754dd2f95
commit
f6e32b1b08
|
@ -175,8 +175,8 @@ func DeleteUser(user *User) error {
|
||||||
|
|
||||||
// EncodePasswd encodes password to safe format.
|
// EncodePasswd encodes password to safe format.
|
||||||
func (user *User) EncodePasswd() error {
|
func (user *User) EncodePasswd() error {
|
||||||
newPasswd, err := scrypt.Key([]byte(user.Passwd), []byte(UserPasswdSalt), 16384, 8, 1, 64)
|
var err error
|
||||||
user.Passwd = fmt.Sprintf("%x", newPasswd)
|
user.Passwd, err = EncodePasswd(user.Passwd)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +184,14 @@ func UserPath(userName string) string {
|
||||||
return filepath.Join(RepoRootPath, userName)
|
return filepath.Join(RepoRootPath, userName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func EncodePasswd(rawPasswd string) (string, error) {
|
||||||
|
newPasswd, err := scrypt.Key([]byte(rawPasswd), []byte(UserPasswdSalt), 16384, 8, 1, 64)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%x", newPasswd), nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetUserByKeyId(keyId int64) (*User, error) {
|
func GetUserByKeyId(keyId int64) (*User, error) {
|
||||||
user := new(User)
|
user := new(User)
|
||||||
has, err := orm.Sql("select a.* from user as a, public_key as b where a.id = b.owner_id and b.id=?", keyId).Get(user)
|
has, err := orm.Sql("select a.* from user as a, public_key as b where a.id = b.owner_id and b.id=?", keyId).Get(user)
|
||||||
|
|
|
@ -302,32 +302,23 @@ html, body {
|
||||||
/* gogits user ssh keys */
|
/* gogits user ssh keys */
|
||||||
|
|
||||||
#gogs-ssh-keys .list-group-item {
|
#gogs-ssh-keys .list-group-item {
|
||||||
line-height: 48px;
|
padding: 15px 0;
|
||||||
border-bottom: 1px solid #DDD;
|
border-bottom: 1px solid #DDD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#gogs-ssh-keys .list-group-item .delete {
|
||||||
|
margin: -5px 50px 0;
|
||||||
|
}
|
||||||
|
|
||||||
#gogs-ssh-keys .list-group-item:after {
|
#gogs-ssh-keys .list-group-item:after {
|
||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
|
||||||
#gogs-ssh-keys .list-group-item:hover a.delete {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
#gogs-ssh-keys .name {
|
#gogs-ssh-keys .name {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
#gogs-ssh-keys .list-group-item a.delete {
|
|
||||||
float: right;
|
|
||||||
color: white;
|
|
||||||
cursor: pointer;
|
|
||||||
margin-top: 10px;
|
|
||||||
border-radius: 3px;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#gogs-ssh-keys .print {
|
#gogs-ssh-keys .print {
|
||||||
padding-left: 1em;
|
padding-left: 1em;
|
||||||
color: #888;
|
color: #888;
|
||||||
|
|
|
@ -99,8 +99,9 @@ function initRegister() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function initUserSetting(){
|
function initUserSetting(){
|
||||||
$('#gogs-ssh-keys').on("click",".delete",function(){
|
$('#gogs-ssh-keys .delete').confirmation({
|
||||||
var $this = $(this);
|
singleton: true,
|
||||||
|
onConfirm: function(e, $this){
|
||||||
Gogits.ajaxDelete("",{"id":$this.data("del")},function(json){
|
Gogits.ajaxDelete("",{"id":$this.data("del")},function(json){
|
||||||
if(json.ok){
|
if(json.ok){
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
@ -108,6 +109,6 @@ function initUserSetting(){
|
||||||
alert(json.err);
|
alert(json.err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
File diff suppressed because one or more lines are too long
|
@ -157,18 +157,28 @@ func Delete(ctx *middleware.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rawPasswd := ctx.Query("password")
|
||||||
|
encodedPwd, _ := models.EncodePasswd(rawPasswd)
|
||||||
|
if len(encodedPwd) == 0 || encodedPwd != ctx.User.Passwd {
|
||||||
|
ctx.Data["HasError"] = true
|
||||||
|
ctx.Data["ErrorMsg"] = "Your password error. Make sure you are owner of this account."
|
||||||
|
} else {
|
||||||
if err := models.DeleteUser(ctx.User); err != nil {
|
if err := models.DeleteUser(ctx.User); err != nil {
|
||||||
ctx.Data["HasError"] = true
|
ctx.Data["HasError"] = true
|
||||||
switch err.Error() {
|
switch err {
|
||||||
case models.ErrUserOwnRepos.Error():
|
case models.ErrUserOwnRepos:
|
||||||
ctx.Data["ErrorMsg"] = "Your account still have ownership of repository, you have to delete or transfer them first."
|
ctx.Data["ErrorMsg"] = "Your account still have ownership of repository, you have to delete or transfer them first."
|
||||||
default:
|
default:
|
||||||
ctx.Handle(200, "user.Delete", err)
|
ctx.Handle(200, "user.Delete", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ctx.Render.Redirect("/")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Render.Redirect("/", 302)
|
ctx.Render.HTML(200, "user/delete", ctx.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -13,22 +13,33 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="gogs-user-setting-container" class="col-md-9">
|
<div id="gogs-user-setting-container" class="col-md-9">
|
||||||
<form action="/user/delete" method="post" class="form-horizontal" id="gogs-user-delete">
|
|
||||||
<h4>Delete Account</h4>
|
<h4>Delete Account</h4>
|
||||||
<p class="alert alert-danger">{{if not .HasError}}The operation will delete your account permanently. Sorry to see you go, but we know you'll back soon.{{else}}{{.ErrorMsg}}{{end}}</p>
|
<p class="alert alert-danger">{{if not .HasError}}The operation will delete your account permanently. Sorry to see you go, but we know you'll back soon.{{else}}{{.ErrorMsg}}{{end}}</p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="col-md-3">
|
<button type="submit" class="btn btn-danger btn-lg" href="#delete-account-modal" id="gogs-delete-account" data-toggle="modal">Delete Account</button>
|
||||||
<button type="submit" class="btn btn-danger btn-lg">Delete Account</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="modal fade" id="delete-account-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<form action="/user/delete" method="post" class="modal-content" id="gogs-user-delete">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
<h4 class="modal-title" id="myModalLabel">Delete Account</h4>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Make sure your are owner of this account. Please enter your password.<strong class="text-danger">*</strong></label>
|
||||||
|
<input name="password" class="form-control" type="password" placeholder="Type your account password" required="required">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||||
|
<button type="submit" class="btn btn-danger">Delete</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
|
||||||
$(function(){
|
|
||||||
$('#gogs-user-delete').on('submit',function(){
|
|
||||||
return confirm("Are you sure ?");
|
|
||||||
})
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{{template "base/footer" .}}
|
{{template "base/footer" .}}
|
|
@ -18,12 +18,14 @@
|
||||||
<h4>SSH Keys</h4>{{if .AddSSHKeySuccess}}
|
<h4>SSH Keys</h4>{{if .AddSSHKeySuccess}}
|
||||||
<p class="alert alert-success">New SSH Key has been added !</p>{{else if .HasError}}<p class="alert alert-danger">{{.ErrorMsg}}</p>{{end}}
|
<p class="alert alert-success">New SSH Key has been added !</p>{{else if .HasError}}<p class="alert alert-danger">{{.ErrorMsg}}</p>{{end}}
|
||||||
<ul id="gogs-ssh-keys-list" class="list-group">
|
<ul id="gogs-ssh-keys-list" class="list-group">
|
||||||
<li class="list-group-item"><span class="name">SSH Key's name</span></li>{{range .Keys}}
|
<li class="list-group-item"><span class="name">SSH Key's name</span></li>
|
||||||
|
{{range .Keys}}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<span class="name">{{.Name}}</span>
|
<span class="name">{{.Name}}</span>
|
||||||
<span class="print">({{.Fingerprint}})</span>
|
<span class="print">({{.Fingerprint}})</span>
|
||||||
<a href="#" class="btn btn-link btn-danger right delete" rel="{{.Id}}" data-del="{{.Id}}">Delete</a>
|
<button href="#" class="btn btn-danger delete pull-right" rel="{{.Id}}" data-del="{{.Id}}">Delete</button>
|
||||||
</li>{{end}}
|
</li>
|
||||||
|
{{end}}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<a class="btn btn-link btn-primary" href="#ssh-add-modal" id="gogs-ssh-add" data-toggle="modal">Add SSH Key</a>
|
<a class="btn btn-link btn-primary" href="#ssh-add-modal" id="gogs-ssh-add" data-toggle="modal">Add SSH Key</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in New Issue