org.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 org
  5. import (
  6. log "unknwon.dev/clog/v2"
  7. "gogs.io/gogs/internal/context"
  8. "gogs.io/gogs/internal/db"
  9. "gogs.io/gogs/internal/form"
  10. )
  11. const (
  12. CREATE = "org/create"
  13. )
  14. func Create(c *context.Context) {
  15. c.Title("new_org")
  16. c.Success(CREATE)
  17. }
  18. func CreatePost(c *context.Context, f form.CreateOrg) {
  19. c.Title("new_org")
  20. if c.HasError() {
  21. c.Success(CREATE)
  22. return
  23. }
  24. org, err := db.Organizations.Create(
  25. c.Req.Context(),
  26. f.OrgName,
  27. c.User.ID,
  28. db.CreateOrganizationOptions{},
  29. )
  30. if err != nil {
  31. c.Data["Err_OrgName"] = true
  32. switch {
  33. case db.IsErrOrganizationAlreadyExist(err):
  34. c.RenderWithErr(c.Tr("form.org_name_been_taken"), CREATE, &f)
  35. case db.IsErrNameNotAllowed(err):
  36. c.RenderWithErr(c.Tr("org.form.name_not_allowed", err.(db.ErrNameNotAllowed).Value()), CREATE, &f)
  37. default:
  38. c.Error(err, "create organization")
  39. }
  40. return
  41. }
  42. log.Trace("Organization created: %s", org.Name)
  43. c.RedirectSubpath("/org/" + f.OrgName + "/dashboard")
  44. }