mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20: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:
@ -148,8 +148,8 @@ func (c *ApiController) UpdateUser() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.DisplayName == "" {
|
if msg := object.CheckUpdateUser(object.GetUser(id), &user, c.GetAcceptLanguage()); msg != "" {
|
||||||
c.ResponseError(c.T("user:Display name cannot be empty"))
|
c.ResponseError(msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,9 +175,14 @@ func (c *ApiController) ResetEmailOrPhone() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkDest := dest
|
checkDest := dest
|
||||||
org := object.GetOrganizationByUser(user)
|
organization := object.GetOrganizationByUser(user)
|
||||||
if destType == "phone" {
|
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 {
|
if phoneItem == nil {
|
||||||
c.ResponseError(c.T("verification:Unable to get the phone modify rule."))
|
c.ResponseError(c.T("verification:Unable to get the phone modify rule."))
|
||||||
return
|
return
|
||||||
@ -189,12 +194,17 @@ func (c *ApiController) ResetEmailOrPhone() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
phonePrefix := "86"
|
phonePrefix := "86"
|
||||||
if org != nil && org.PhonePrefix != "" {
|
if organization != nil && organization.PhonePrefix != "" {
|
||||||
phonePrefix = org.PhonePrefix
|
phonePrefix = organization.PhonePrefix
|
||||||
}
|
}
|
||||||
checkDest = fmt.Sprintf("+%s%s", phonePrefix, dest)
|
checkDest = fmt.Sprintf("+%s%s", phonePrefix, dest)
|
||||||
} else if destType == "email" {
|
} 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 {
|
if emailItem == nil {
|
||||||
c.ResponseError(c.T("verification:Unable to get the email modify rule."))
|
c.ResponseError(c.T("verification:Unable to get the email modify rule."))
|
||||||
return
|
return
|
||||||
|
@ -60,8 +60,8 @@ func CheckUserSignup(application *Application, organization *Organization, usern
|
|||||||
if reWhiteSpace.MatchString(username) {
|
if reWhiteSpace.MatchString(username) {
|
||||||
return i18n.Translate(lang, "check:Username cannot contain white spaces")
|
return i18n.Translate(lang, "check:Username cannot contain white spaces")
|
||||||
}
|
}
|
||||||
msg := CheckUsername(username, lang)
|
|
||||||
if msg != "" {
|
if msg := CheckUsername(username, lang); msg != "" {
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,6 +342,34 @@ func CheckUsername(username string, lang string) string {
|
|||||||
return ""
|
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 {
|
func CheckToEnableCaptcha(application *Application) bool {
|
||||||
if len(application.Providers) == 0 {
|
if len(application.Providers) == 0 {
|
||||||
return false
|
return false
|
||||||
|
@ -37,7 +37,11 @@ export const ResetModal = (props) => {
|
|||||||
|
|
||||||
const handleOk = () => {
|
const handleOk = () => {
|
||||||
if (dest === "") {
|
if (dest === "") {
|
||||||
Setting.showMessage("error", i18next.t("user:Empty " + destType));
|
if (destType === "phone") {
|
||||||
|
Setting.showMessage("error", i18next.t("user:Phone cannot be empty"));
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", i18next.t("user:Email cannot be empty"));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (code === "") {
|
if (code === "") {
|
||||||
|
@ -284,18 +284,16 @@ class UserEditPage extends React.Component {
|
|||||||
{Setting.getLabel(i18next.t("general:Email"), i18next.t("general:Email - Tooltip"))} :
|
{Setting.getLabel(i18next.t("general:Email"), i18next.t("general:Email - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col style={{paddingRight: "20px"}} span={11} >
|
<Col style={{paddingRight: "20px"}} span={11} >
|
||||||
<Input value={this.state.user.email}
|
<Select value={this.state.user.email}
|
||||||
|
options={[Setting.getItem(this.state.user.email, this.state.user.email)]}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
this.updateUserField("email", e.target.value);
|
this.updateUserField("email", e.target.value);
|
||||||
}} />
|
}} />
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={11} >
|
<Col span={11} >
|
||||||
{
|
{/* backend auto get the current user, so admin can not edit. Just self can reset*/}
|
||||||
!this.isSelf() ? null : (
|
{this.isSelf() ? <ResetModal application={this.state.application} disabled={disabled} buttonText={i18next.t("user:Reset Email...")} destType={"email"} /> : null}
|
||||||
<ResetModal application={this.state.application} disabled={disabled} buttonText={i18next.t("user:Reset Email...")} destType={"email"} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
@ -306,14 +304,15 @@ class UserEditPage extends React.Component {
|
|||||||
{Setting.getLabel(i18next.t("general:Phone"), i18next.t("general:Phone - Tooltip"))} :
|
{Setting.getLabel(i18next.t("general:Phone"), i18next.t("general:Phone - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col style={{paddingRight: "20px"}} span={11} >
|
<Col style={{paddingRight: "20px"}} span={11} >
|
||||||
<Input value={this.state.user.phone} addonBefore={`+${this.state.application?.organizationObj.phonePrefix}`}
|
<Select value={`+${this.state.application?.organizationObj.phonePrefix} ${this.state.user.phone}`}
|
||||||
|
options={[Setting.getItem(`+${this.state.application?.organizationObj.phonePrefix} ${this.state.user.phone}`, this.state.user.phone)]}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
this.updateUserField("phone", e.target.value);
|
this.updateUserField("phone", e.target.value);
|
||||||
}} />
|
}} />
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={11} >
|
<Col span={11} >
|
||||||
{this.state.user.id === this.props.account?.id ? (<ResetModal application={this.state.application} disabled={disabled} buttonText={i18next.t("user:Reset Phone...")} destType={"phone"} />) : null}
|
{this.isSelf() ? (<ResetModal application={this.state.application} disabled={disabled} buttonText={i18next.t("user:Reset Phone...")} destType={"phone"} />) : null}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
|
@ -354,6 +354,7 @@ class UserListPage extends BaseListPage {
|
|||||||
<Popconfirm
|
<Popconfirm
|
||||||
title={`Sure to delete user: ${record.name} ?`}
|
title={`Sure to delete user: ${record.name} ?`}
|
||||||
onConfirm={() => this.deleteUser(index)}
|
onConfirm={() => this.deleteUser(index)}
|
||||||
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
<Button disabled={disabled} style={{marginBottom: "10px"}} type="primary" danger>{i18next.t("general:Delete")}</Button>
|
<Button disabled={disabled} style={{marginBottom: "10px"}} type="primary" danger>{i18next.t("general:Delete")}</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
|
@ -714,6 +714,7 @@
|
|||||||
"Country/Region": "Land/Region",
|
"Country/Region": "Land/Region",
|
||||||
"Country/Region - Tooltip": "Country/Region",
|
"Country/Region - Tooltip": "Country/Region",
|
||||||
"Edit User": "Benutzer bearbeiten",
|
"Edit User": "Benutzer bearbeiten",
|
||||||
|
"Email cannot be empty": "Email cannot be empty",
|
||||||
"Empty input!": "Empty input!",
|
"Empty input!": "Empty input!",
|
||||||
"Homepage": "Homepage",
|
"Homepage": "Homepage",
|
||||||
"Homepage - Tooltip": "Startseite - Tooltip",
|
"Homepage - Tooltip": "Startseite - Tooltip",
|
||||||
@ -742,6 +743,7 @@
|
|||||||
"Old Password": "Altes Passwort",
|
"Old Password": "Altes Passwort",
|
||||||
"Password": "Passwort",
|
"Password": "Passwort",
|
||||||
"Password Set": "Passwort setzen",
|
"Password Set": "Passwort setzen",
|
||||||
|
"Phone cannot be empty": "Phone cannot be empty",
|
||||||
"Please select avatar from resources": "Please select avatar from resources",
|
"Please select avatar from resources": "Please select avatar from resources",
|
||||||
"Properties": "Eigenschaften",
|
"Properties": "Eigenschaften",
|
||||||
"Properties - Tooltip": "Properties - Tooltip",
|
"Properties - Tooltip": "Properties - Tooltip",
|
||||||
|
@ -714,6 +714,7 @@
|
|||||||
"Country/Region": "Country/Region",
|
"Country/Region": "Country/Region",
|
||||||
"Country/Region - Tooltip": "Country/Region - Tooltip",
|
"Country/Region - Tooltip": "Country/Region - Tooltip",
|
||||||
"Edit User": "Edit User",
|
"Edit User": "Edit User",
|
||||||
|
"Email cannot be empty": "Email cannot be empty",
|
||||||
"Empty input!": "Empty input!",
|
"Empty input!": "Empty input!",
|
||||||
"Homepage": "Homepage",
|
"Homepage": "Homepage",
|
||||||
"Homepage - Tooltip": "Homepage - Tooltip",
|
"Homepage - Tooltip": "Homepage - Tooltip",
|
||||||
@ -742,6 +743,7 @@
|
|||||||
"Old Password": "Old Password",
|
"Old Password": "Old Password",
|
||||||
"Password": "Password",
|
"Password": "Password",
|
||||||
"Password Set": "Password Set",
|
"Password Set": "Password Set",
|
||||||
|
"Phone cannot be empty": "Phone cannot be empty",
|
||||||
"Please select avatar from resources": "Please select avatar from resources",
|
"Please select avatar from resources": "Please select avatar from resources",
|
||||||
"Properties": "Properties",
|
"Properties": "Properties",
|
||||||
"Properties - Tooltip": "Properties - Tooltip",
|
"Properties - Tooltip": "Properties - Tooltip",
|
||||||
|
@ -714,6 +714,7 @@
|
|||||||
"Country/Region": "Pais/Región",
|
"Country/Region": "Pais/Región",
|
||||||
"Country/Region - Tooltip": "Pais/Región - Tooltip",
|
"Country/Region - Tooltip": "Pais/Región - Tooltip",
|
||||||
"Edit User": "Editar usuario",
|
"Edit User": "Editar usuario",
|
||||||
|
"Email cannot be empty": "Email cannot be empty",
|
||||||
"Empty input!": "Campo requerido!",
|
"Empty input!": "Campo requerido!",
|
||||||
"Homepage": "Página de Inicio",
|
"Homepage": "Página de Inicio",
|
||||||
"Homepage - Tooltip": "Página de Inicio - Tooltip",
|
"Homepage - Tooltip": "Página de Inicio - Tooltip",
|
||||||
@ -742,6 +743,7 @@
|
|||||||
"Old Password": "Contraseña anterior",
|
"Old Password": "Contraseña anterior",
|
||||||
"Password": "Contraseña",
|
"Password": "Contraseña",
|
||||||
"Password Set": "Password Set",
|
"Password Set": "Password Set",
|
||||||
|
"Phone cannot be empty": "Phone cannot be empty",
|
||||||
"Please select avatar from resources": "Please select avatar from resources",
|
"Please select avatar from resources": "Please select avatar from resources",
|
||||||
"Properties": "Propiedades",
|
"Properties": "Propiedades",
|
||||||
"Properties - Tooltip": "Properties - Tooltip",
|
"Properties - Tooltip": "Properties - Tooltip",
|
||||||
|
@ -714,6 +714,7 @@
|
|||||||
"Country/Region": "Pays/Région",
|
"Country/Region": "Pays/Région",
|
||||||
"Country/Region - Tooltip": "Country/Region",
|
"Country/Region - Tooltip": "Country/Region",
|
||||||
"Edit User": "Editer l'utilisateur",
|
"Edit User": "Editer l'utilisateur",
|
||||||
|
"Email cannot be empty": "Email cannot be empty",
|
||||||
"Empty input!": "Empty input!",
|
"Empty input!": "Empty input!",
|
||||||
"Homepage": "Page d'accueil",
|
"Homepage": "Page d'accueil",
|
||||||
"Homepage - Tooltip": "Page d'accueil - infobulle",
|
"Homepage - Tooltip": "Page d'accueil - infobulle",
|
||||||
@ -742,6 +743,7 @@
|
|||||||
"Old Password": "Ancien mot de passe",
|
"Old Password": "Ancien mot de passe",
|
||||||
"Password": "Mot de passe",
|
"Password": "Mot de passe",
|
||||||
"Password Set": "Mot de passe défini",
|
"Password Set": "Mot de passe défini",
|
||||||
|
"Phone cannot be empty": "Phone cannot be empty",
|
||||||
"Please select avatar from resources": "Please select avatar from resources",
|
"Please select avatar from resources": "Please select avatar from resources",
|
||||||
"Properties": "Propriétés",
|
"Properties": "Propriétés",
|
||||||
"Properties - Tooltip": "Properties - Tooltip",
|
"Properties - Tooltip": "Properties - Tooltip",
|
||||||
|
@ -714,6 +714,7 @@
|
|||||||
"Country/Region": "国/地域",
|
"Country/Region": "国/地域",
|
||||||
"Country/Region - Tooltip": "Country/Region",
|
"Country/Region - Tooltip": "Country/Region",
|
||||||
"Edit User": "ユーザーを編集",
|
"Edit User": "ユーザーを編集",
|
||||||
|
"Email cannot be empty": "Email cannot be empty",
|
||||||
"Empty input!": "Empty input!",
|
"Empty input!": "Empty input!",
|
||||||
"Homepage": "ホームページ",
|
"Homepage": "ホームページ",
|
||||||
"Homepage - Tooltip": "ホームページ - ツールチップ",
|
"Homepage - Tooltip": "ホームページ - ツールチップ",
|
||||||
@ -742,6 +743,7 @@
|
|||||||
"Old Password": "古いパスワード",
|
"Old Password": "古いパスワード",
|
||||||
"Password": "パスワード",
|
"Password": "パスワード",
|
||||||
"Password Set": "パスワード設定",
|
"Password Set": "パスワード設定",
|
||||||
|
"Phone cannot be empty": "Phone cannot be empty",
|
||||||
"Please select avatar from resources": "Please select avatar from resources",
|
"Please select avatar from resources": "Please select avatar from resources",
|
||||||
"Properties": "プロパティー",
|
"Properties": "プロパティー",
|
||||||
"Properties - Tooltip": "Properties - Tooltip",
|
"Properties - Tooltip": "Properties - Tooltip",
|
||||||
|
@ -714,6 +714,7 @@
|
|||||||
"Country/Region": "Country/Region",
|
"Country/Region": "Country/Region",
|
||||||
"Country/Region - Tooltip": "Country/Region",
|
"Country/Region - Tooltip": "Country/Region",
|
||||||
"Edit User": "Edit User",
|
"Edit User": "Edit User",
|
||||||
|
"Email cannot be empty": "Email cannot be empty",
|
||||||
"Empty input!": "Empty input!",
|
"Empty input!": "Empty input!",
|
||||||
"Homepage": "Homepage",
|
"Homepage": "Homepage",
|
||||||
"Homepage - Tooltip": "Homepage - Tooltip",
|
"Homepage - Tooltip": "Homepage - Tooltip",
|
||||||
@ -742,6 +743,7 @@
|
|||||||
"Old Password": "Old Password",
|
"Old Password": "Old Password",
|
||||||
"Password": "Password",
|
"Password": "Password",
|
||||||
"Password Set": "Password Set",
|
"Password Set": "Password Set",
|
||||||
|
"Phone cannot be empty": "Phone cannot be empty",
|
||||||
"Please select avatar from resources": "Please select avatar from resources",
|
"Please select avatar from resources": "Please select avatar from resources",
|
||||||
"Properties": "Properties",
|
"Properties": "Properties",
|
||||||
"Properties - Tooltip": "Properties - Tooltip",
|
"Properties - Tooltip": "Properties - Tooltip",
|
||||||
|
@ -714,6 +714,7 @@
|
|||||||
"Country/Region": "Страна/регион",
|
"Country/Region": "Страна/регион",
|
||||||
"Country/Region - Tooltip": "Country/Region",
|
"Country/Region - Tooltip": "Country/Region",
|
||||||
"Edit User": "Изменить пользователя",
|
"Edit User": "Изменить пользователя",
|
||||||
|
"Email cannot be empty": "Email cannot be empty",
|
||||||
"Empty input!": "Empty input!",
|
"Empty input!": "Empty input!",
|
||||||
"Homepage": "Главная страница",
|
"Homepage": "Главная страница",
|
||||||
"Homepage - Tooltip": "Главная страница - Подсказки",
|
"Homepage - Tooltip": "Главная страница - Подсказки",
|
||||||
@ -742,6 +743,7 @@
|
|||||||
"Old Password": "Старый пароль",
|
"Old Password": "Старый пароль",
|
||||||
"Password": "Пароль",
|
"Password": "Пароль",
|
||||||
"Password Set": "Пароль установлен",
|
"Password Set": "Пароль установлен",
|
||||||
|
"Phone cannot be empty": "Phone cannot be empty",
|
||||||
"Please select avatar from resources": "Please select avatar from resources",
|
"Please select avatar from resources": "Please select avatar from resources",
|
||||||
"Properties": "Свойства",
|
"Properties": "Свойства",
|
||||||
"Properties - Tooltip": "Properties - Tooltip",
|
"Properties - Tooltip": "Properties - Tooltip",
|
||||||
|
@ -714,6 +714,7 @@
|
|||||||
"Country/Region": "国家/地区",
|
"Country/Region": "国家/地区",
|
||||||
"Country/Region - Tooltip": "国家/地区",
|
"Country/Region - Tooltip": "国家/地区",
|
||||||
"Edit User": "编辑用户",
|
"Edit User": "编辑用户",
|
||||||
|
"Email cannot be empty": "邮箱不能为空",
|
||||||
"Empty input!": "输入为空!",
|
"Empty input!": "输入为空!",
|
||||||
"Homepage": "个人主页",
|
"Homepage": "个人主页",
|
||||||
"Homepage - Tooltip": "个人主页链接",
|
"Homepage - Tooltip": "个人主页链接",
|
||||||
@ -742,6 +743,7 @@
|
|||||||
"Old Password": "旧密码",
|
"Old Password": "旧密码",
|
||||||
"Password": "密码",
|
"Password": "密码",
|
||||||
"Password Set": "密码已设置",
|
"Password Set": "密码已设置",
|
||||||
|
"Phone cannot be empty": "手机号不能为空",
|
||||||
"Please select avatar from resources": "从资源中选择...",
|
"Please select avatar from resources": "从资源中选择...",
|
||||||
"Properties": "属性",
|
"Properties": "属性",
|
||||||
"Properties - Tooltip": "属性",
|
"Properties - Tooltip": "属性",
|
||||||
|
Reference in New Issue
Block a user