mirror of https://github.com/gogits/gogs.git
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.
57 lines
1.4 KiB
57 lines
1.4 KiB
11 years ago
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
11 years ago
|
package org
|
||
|
|
||
|
import (
|
||
8 years ago
|
log "gopkg.in/clog.v1"
|
||
|
|
||
11 years ago
|
"github.com/gogits/gogs/models"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/context"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/form"
|
||
8 years ago
|
"github.com/gogits/gogs/pkg/setting"
|
||
11 years ago
|
)
|
||
|
|
||
|
const (
|
||
8 years ago
|
CREATE = "org/create"
|
||
11 years ago
|
)
|
||
|
|
||
8 years ago
|
func Create(c *context.Context) {
|
||
|
c.Data["Title"] = c.Tr("new_org")
|
||
|
c.HTML(200, CREATE)
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
func CreatePost(c *context.Context, f form.CreateOrg) {
|
||
|
c.Data["Title"] = c.Tr("new_org")
|
||
11 years ago
|
|
||
8 years ago
|
if c.HasError() {
|
||
|
c.HTML(200, CREATE)
|
||
11 years ago
|
return
|
||
|
}
|
||
|
|
||
|
org := &models.User{
|
||
8 years ago
|
Name: f.OrgName,
|
||
11 years ago
|
IsActive: true,
|
||
9 years ago
|
Type: models.USER_TYPE_ORGANIZATION,
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
if err := models.CreateOrganization(org, c.User); err != nil {
|
||
|
c.Data["Err_OrgName"] = true
|
||
10 years ago
|
switch {
|
||
|
case models.IsErrUserAlreadyExist(err):
|
||
8 years ago
|
c.RenderWithErr(c.Tr("form.org_name_been_taken"), CREATE, &f)
|
||
10 years ago
|
case models.IsErrNameReserved(err):
|
||
8 years ago
|
c.RenderWithErr(c.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), CREATE, &f)
|
||
10 years ago
|
case models.IsErrNamePatternNotAllowed(err):
|
||
8 years ago
|
c.RenderWithErr(c.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), CREATE, &f)
|
||
11 years ago
|
default:
|
||
8 years ago
|
c.Handle(500, "CreateOrganization", err)
|
||
11 years ago
|
}
|
||
|
return
|
||
|
}
|
||
11 years ago
|
log.Trace("Organization created: %s", org.Name)
|
||
11 years ago
|
|
||
8 years ago
|
c.Redirect(setting.AppSubURL + "/org/" + f.OrgName + "/dashboard")
|
||
11 years ago
|
}
|