mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 13:20:19 +08:00
feat: check uniqueness for email and phone when updating user (#1461)
* fix: check unique field when update user * Update data.json Co-authored-by: hsluoyz <hsluoyz@qq.com>
This commit is contained in:
@ -60,8 +60,8 @@ func CheckUserSignup(application *Application, organization *Organization, usern
|
||||
if reWhiteSpace.MatchString(username) {
|
||||
return i18n.Translate(lang, "check:Username cannot contain white spaces")
|
||||
}
|
||||
msg := CheckUsername(username, lang)
|
||||
if msg != "" {
|
||||
|
||||
if msg := CheckUsername(username, lang); msg != "" {
|
||||
return msg
|
||||
}
|
||||
|
||||
@ -342,6 +342,34 @@ func CheckUsername(username string, lang string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func CheckUpdateUser(oldUser *User, user *User, lang string) string {
|
||||
if user.DisplayName == "" {
|
||||
return i18n.Translate(lang, "user:Display name cannot be empty")
|
||||
}
|
||||
|
||||
if msg := CheckUsername(user.Name, lang); msg != "" {
|
||||
return msg
|
||||
}
|
||||
|
||||
if oldUser.Name != user.Name {
|
||||
if HasUserByField(user.Owner, "name", user.Name) {
|
||||
return i18n.Translate(lang, "check:Username already exists")
|
||||
}
|
||||
}
|
||||
if oldUser.Email != user.Email {
|
||||
if HasUserByField(user.Name, "email", user.Email) {
|
||||
return i18n.Translate(lang, "check:Email already exists")
|
||||
}
|
||||
}
|
||||
if oldUser.Phone != user.Phone {
|
||||
if HasUserByField(user.Owner, "phone", user.Phone) {
|
||||
return i18n.Translate(lang, "check:Phone already exists")
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func CheckToEnableCaptcha(application *Application) bool {
|
||||
if len(application.Providers) == 0 {
|
||||
return false
|
||||
|
Reference in New Issue
Block a user