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.

59 lines
1.7 KiB

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