repo.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 repo
  5. import (
  6. "fmt"
  7. "net/http"
  8. "strconv"
  9. "github.com/martini-contrib/render"
  10. "github.com/gogits/gogs/models"
  11. )
  12. func Create(req *http.Request, r render.Render) {
  13. if req.Method == "GET" {
  14. r.HTML(200, "repo/create", map[string]interface{}{
  15. "Title": "Create repository",
  16. })
  17. return
  18. }
  19. // TODO: access check
  20. //fmt.Println(req.FormValue("userId"), req.FormValue("name"))
  21. id, err := strconv.ParseInt(req.FormValue("userId"), 10, 64)
  22. if err == nil {
  23. var user *models.User
  24. user, err = models.GetUserById(id)
  25. if user == nil {
  26. err = models.ErrUserNotExist
  27. }
  28. if err == nil {
  29. _, err = models.CreateRepository(user, req.FormValue("name"))
  30. }
  31. if err == nil {
  32. r.HTML(200, "repo/created", map[string]interface{}{
  33. "RepoName": user.Name + "/" + req.FormValue("name"),
  34. })
  35. return
  36. }
  37. }
  38. if err != nil {
  39. r.HTML(403, "status/403", map[string]interface{}{
  40. "Title": fmt.Sprintf("%v", err),
  41. })
  42. }
  43. }
  44. func Delete(req *http.Request, r render.Render) {
  45. if req.Method == "GET" {
  46. r.HTML(200, "repo/delete", map[string]interface{}{
  47. "Title": "Delete repository",
  48. })
  49. return
  50. }
  51. u := &models.User{}
  52. err := models.DeleteRepository(u, "")
  53. r.HTML(403, "status/403", map[string]interface{}{
  54. "Title": fmt.Sprintf("%v", err),
  55. })
  56. }