fix 500 when use a duplicat email instead of giving an error tip (#1040)
This commit is contained in:
parent
cd1821a7e2
commit
19b3c45ca7
|
@ -20,9 +20,9 @@ import (
|
|||
"github.com/go-xorm/xorm"
|
||||
|
||||
"code.gitea.io/gitea/modules/auth/ldap"
|
||||
"code.gitea.io/gitea/modules/auth/oauth2"
|
||||
"code.gitea.io/gitea/modules/auth/pam"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/auth/oauth2"
|
||||
)
|
||||
|
||||
// LoginType represents an login type.
|
||||
|
@ -624,6 +624,16 @@ func UserSignIn(username, password string) (*User, error) {
|
|||
var user *User
|
||||
if strings.Contains(username, "@") {
|
||||
user = &User{Email: strings.ToLower(strings.TrimSpace(username))}
|
||||
// check same email
|
||||
cnt, err := x.Count(user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cnt > 1 {
|
||||
return nil, ErrEmailAlreadyUsed{
|
||||
Email: user.Email,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
user = &User{LowerName: strings.ToLower(strings.TrimSpace(username))}
|
||||
}
|
||||
|
|
|
@ -7,20 +7,20 @@ package user
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/go-macaron/captcha"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth"
|
||||
"code.gitea.io/gitea/modules/auth/oauth2"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"net/http"
|
||||
"code.gitea.io/gitea/modules/auth/oauth2"
|
||||
|
||||
"github.com/go-macaron/captcha"
|
||||
"github.com/markbates/goth"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -144,6 +144,8 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) {
|
|||
if err != nil {
|
||||
if models.IsErrUserNotExist(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
|
||||
} else if models.IsErrEmailAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form)
|
||||
} else {
|
||||
ctx.Handle(500, "UserSignIn", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user