diff options
author | Unknwon <u@gogs.io> | 2015-08-20 17:11:29 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-08-20 17:11:29 +0800 |
commit | 062adbed8a8a9cb83cd172b5a6e232e75af89f2d (patch) | |
tree | 07a35a3c9dca8d1be54614b006b7c0487a9cdb62 /routers | |
parent | 9b01a3501b8c1897a9c02bf82dcc169a20b9a51f (diff) | |
download | gitea-062adbed8a8a9cb83cd172b5a6e232e75af89f2d.tar.gz gitea-062adbed8a8a9cb83cd172b5a6e232e75af89f2d.zip |
add confirmation to delete ssh key
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/setting.go | 7 | ||||
-rw-r--r-- | routers/user/setting.go | 94 |
2 files changed, 53 insertions, 48 deletions
diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 551ba11513..61ac6deb1d 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -677,6 +677,13 @@ func SettingsDeployKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsKeys"] = true + keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID) + if err != nil { + ctx.Handle(500, "ListDeployKeys", err) + return + } + ctx.Data["Deploykeys"] = keys + if ctx.HasError() { ctx.HTML(200, DEPLOY_KEYS) return diff --git a/routers/user/setting.go b/routers/user/setting.go index c8b9f130d4..8afc56ac49 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -269,12 +269,12 @@ func SettingsSSHKeys(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsSettingsSSHKeys"] = true - var err error - ctx.Data["Keys"], err = models.ListPublicKeys(ctx.User.Id) + keys, err := models.ListPublicKeys(ctx.User.Id) if err != nil { - ctx.Handle(500, "ssh.ListPublicKey", err) + ctx.Handle(500, "ListPublicKeys", err) return } + ctx.Data["Keys"] = keys ctx.HTML(200, SETTINGS_SSH_KEYS) } @@ -283,66 +283,58 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsSettingsSSHKeys"] = true - var err error - ctx.Data["Keys"], err = models.ListPublicKeys(ctx.User.Id) + keys, err := models.ListPublicKeys(ctx.User.Id) if err != nil { - ctx.Handle(500, "ssh.ListPublicKey", err) + ctx.Handle(500, "ListPublicKeys", err) return } + ctx.Data["Keys"] = keys - // Delete SSH key. - if ctx.Query("_method") == "DELETE" { - id := com.StrTo(ctx.Query("id")).MustInt64() - if id <= 0 { - return - } + if ctx.HasError() { + ctx.HTML(200, SETTINGS_SSH_KEYS) + return + } - if err = models.DeletePublicKey(&models.PublicKey{ID: id}); err != nil { - ctx.Handle(500, "DeletePublicKey", err) + content, err := models.CheckPublicKeyString(form.Content) + if err != nil { + if err == models.ErrKeyUnableVerify { + ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key")) } else { - log.Trace("SSH key deleted: %s", ctx.User.Name) + ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") + return } - return } - // Add new SSH key. - if ctx.Req.Method == "POST" { - if ctx.HasError() { - ctx.HTML(200, SETTINGS_SSH_KEYS) - return + if err = models.AddPublicKey(ctx.User.Id, form.Title, content); err != nil { + ctx.Data["HasError"] = true + switch { + case models.IsErrKeyAlreadyExist(err): + ctx.Data["Err_Content"] = true + ctx.RenderWithErr(ctx.Tr("settings.ssh_key_been_used"), SETTINGS_SSH_KEYS, &form) + case models.IsErrKeyNameAlreadyUsed(err): + ctx.Data["Err_Title"] = true + ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), SETTINGS_SSH_KEYS, &form) + default: + ctx.Handle(500, "AddPublicKey", err) } + return + } - content, err := models.CheckPublicKeyString(form.Content) - if err != nil { - if err == models.ErrKeyUnableVerify { - ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key")) - } else { - ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) - ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") - return - } - } + ctx.Flash.Success(ctx.Tr("settings.add_key_success", form.Title)) + ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") +} - if err = models.AddPublicKey(ctx.User.Id, form.Title, content); err != nil { - switch { - case models.IsErrKeyAlreadyExist(err): - ctx.RenderWithErr(ctx.Tr("settings.ssh_key_been_used"), SETTINGS_SSH_KEYS, &form) - case models.IsErrKeyNameAlreadyUsed(err): - ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), SETTINGS_SSH_KEYS, &form) - default: - ctx.Handle(500, "AddPublicKey", err) - } - return - } else { - log.Trace("SSH key added: %s", ctx.User.Name) - ctx.Flash.Success(ctx.Tr("settings.add_key_success", form.Title)) - ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") - return - } +func DeleteSSHKey(ctx *middleware.Context) { + if err := models.DeletePublicKey(ctx.QueryInt64("id")); err != nil { + ctx.Flash.Error("DeletePublicKey: " + err.Error()) + } else { + ctx.Flash.Success(ctx.Tr("settings.ssh_key_deletion_success")) } - ctx.HTML(200, SETTINGS_SSH_KEYS) + ctx.JSON(200, map[string]interface{}{ + "redirect": setting.AppSubUrl + "/user/settings/ssh", + }) } func SettingsSocial(ctx *middleware.Context) { @@ -389,6 +381,12 @@ func SettingsApplicationsPost(ctx *middleware.Context, form auth.NewAccessTokenF ctx.Data["PageIsSettingsApplications"] = true if ctx.HasError() { + tokens, err := models.ListAccessTokens(ctx.User.Id) + if err != nil { + ctx.Handle(500, "ListAccessTokens", err) + return + } + ctx.Data["Tokens"] = tokens ctx.HTML(200, SETTINGS_APPLICATIONS) return } |