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 | |
parent | e2d6b0116e44ca0fa2c577f40adde4ebfa612ae0 (diff) | |
download | gitea-8e0a69f86a9e103d1d82d3c5000e01b4e2570a51.tar.gz gitea-8e0a69f86a9e103d1d82d3c5000e01b4e2570a51.zip |
#697 disable captcha and new admin create user UI
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/auths.go | 4 | ||||
-rw-r--r-- | routers/admin/repos.go | 19 | ||||
-rw-r--r-- | routers/admin/users.go | 59 | ||||
-rw-r--r-- | routers/user/auth.go | 30 |
4 files changed, 52 insertions, 60 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) } diff --git a/routers/user/auth.go b/routers/user/auth.go index 5c6bb26fba..1b15d90eb7 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -151,6 +151,8 @@ func oauthSignUp(ctx *middleware.Context, sid int64) { func SignUp(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("sign_up") + ctx.Data["DisableCaptcha"] = setting.Service.DisableCaptcha + if setting.Service.DisableRegistration { ctx.Data["DisableRegistration"] = true ctx.HTML(200, SIGNUP) @@ -168,6 +170,8 @@ func SignUp(ctx *middleware.Context) { func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.RegisterForm) { ctx.Data["Title"] = ctx.Tr("sign_up") + ctx.Data["DisableCaptcha"] = setting.Service.DisableCaptcha + if setting.Service.DisableRegistration { ctx.Error(403) return @@ -179,36 +183,18 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe ctx.Data["IsSocialLogin"] = true } - // May redirect from home page. - if ctx.Query("from") == "home" { - // Clear input error box. - ctx.Data["Err_UserName"] = false - ctx.Data["Err_Email"] = false - - // Make the best guess. - uname := ctx.Query("uname") - i := strings.Index(uname, "@") - if i > -1 { - ctx.Data["email"] = uname - ctx.Data["uname"] = uname[:i] - } else { - ctx.Data["uname"] = uname - } - ctx.Data["password"] = ctx.Query("password") - ctx.HTML(200, SIGNUP) - return - } - if ctx.HasError() { ctx.HTML(200, SIGNUP) return } - if !cpt.VerifyReq(ctx.Req) { + if !setting.Service.DisableCaptcha && !cpt.VerifyReq(ctx.Req) { ctx.Data["Err_Captcha"] = true ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), SIGNUP, &form) return - } else if form.Password != form.Retype { + } + + if form.Password != form.Retype { ctx.Data["Err_Password"] = true ctx.RenderWithErr(ctx.Tr("form.password_not_match"), SIGNUP, &form) return |