mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-08 09:01:00 +08:00
Remove org API calls in PasswordModal page
This commit is contained in:
@ -410,7 +410,7 @@ class UserEditPage extends React.Component {
|
|||||||
{Setting.getLabel(i18next.t("general:Password"), i18next.t("general:Password - Tooltip"))} :
|
{Setting.getLabel(i18next.t("general:Password"), i18next.t("general:Password - Tooltip"))} :
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={22} >
|
<Col span={22} >
|
||||||
<PasswordModal user={this.state.user} account={this.props.account} disabled={disabled} />
|
<PasswordModal user={this.state.user} organization={this.state.application?.organizationObj} account={this.props.account} disabled={disabled} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
|
@ -17,7 +17,6 @@ import i18next from "i18next";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import * as UserBackend from "../../backend/UserBackend";
|
import * as UserBackend from "../../backend/UserBackend";
|
||||||
import * as Setting from "../../Setting";
|
import * as Setting from "../../Setting";
|
||||||
import * as OrganizationBackend from "../../backend/OrganizationBackend";
|
|
||||||
import * as PasswordChecker from "../PasswordChecker";
|
import * as PasswordChecker from "../PasswordChecker";
|
||||||
|
|
||||||
export const PasswordModal = (props) => {
|
export const PasswordModal = (props) => {
|
||||||
@ -27,6 +26,7 @@ export const PasswordModal = (props) => {
|
|||||||
const [newPassword, setNewPassword] = React.useState("");
|
const [newPassword, setNewPassword] = React.useState("");
|
||||||
const [rePassword, setRePassword] = React.useState("");
|
const [rePassword, setRePassword] = React.useState("");
|
||||||
const {user} = props;
|
const {user} = props;
|
||||||
|
const {organization} = props;
|
||||||
const {account} = props;
|
const {account} = props;
|
||||||
|
|
||||||
const [passwordOptions, setPasswordOptions] = React.useState([]);
|
const [passwordOptions, setPasswordOptions] = React.useState([]);
|
||||||
@ -36,18 +36,9 @@ export const PasswordModal = (props) => {
|
|||||||
const [rePasswordErrorMessage, setRePasswordErrorMessage] = React.useState("");
|
const [rePasswordErrorMessage, setRePasswordErrorMessage] = React.useState("");
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
OrganizationBackend.getOrganizations("admin")
|
if (organization) {
|
||||||
.then((res) => {
|
setPasswordOptions(organization.passwordOptions);
|
||||||
const organizations = (res.msg === undefined) ? res : [];
|
}
|
||||||
// Find the user's corresponding organization
|
|
||||||
const organization = organizations.find((org) => org.name === user.owner);
|
|
||||||
if (organization) {
|
|
||||||
setPasswordOptions(organization.passwordOptions);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`);
|
|
||||||
});
|
|
||||||
}, [user.owner]);
|
}, [user.owner]);
|
||||||
const showModal = () => {
|
const showModal = () => {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
@ -86,44 +77,31 @@ export const PasswordModal = (props) => {
|
|||||||
}
|
}
|
||||||
setConfirmLoading(true);
|
setConfirmLoading(true);
|
||||||
|
|
||||||
OrganizationBackend.getOrganizations("admin").then((res) => {
|
if (organization === null) {
|
||||||
const organizations = (res.msg === undefined) ? res : [];
|
Setting.showMessage("error", "organization is null");
|
||||||
|
setConfirmLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// find the users' corresponding organization
|
const errorMsg = PasswordChecker.checkPasswordComplexity(newPassword, organization.passwordOptions);
|
||||||
let organization = null;
|
if (errorMsg !== "") {
|
||||||
for (let i = 0; i < organizations.length; i++) {
|
Setting.showMessage("error", errorMsg);
|
||||||
if (organizations[i].name === user.owner) {
|
setConfirmLoading(false);
|
||||||
organization = organizations[i];
|
return;
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
UserBackend.setPassword(user.owner, user.name, oldPassword, newPassword)
|
||||||
|
.then((res) => {
|
||||||
|
if (res.status === "ok") {
|
||||||
|
Setting.showMessage("success", i18next.t("user:Password set successfully"));
|
||||||
|
setVisible(false);
|
||||||
|
} else {
|
||||||
|
Setting.showMessage("error", i18next.t(`user:${res.msg}`));
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
.finally(() => {
|
||||||
if (organization === null) {
|
|
||||||
Setting.showMessage("error", "organization is null");
|
|
||||||
setConfirmLoading(false);
|
setConfirmLoading(false);
|
||||||
return;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
const errorMsg = PasswordChecker.checkPasswordComplexity(newPassword, organization.passwordOptions);
|
|
||||||
if (errorMsg !== "") {
|
|
||||||
Setting.showMessage("error", errorMsg);
|
|
||||||
setConfirmLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UserBackend.setPassword(user.owner, user.name, oldPassword, newPassword)
|
|
||||||
.then((res) => {
|
|
||||||
if (res.status === "ok") {
|
|
||||||
Setting.showMessage("success", i18next.t("user:Password set successfully"));
|
|
||||||
setVisible(false);
|
|
||||||
} else {
|
|
||||||
Setting.showMessage("error", i18next.t(`user:${res.msg}`));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setConfirmLoading(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasOldPassword = user.password !== "";
|
const hasOldPassword = user.password !== "";
|
||||||
|
Reference in New Issue
Block a user