diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-21 03:27:59 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-21 03:27:59 -0400 |
commit | c1576b4c400376f22ec25012a6ca66e9c5539ee4 (patch) | |
tree | b8e682560055e8e91448d701e798edc3450a86c4 /routers | |
parent | 5373a3093eaf9bc9ced7a6b3335ccf1b17fd343e (diff) | |
download | gitea-c1576b4c400376f22ec25012a6ca66e9c5539ee4.tar.gz gitea-c1576b4c400376f22ec25012a6ca66e9c5539ee4.zip |
Add admin add user
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/admin.go | 18 | ||||
-rw-r--r-- | routers/admin/user.go | 63 |
2 files changed, 81 insertions, 0 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 1095a599b9..547883f7bc 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -5,7 +5,12 @@ package admin import ( + "strings" + + "github.com/codegangsta/martini" + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" ) @@ -45,5 +50,18 @@ func Repositories(ctx *middleware.Context) { func Config(ctx *middleware.Context) { ctx.Data["Title"] = "Server Configuration" ctx.Data["PageIsConfig"] = true + + ctx.Data["AppUrl"] = base.AppUrl + ctx.Data["Domain"] = base.Domain + ctx.Data["RunUser"] = base.RunUser + ctx.Data["RunMode"] = strings.Title(martini.Env) + ctx.Data["RepoRootPath"] = base.RepoRootPath + + ctx.Data["Service"] = base.Service + + ctx.Data["DbCfg"] = models.DbCfg + + ctx.Data["Mailer"] = base.MailService + ctx.HTML(200, "admin/config") } diff --git a/routers/admin/user.go b/routers/admin/user.go new file mode 100644 index 0000000000..9dcc1499e3 --- /dev/null +++ b/routers/admin/user.go @@ -0,0 +1,63 @@ +// 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. + +package admin + +import ( + "strings" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/auth" + "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/middleware" +) + +func NewUser(ctx *middleware.Context, form auth.RegisterForm) { + ctx.Data["Title"] = "New Account" + + if ctx.Req.Method == "GET" { + ctx.HTML(200, "admin/users/new") + return + } + + if form.Password != form.RetypePasswd { + ctx.Data["HasError"] = true + ctx.Data["Err_Password"] = true + ctx.Data["Err_RetypePasswd"] = true + ctx.Data["ErrorMsg"] = "Password and re-type password are not same" + auth.AssignForm(form, ctx.Data) + } + + if ctx.HasError() { + ctx.HTML(200, "admin/users/new") + return + } + + u := &models.User{ + Name: form.UserName, + Email: form.Email, + Passwd: form.Password, + IsActive: true, + } + + var err error + if u, err = models.RegisterUser(u); err != nil { + switch err { + case models.ErrUserAlreadyExist: + ctx.RenderWithErr("Username has been already taken", "admin/users/new", &form) + case models.ErrEmailAlreadyUsed: + ctx.RenderWithErr("E-mail address has been already used", "admin/users/new", &form) + case models.ErrUserNameIllegal: + ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "admin/users/new", &form) + default: + ctx.Handle(200, "admin.user.NewUser", err) + } + return + } + + log.Trace("%s User created by admin(%s): %s", ctx.Req.RequestURI, + ctx.User.LowerName, strings.ToLower(form.UserName)) + + ctx.Redirect("/admin/users") +} |