ssh.go 806 B

123456789101112131415161718192021222324252627282930313233343536
  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. )
  11. func AddPublicKey(req *http.Request, r render.Render) {
  12. if req.Method == "GET" {
  13. r.HTML(200, "user/publickey_add", map[string]interface{}{
  14. "Title": "Add Public Key",
  15. })
  16. return
  17. }
  18. k := &models.PublicKey{OwnerId: 1,
  19. Name: req.FormValue("keyname"),
  20. Content: req.FormValue("key_content"),
  21. }
  22. err := models.AddPublicKey(k)
  23. if err != nil {
  24. r.HTML(403, "status/403", map[string]interface{}{
  25. "Title": fmt.Sprintf("%v", err),
  26. })
  27. } else {
  28. r.HTML(200, "user/publickey_added", map[string]interface{}{})
  29. }
  30. }