2
0

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 := &db.User{
  25. Name: f.OrgName,
  26. IsActive: true,
  27. Type: db.UserOrganization,
  28. }
  29. if err := db.CreateOrganization(org, c.User); err != nil {
  30. c.Data["Err_OrgName"] = true
  31. switch {
  32. case db.IsErrUserAlreadyExist(err):
  33. c.RenderWithErr(c.Tr("form.org_name_been_taken"), CREATE, &f)
  34. case db.IsErrNameNotAllowed(err):
  35. c.RenderWithErr(c.Tr("org.form.name_not_allowed", err.(db.ErrNameNotAllowed).Value()), CREATE, &f)
  36. default:
  37. c.Error(err, "create organization")
  38. }
  39. return
  40. }
  41. log.Trace("Organization created: %s", org.Name)
  42. c.RedirectSubpath("/org/" + f.OrgName + "/dashboard")
  43. }