#697 disable captcha and new admin create user UI

This commit is contained in:
Unknwon 2015-09-13 09:51:51 -04:00
parent e2d6b0116e
commit 8e0a69f86a
19 changed files with 228 additions and 179 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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)
}

View file

@ -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