2014-06-07 13:27:24 +08:00
|
|
|
package org
|
|
|
|
|
|
|
|
|
|
import (
|
2026-01-30 22:27:59 +08:00
|
|
|
"net/http"
|
|
|
|
|
|
2020-02-20 02:25:02 +08:00
|
|
|
log "unknwon.dev/clog/v2"
|
2017-02-09 19:29:59 -05:00
|
|
|
|
2019-10-24 01:51:46 -07:00
|
|
|
"gogs.io/gogs/internal/context"
|
2024-02-18 19:39:41 -05:00
|
|
|
"gogs.io/gogs/internal/database"
|
2019-10-24 01:51:46 -07:00
|
|
|
"gogs.io/gogs/internal/form"
|
2014-06-25 00:44:48 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2017-04-05 09:17:21 -04:00
|
|
|
CREATE = "org/create"
|
2014-06-07 13:27:24 +08:00
|
|
|
)
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func Create(c *context.Context) {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Title("new_org")
|
|
|
|
|
c.Success(CREATE)
|
2014-06-25 00:44:48 -04:00
|
|
|
}
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func CreatePost(c *context.Context, f form.CreateOrg) {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Title("new_org")
|
2014-06-25 00:44:48 -04:00
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
if c.HasError() {
|
2026-01-30 22:27:59 +08:00
|
|
|
c.HTML(http.StatusBadRequest, CREATE)
|
2014-06-25 00:44:48 -04:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-18 19:39:41 -05:00
|
|
|
org := &database.User{
|
2017-02-23 11:39:09 -05:00
|
|
|
Name: f.OrgName,
|
2014-07-26 23:53:16 -04:00
|
|
|
IsActive: true,
|
2024-02-18 19:39:41 -05:00
|
|
|
Type: database.UserTypeOrganization,
|
2014-06-25 00:44:48 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-18 19:39:41 -05:00
|
|
|
if err := database.CreateOrganization(org, c.User); err != nil {
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Data["Err_OrgName"] = true
|
2015-03-26 17:11:47 -04:00
|
|
|
switch {
|
2024-02-18 19:39:41 -05:00
|
|
|
case database.IsErrUserAlreadyExist(err):
|
2026-01-30 22:27:59 +08:00
|
|
|
c.RenderWithErr(c.Tr("form.org_name_been_taken"), http.StatusUnprocessableEntity, CREATE, &f)
|
2024-02-18 19:39:41 -05:00
|
|
|
case database.IsErrNameNotAllowed(err):
|
2026-01-30 22:27:59 +08:00
|
|
|
c.RenderWithErr(c.Tr("org.form.name_not_allowed", err.(database.ErrNameNotAllowed).Value()), http.StatusBadRequest, CREATE, &f)
|
2014-06-25 00:44:48 -04:00
|
|
|
default:
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Error(err, "create organization")
|
2014-06-25 00:44:48 -04:00
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
2014-07-26 23:53:16 -04:00
|
|
|
log.Trace("Organization created: %s", org.Name)
|
2014-06-25 00:44:48 -04:00
|
|
|
|
2020-03-16 01:22:27 +08:00
|
|
|
c.RedirectSubpath("/org/" + f.OrgName + "/dashboard")
|
2014-06-23 11:40:49 +08:00
|
|
|
}
|