aboutsummaryrefslogtreecommitdiffstats
path: root/routers/user
diff options
context:
space:
mode:
authorPeter Smit <peter@smitmail.eu>2015-01-02 15:38:11 +0200
committerPeter Smit <peter@smitmail.eu>2015-01-02 15:38:11 +0200
commit6251626de45a2310b3532176c0fc12c52dbd6e32 (patch)
treed8da1f5ec9aa6255700d22eae077dfd5ccb294a8 /routers/user
parent9b0858b1ad96455c0660d6311fedc6fb752a928f (diff)
downloadgitea-6251626de45a2310b3532176c0fc12c52dbd6e32.tar.gz
gitea-6251626de45a2310b3532176c0fc12c52dbd6e32.zip
Implement #798 Flexible ssh-key input
It is now possible to input ssh keys in a number of formats: openssh, SSH2 or just the base64 encoded key.
Diffstat (limited to 'routers/user')
-rw-r--r--routers/user/setting.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/routers/user/setting.go b/routers/user/setting.go
index 419e84b395..953e61138f 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -325,10 +325,15 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
return
}
- // Remove newline characters from form.KeyContent
- cleanContent := strings.Replace(form.Content, "\n", "", -1)
+ // Parse openssh style string from form content
+ content, err := models.ParseKeyString(form.Content)
+ if err != nil {
+ ctx.Flash.Error(ctx.Tr("form.invalid_ssh_key", err.Error()))
+ ctx.Redirect(setting.AppSubUrl + "/user/settings/ssh")
+ return
+ }
- if ok, err := models.CheckPublicKeyString(cleanContent); !ok {
+ if ok, err := models.CheckPublicKeyString(content); !ok {
if err == models.ErrKeyUnableVerify {
ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key"))
} else {
@@ -341,7 +346,7 @@ func SettingsSSHKeysPost(ctx *middleware.Context, form auth.AddSSHKeyForm) {
k := &models.PublicKey{
OwnerId: ctx.User.Id,
Name: form.SSHTitle,
- Content: cleanContent,
+ Content: content,
}
if err := models.AddPublicKey(k); err != nil {
if err == models.ErrKeyAlreadyExist {