(c *context.Context, f form.AddSSHKey)
| 330 | } |
| 331 | |
| 332 | func SettingsSSHKeysPost(c *context.Context, f form.AddSSHKey) { |
| 333 | c.Title("settings.ssh_keys") |
| 334 | c.PageIs("SettingsSSHKeys") |
| 335 | |
| 336 | keys, err := database.ListPublicKeys(c.User.ID) |
| 337 | if err != nil { |
| 338 | c.Errorf(err, "list public keys") |
| 339 | return |
| 340 | } |
| 341 | c.Data["Keys"] = keys |
| 342 | |
| 343 | if c.HasError() { |
| 344 | c.HTML(http.StatusBadRequest, tmplUserSettingsSSHKeys) |
| 345 | return |
| 346 | } |
| 347 | |
| 348 | content, err := database.CheckPublicKeyString(f.Content) |
| 349 | if err != nil { |
| 350 | if database.IsErrKeyUnableVerify(err) { |
| 351 | c.Flash.Info(c.Tr("form.unable_verify_ssh_key")) |
| 352 | } else { |
| 353 | c.Flash.Error(c.Tr("form.invalid_ssh_key", err.Error())) |
| 354 | c.RedirectSubpath("/user/settings/ssh") |
| 355 | return |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | if _, err = database.AddPublicKey(c.User.ID, f.Title, content); err != nil { |
| 360 | c.Data["HasError"] = true |
| 361 | switch { |
| 362 | case database.IsErrKeyAlreadyExist(err): |
| 363 | c.FormErr("Content") |
| 364 | c.RenderWithErr(c.Tr("settings.ssh_key_been_used"), http.StatusUnprocessableEntity, tmplUserSettingsSSHKeys, &f) |
| 365 | case database.IsErrKeyNameAlreadyUsed(err): |
| 366 | c.FormErr("Title") |
| 367 | c.RenderWithErr(c.Tr("settings.ssh_key_name_used"), http.StatusUnprocessableEntity, tmplUserSettingsSSHKeys, &f) |
| 368 | default: |
| 369 | c.Errorf(err, "add public key") |
| 370 | } |
| 371 | return |
| 372 | } |
| 373 | |
| 374 | c.Flash.Success(c.Tr("settings.add_key_success", f.Title)) |
| 375 | c.RedirectSubpath("/user/settings/ssh") |
| 376 | } |
| 377 | |
| 378 | func DeleteSSHKey(c *context.Context) { |
| 379 | if err := database.DeletePublicKey(c.User, c.QueryInt64("id")); err != nil { |
nothing calls this directly
no test coverage detected