From 452ccff81ca736a07bec44a059a0562a08656bf4 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 11 Oct 2014 21:04:42 -0400 Subject: [PATCH] Mirror fix on add ssh key --- conf/locale/locale_en-US.ini | 1 + conf/locale/locale_zh-CN.ini | 1 + models/publickey.go | 4 +++- routers/user/setting.go | 10 +++++++--- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index e0a50665..f99a9e72 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -159,6 +159,7 @@ user_not_exist = Given user does not exist. last_org_owner = The user to remove is the last member in owner team. There must be another owner. invalid_ssh_key = Sorry, we're not able to verify your SSH key: %s +unable_verify_ssh_key = Gogs cannot verify your SSH key, but we assume that is valid, please make sure yourself. auth_failed = Authentication failed: %v still_own_repo = Your account still have ownership of repository, you have to delete or transfer them first. diff --git a/conf/locale/locale_zh-CN.ini b/conf/locale/locale_zh-CN.ini index c704ad20..0c17f2d7 100644 --- a/conf/locale/locale_zh-CN.ini +++ b/conf/locale/locale_zh-CN.ini @@ -159,6 +159,7 @@ user_not_exist = 被操作的用户不存在! last_org_owner = 被移除用户为最后一位管理员。请添加一位新的管理员再进行移除成员操作! invalid_ssh_key = 很抱歉,我们无法验证您输入的 SSH 密钥:%s +unable_verify_ssh_key = Gogs 无法验证您输入的 SSH 密钥,但我们假设那是有效的密钥,请您自行确保其有效性! auth_failed = 授权验证失败:%v still_own_repo = 您的帐户仍然是某些仓库的拥有者,您必须先转移或删除它们才能执行删除帐户操作! diff --git a/models/publickey.go b/models/publickey.go index aac5a81a..762d7333 100644 --- a/models/publickey.go +++ b/models/publickey.go @@ -33,6 +33,7 @@ const ( var ( ErrKeyAlreadyExist = errors.New("Public key already exist") ErrKeyNotExist = errors.New("Public key does not exist") + ErrKeyUnableVerify = errors.New("Unable to verify public key") ) var sshOpLocker = sync.Mutex{} @@ -134,9 +135,10 @@ func CheckPublicKeyString(content string) (bool, error) { return true, nil } + fmt.Println(stdout) sshKeygenOutput := strings.Split(stdout, " ") if len(sshKeygenOutput) < 4 { - return false, fmt.Errorf("not enough fields returned by ssh-keygen -l -f: %v", sshKeygenOutput) + return false, ErrKeyUnableVerify } // Check if key type and key size match. diff --git a/routers/user/setting.go b/routers/user/setting.go index 8f778acd..778f27ac 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -177,9 +177,13 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) { cleanContent := strings.Replace(form.Content, "\n", "", -1) if ok, err := models.CheckPublicKeyString(cleanContent); !ok { - ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error())) - ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh") - return + 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 + } } k := &models.PublicKey{