fix: web login authorize delay

This commit is contained in:
yystopf 2021-12-22 15:47:00 +08:00
parent d4eec1b75c
commit db7e13f040
2 changed files with 14 additions and 7 deletions

View File

@ -829,9 +829,6 @@ func UserSignIn(username, password string) (*User, error) {
} }
if hasUser { if hasUser {
if !user.IsAdmin {
return nil, ErrUserNodAdmin{user.ID, user.Name}
}
switch user.LoginType { switch user.LoginType {
case LoginNoType, LoginPlain, LoginOAuth2: case LoginNoType, LoginPlain, LoginOAuth2:
if user.IsPasswordSet() && user.ValidatePassword(password) { if user.IsPasswordSet() && user.ValidatePassword(password) {

View File

@ -174,6 +174,20 @@ func SignInPost(ctx *context.Context) {
} }
form := web.GetForm(ctx).(*forms.SignInForm) form := web.GetForm(ctx).(*forms.SignInForm)
if user, err := models.GetUserByName(form.UserName); models.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
return
} else {
// If this user not is administrator
// Instead, tip error
if !user.IsAdmin {
ctx.RenderWithErr(ctx.Tr("form.User is not an administrator"), tplSignIn, &form)
log.Info("Failed authentiation attempt for %s from %s ", form.UserName, ctx.RemoteAddr())
return
}
}
u, err := models.UserSignIn(form.UserName, form.Password) u, err := models.UserSignIn(form.UserName, form.Password)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
@ -195,10 +209,6 @@ func SignInPost(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login") ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
ctx.HTML(http.StatusOK, "user/auth/prohibit_login") ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
} }
} else if models.IsErrUserNotAdmin(err) {
ctx.RenderWithErr(ctx.Tr("form.User is not an administrator"), tplSignIn, &form)
log.Info("Failed authentiation attempt for %s from %s ", form.UserName, ctx.RemoteAddr())
} else { } else {
ctx.ServerError("UserSignIn", err) ctx.ServerError("UserSignIn", err)
} }