fix 500 when use a duplicat email instead of giving an error tip (#1040)
This commit is contained in:
parent
cd1821a7e2
commit
19b3c45ca7
2 changed files with 30 additions and 18 deletions
|
@ -20,9 +20,9 @@ import (
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/auth/ldap"
|
"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/auth/pam"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/auth/oauth2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LoginType represents an login type.
|
// LoginType represents an login type.
|
||||||
|
@ -624,6 +624,16 @@ func UserSignIn(username, password string) (*User, error) {
|
||||||
var user *User
|
var user *User
|
||||||
if strings.Contains(username, "@") {
|
if strings.Contains(username, "@") {
|
||||||
user = &User{Email: strings.ToLower(strings.TrimSpace(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 {
|
} else {
|
||||||
user = &User{LowerName: strings.ToLower(strings.TrimSpace(username))}
|
user = &User{LowerName: strings.ToLower(strings.TrimSpace(username))}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,20 +7,20 @@ package user
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"github.com/go-macaron/captcha"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/auth"
|
"code.gitea.io/gitea/modules/auth"
|
||||||
|
"code.gitea.io/gitea/modules/auth/oauth2"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"net/http"
|
|
||||||
"code.gitea.io/gitea/modules/auth/oauth2"
|
"github.com/go-macaron/captcha"
|
||||||
"github.com/markbates/goth"
|
"github.com/markbates/goth"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -144,6 +144,8 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrUserNotExist(err) {
|
if models.IsErrUserNotExist(err) {
|
||||||
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
|
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 {
|
} else {
|
||||||
ctx.Handle(500, "UserSignIn", err)
|
ctx.Handle(500, "UserSignIn", err)
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue