ssh.go 1.4 KB

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