You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ssh.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package user
  5. import (
  6. "net/http"
  7. "strconv"
  8. "github.com/martini-contrib/render"
  9. "github.com/martini-contrib/sessions"
  10. "github.com/gogits/gogs/models"
  11. "github.com/gogits/gogs/modules/auth"
  12. "github.com/gogits/gogs/modules/base"
  13. "github.com/gogits/gogs/modules/log"
  14. )
  15. func DelPublicKey(req *http.Request, data base.TmplData, r render.Render, session sessions.Session) {
  16. data["Title"] = "Del Public Key"
  17. if req.Method == "GET" {
  18. r.HTML(200, "user/publickey_add", data)
  19. return
  20. }
  21. if req.Method == "DELETE" {
  22. id, err := strconv.ParseInt(req.FormValue("id"), 10, 64)
  23. if err != nil {
  24. data["ErrorMsg"] = err
  25. log.Error("ssh.DelPublicKey: %v", err)
  26. r.JSON(200, map[string]interface{}{
  27. "ok": false,
  28. "err": err.Error(),
  29. })
  30. return
  31. }
  32. k := &models.PublicKey{
  33. Id: id,
  34. OwnerId: auth.SignedInId(session),
  35. }
  36. err = models.DeletePublicKey(k)
  37. if err != nil {
  38. data["ErrorMsg"] = err
  39. log.Error("ssh.DelPublicKey: %v", err)
  40. r.JSON(200, map[string]interface{}{
  41. "ok": false,
  42. "err": err.Error(),
  43. })
  44. } else {
  45. r.JSON(200, map[string]interface{}{
  46. "ok": true,
  47. })
  48. }
  49. }
  50. }