|
|
@ -23,19 +23,7 @@ func Keys(ctx *context.Context) { |
|
|
|
ctx.Data["PageIsSettingsKeys"] = true |
|
|
|
ctx.Data["PageIsSettingsKeys"] = true |
|
|
|
ctx.Data["DisableSSH"] = setting.SSH.Disabled |
|
|
|
ctx.Data["DisableSSH"] = setting.SSH.Disabled |
|
|
|
|
|
|
|
|
|
|
|
keys, err := models.ListPublicKeys(ctx.User.ID) |
|
|
|
loadKeysData(ctx) |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("ListPublicKeys", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["Keys"] = keys |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpgkeys, err := models.ListGPGKeys(ctx.User.ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("ListGPGKeys", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["GPGKeys"] = gpgkeys |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.HTML(200, tplSettingsKeys) |
|
|
|
ctx.HTML(200, tplSettingsKeys) |
|
|
|
} |
|
|
|
} |
|
|
@ -45,21 +33,9 @@ func KeysPost(ctx *context.Context, form auth.AddKeyForm) { |
|
|
|
ctx.Data["Title"] = ctx.Tr("settings") |
|
|
|
ctx.Data["Title"] = ctx.Tr("settings") |
|
|
|
ctx.Data["PageIsSettingsKeys"] = true |
|
|
|
ctx.Data["PageIsSettingsKeys"] = true |
|
|
|
|
|
|
|
|
|
|
|
keys, err := models.ListPublicKeys(ctx.User.ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("ListPublicKeys", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["Keys"] = keys |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpgkeys, err := models.ListGPGKeys(ctx.User.ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("ListGPGKeys", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["GPGKeys"] = gpgkeys |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ctx.HasError() { |
|
|
|
if ctx.HasError() { |
|
|
|
|
|
|
|
loadKeysData(ctx) |
|
|
|
|
|
|
|
|
|
|
|
ctx.HTML(200, tplSettingsKeys) |
|
|
|
ctx.HTML(200, tplSettingsKeys) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -73,9 +49,13 @@ func KeysPost(ctx *context.Context, form auth.AddKeyForm) { |
|
|
|
ctx.Flash.Error(ctx.Tr("form.invalid_gpg_key", err.Error())) |
|
|
|
ctx.Flash.Error(ctx.Tr("form.invalid_gpg_key", err.Error())) |
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys") |
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/keys") |
|
|
|
case models.IsErrGPGKeyIDAlreadyUsed(err): |
|
|
|
case models.IsErrGPGKeyIDAlreadyUsed(err): |
|
|
|
|
|
|
|
loadKeysData(ctx) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["Err_Content"] = true |
|
|
|
ctx.Data["Err_Content"] = true |
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.gpg_key_id_used"), tplSettingsKeys, &form) |
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.gpg_key_id_used"), tplSettingsKeys, &form) |
|
|
|
case models.IsErrGPGNoEmailFound(err): |
|
|
|
case models.IsErrGPGNoEmailFound(err): |
|
|
|
|
|
|
|
loadKeysData(ctx) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["Err_Content"] = true |
|
|
|
ctx.Data["Err_Content"] = true |
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.gpg_no_key_email_found"), tplSettingsKeys, &form) |
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.gpg_no_key_email_found"), tplSettingsKeys, &form) |
|
|
|
default: |
|
|
|
default: |
|
|
@ -103,9 +83,13 @@ func KeysPost(ctx *context.Context, form auth.AddKeyForm) { |
|
|
|
ctx.Data["HasSSHError"] = true |
|
|
|
ctx.Data["HasSSHError"] = true |
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case models.IsErrKeyAlreadyExist(err): |
|
|
|
case models.IsErrKeyAlreadyExist(err): |
|
|
|
|
|
|
|
loadKeysData(ctx) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["Err_Content"] = true |
|
|
|
ctx.Data["Err_Content"] = true |
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.ssh_key_been_used"), tplSettingsKeys, &form) |
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.ssh_key_been_used"), tplSettingsKeys, &form) |
|
|
|
case models.IsErrKeyNameAlreadyUsed(err): |
|
|
|
case models.IsErrKeyNameAlreadyUsed(err): |
|
|
|
|
|
|
|
loadKeysData(ctx) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Data["Err_Title"] = true |
|
|
|
ctx.Data["Err_Title"] = true |
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), tplSettingsKeys, &form) |
|
|
|
ctx.RenderWithErr(ctx.Tr("settings.ssh_key_name_used"), tplSettingsKeys, &form) |
|
|
|
default: |
|
|
|
default: |
|
|
@ -147,3 +131,19 @@ func DeleteKey(ctx *context.Context) { |
|
|
|
"redirect": setting.AppSubURL + "/user/settings/keys", |
|
|
|
"redirect": setting.AppSubURL + "/user/settings/keys", |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func loadKeysData(ctx *context.Context) { |
|
|
|
|
|
|
|
keys, err := models.ListPublicKeys(ctx.User.ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("ListPublicKeys", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["Keys"] = keys |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpgkeys, err := models.ListGPGKeys(ctx.User.ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
ctx.ServerError("ListGPGKeys", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["GPGKeys"] = gpgkeys |
|
|
|
|
|
|
|
} |
|
|
|