ssh.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. "fmt"
  7. "net/http"
  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. )
  13. func AddPublicKey(req *http.Request, r render.Render, session sessions.Session) {
  14. if req.Method == "GET" {
  15. r.HTML(200, "user/publickey_add", map[string]interface{}{
  16. "Title": "Add Public Key",
  17. "IsSigned": auth.IsSignedIn(session),
  18. })
  19. return
  20. }
  21. k := &models.PublicKey{OwnerId: auth.SignedInId(session),
  22. Name: req.FormValue("keyname"),
  23. Content: req.FormValue("key_content"),
  24. }
  25. err := models.AddPublicKey(k)
  26. if err != nil {
  27. r.HTML(403, "status/403", map[string]interface{}{
  28. "Title": fmt.Sprintf("%v", err),
  29. "IsSigned": auth.IsSignedIn(session),
  30. })
  31. } else {
  32. r.HTML(200, "user/publickey_added", map[string]interface{}{})
  33. }
  34. }
  35. func ListPublicKey(req *http.Request, r render.Render, session sessions.Session) {
  36. keys, err := models.ListPublicKey(auth.SignedInId(session))
  37. if err != nil {
  38. r.HTML(200, "base/error", map[string]interface{}{
  39. "Error": fmt.Sprintf("%v", err),
  40. "IsSigned": auth.IsSignedIn(session),
  41. })
  42. return
  43. }
  44. r.HTML(200, "user/publickey_list", map[string]interface{}{
  45. "Title": "repositories",
  46. "Keys": keys,
  47. "IsSigned": auth.IsSignedIn(session),
  48. })
  49. }