mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 03:00:18 +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:
@ -175,9 +175,14 @@ func (c *ApiController) ResetEmailOrPhone() {
|
||||
}
|
||||
|
||||
checkDest := dest
|
||||
org := object.GetOrganizationByUser(user)
|
||||
organization := object.GetOrganizationByUser(user)
|
||||
if destType == "phone" {
|
||||
phoneItem := object.GetAccountItemByName("Phone", org)
|
||||
if object.HasUserByField(user.Owner, "phone", user.Phone) {
|
||||
c.ResponseError(c.T("check:Phone already exists"))
|
||||
return
|
||||
}
|
||||
|
||||
phoneItem := object.GetAccountItemByName("Phone", organization)
|
||||
if phoneItem == nil {
|
||||
c.ResponseError(c.T("verification:Unable to get the phone modify rule."))
|
||||
return
|
||||
@ -189,12 +194,17 @@ func (c *ApiController) ResetEmailOrPhone() {
|
||||
}
|
||||
|
||||
phonePrefix := "86"
|
||||
if org != nil && org.PhonePrefix != "" {
|
||||
phonePrefix = org.PhonePrefix
|
||||
if organization != nil && organization.PhonePrefix != "" {
|
||||
phonePrefix = organization.PhonePrefix
|
||||
}
|
||||
checkDest = fmt.Sprintf("+%s%s", phonePrefix, dest)
|
||||
} else if destType == "email" {
|
||||
emailItem := object.GetAccountItemByName("Email", org)
|
||||
if object.HasUserByField(user.Owner, "email", user.Email) {
|
||||
c.ResponseError(c.T("check:Email already exists"))
|
||||
return
|
||||
}
|
||||
|
||||
emailItem := object.GetAccountItemByName("Email", organization)
|
||||
if emailItem == nil {
|
||||
c.ResponseError(c.T("verification:Unable to get the email modify rule."))
|
||||
return
|
||||
|
Reference in New Issue
Block a user