diff options
author | Unknwon <u@gogs.io> | 2015-09-13 09:51:51 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-09-13 09:51:51 -0400 |
commit | 8e0a69f86a9e103d1d82d3c5000e01b4e2570a51 (patch) | |
tree | 6c0802f63be1ff7867b80375b406dd8b520f6b1e /routers/admin | |
parent | e2d6b0116e44ca0fa2c577f40adde4ebfa612ae0 (diff) | |
download | gitea-8e0a69f86a9e103d1d82d3c5000e01b4e2570a51.tar.gz gitea-8e0a69f86a9e103d1d82d3c5000e01b4e2570a51.zip |
#697 disable captcha and new admin create user UI
Diffstat (limited to 'routers/admin')
-rw-r--r-- | routers/admin/auths.go | 4 | ||||
-rw-r--r-- | routers/admin/repos.go | 19 | ||||
-rw-r--r-- | routers/admin/users.go | 59 |
3 files changed, 44 insertions, 38 deletions
diff --git a/routers/admin/auths.go b/routers/admin/auths.go index 6edf41ca25..a218ee09b7 100644 --- a/routers/admin/auths.go +++ b/routers/admin/auths.go @@ -29,9 +29,9 @@ func Authentications(ctx *middleware.Context) { ctx.Data["PageIsAdminAuthentications"] = true var err error - ctx.Data["Sources"], err = models.GetAuths() + ctx.Data["Sources"], err = models.LoginSources() if err != nil { - ctx.Handle(500, "GetAuths", err) + ctx.Handle(500, "LoginSources", err) return } diff --git a/routers/admin/repos.go b/routers/admin/repos.go index 6d9169f94d..3f63887139 100644 --- a/routers/admin/repos.go +++ b/routers/admin/repos.go @@ -5,6 +5,8 @@ package admin import ( + "math" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" @@ -14,6 +16,23 @@ const ( REPOS base.TplName = "admin/repo/list" ) +func pagination(ctx *middleware.Context, count int64, pageNum int) int { + p := ctx.QueryInt("p") + if p < 1 { + p = 1 + } + curCount := int64((p-1)*pageNum + pageNum) + if curCount >= count { + p = int(math.Ceil(float64(count) / float64(pageNum))) + } else { + ctx.Data["NextPageNum"] = p + 1 + } + if p > 1 { + ctx.Data["LastPageNum"] = p - 1 + } + return p +} + func Repositories(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("admin.repositories") ctx.Data["PageIsAdmin"] = true diff --git a/routers/admin/users.go b/routers/admin/users.go index bc2deac1a9..7553aba6bd 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -5,7 +5,6 @@ package admin import ( - "math" "strings" "github.com/Unknwon/com" @@ -25,23 +24,6 @@ const ( USER_EDIT base.TplName = "admin/user/edit" ) -func pagination(ctx *middleware.Context, count int64, pageNum int) int { - p := ctx.QueryInt("p") - if p < 1 { - p = 1 - } - curCount := int64((p-1)*pageNum + pageNum) - if curCount >= count { - p = int(math.Ceil(float64(count) / float64(pageNum))) - } else { - ctx.Data["NextPageNum"] = p + 1 - } - if p > 1 { - ctx.Data["LastPageNum"] = p - 1 - } - return p -} - func Users(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("admin.users") ctx.Data["PageIsAdmin"] = true @@ -70,12 +52,14 @@ func NewUser(ctx *middleware.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminUsers"] = true - auths, err := models.GetAuths() + ctx.Data["login_type"] = "0-0" + + sources, err := models.LoginSources() if err != nil { - ctx.Handle(500, "GetAuths", err) + ctx.Handle(500, "LoginSources", err) return } - ctx.Data["LoginSources"] = auths + ctx.Data["Sources"] = sources ctx.HTML(200, USER_NEW) } @@ -84,14 +68,15 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminUsers"] = true - if ctx.HasError() { - ctx.HTML(200, USER_NEW) + sources, err := models.LoginSources() + if err != nil { + ctx.Handle(500, "LoginSources", err) return } + ctx.Data["Sources"] = sources - if form.Password != form.Retype { - ctx.Data["Err_Password"] = true - ctx.RenderWithErr(ctx.Tr("form.password_not_match"), USER_NEW, &form) + if ctx.HasError() { + ctx.HTML(200, USER_NEW) return } @@ -104,12 +89,12 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { } if len(form.LoginType) > 0 { - // NOTE: need rewrite. fields := strings.Split(form.LoginType, "-") - tp, _ := com.StrTo(fields[0]).Int() - u.LoginType = models.LoginType(tp) - u.LoginSource, _ = com.StrTo(fields[1]).Int64() - u.LoginName = form.LoginName + if len(fields) == 2 { + u.LoginType = models.LoginType(com.StrTo(fields[0]).MustInt()) + u.LoginSource = com.StrTo(fields[1]).MustInt64() + u.LoginName = form.LoginName + } } if err := models.CreateUser(u); err != nil { @@ -132,7 +117,9 @@ func NewUserPost(ctx *middleware.Context, form auth.RegisterForm) { return } log.Trace("Account created by admin(%s): %s", ctx.User.Name, u.Name) - ctx.Redirect(setting.AppSubUrl + "/admin/users") + + ctx.Flash.Success(ctx.Tr("admin.users.new_success", u.Name)) + ctx.Redirect(setting.AppSubUrl + "/admin/users/" + com.ToStr(u.Id)) } func EditUser(ctx *middleware.Context) { @@ -151,14 +138,14 @@ func EditUser(ctx *middleware.Context) { ctx.Handle(500, "GetUserByID", err) return } - ctx.Data["User"] = u - auths, err := models.GetAuths() + + sources, err := models.LoginSources() if err != nil { - ctx.Handle(500, "GetAuths", err) + ctx.Handle(500, "LoginSources", err) return } - ctx.Data["LoginSources"] = auths + ctx.Data["LoginSources"] = sources ctx.HTML(200, USER_EDIT) } |