You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

  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. "github.com/gogits/gogs/models"
  7. "github.com/gogits/gogs/modules/auth"
  8. "github.com/gogits/gogs/modules/base"
  9. "github.com/gogits/gogs/modules/log"
  10. "github.com/gogits/gogs/modules/middleware"
  11. "github.com/gogits/gogs/modules/setting"
  12. )
  13. const (
  14. CREATE base.TplName = "org/create"
  15. )
  16. func Create(ctx *middleware.Context) {
  17. ctx.Data["Title"] = ctx.Tr("new_org")
  18. ctx.HTML(200, CREATE)
  19. }
  20. func CreatePost(ctx *middleware.Context, form auth.CreateOrgForm) {
  21. ctx.Data["Title"] = ctx.Tr("new_org")
  22. if ctx.HasError() {
  23. ctx.HTML(200, CREATE)
  24. return
  25. }
  26. org := &models.User{
  27. Name: form.OrgName,
  28. IsActive: true,
  29. Type: models.ORGANIZATION,
  30. }
  31. if err := models.CreateOrganization(org, ctx.User); err != nil {
  32. ctx.Data["Err_OrgName"] = true
  33. switch {
  34. case models.IsErrUserAlreadyExist(err):
  35. ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), CREATE, &form)
  36. case models.IsErrNameReserved(err):
  37. ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), CREATE, &form)
  38. case models.IsErrNamePatternNotAllowed(err):
  39. ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), CREATE, &form)
  40. default:
  41. ctx.Handle(500, "CreateOrganization", err)
  42. }
  43. return
  44. }
  45. log.Trace("Organization created: %s", org.Name)
  46. ctx.Redirect(setting.AppSubUrl + "/org/" + form.OrgName + "/dashboard")
  47. }