Commit c7fbcb68 by end

增加重置密码

parent 4d43a812
No preview for this file type
......@@ -67,20 +67,12 @@ class EditPassword extends Component {
const public_key = '047214fe3a249b75b6ba92ee494e0a8a68c0a19893a480b3c28bf06cd5b7d621243c7f6704caa3b43ade6be15de11cabd185611a9edfdcf1b11d7a2478c67b4c1c';
const private_key = '00a2bbe941a177ca9f200d1c4d37e8f0b43b9cd2ea662304a05c064c6416e74d49';
const salt = this.generateCharacter(16);
console.log("validate-salt", salt);
const date = this.getCurrentDay();
console.log("validate-date", date);
const newPassword = "04" + sm2.doEncrypt(password + salt, public_key, 1);
const requestId = "04" + sm2.doEncrypt(id + salt, public_key, 1);
const key = salt + date;
console.log("validate-key", key);
const sign = `id=${requestId}&password=${newPassword}&salt=${salt}&key=${key}`;
console.log("validate-sign", md5(sign));
const parms = {
id: requestId,
......@@ -88,13 +80,7 @@ class EditPassword extends Component {
salt: salt,
sign: md5(sign)
};
if (typeof this.props.accountUpdatePassword !== 'function') {
console.error('accountUpdatePassword 不是一个函数');
return;
}
await this.props.accountUpdatePassword(parms);
await this.props.accountUpdatePassword(parms,"edit");
// 关闭模态框
if (typeof this.props.onCancel === 'function') {
this.props.onCancel(false);
......
......@@ -5,6 +5,8 @@ import StopUser from "../StopUser/StopUser";
import EditUser from "../EditUser/EditUser";
import EditPasswords from "../EditPassword/EditPassword";
import moment from "moment";
import { sm2 } from "sm-crypto";
import md5 from "md5";
class UserTable extends Component {
constructor(props) {
......@@ -93,6 +95,8 @@ class UserTable extends Component {
<a onClick={() => this.handleEditPassWord("修改密码", record)}>
修改密码
</a>
<Divider type="vertical" />
<a onClick={() => this.handleResetPassword(record)}>重置密码</a>
</span>
);
},
......@@ -201,6 +205,82 @@ class UserTable extends Component {
this.props.accountUpdatePassword(values);
});
};
generateCharacter(n) {
var chars = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
];
var res = "";
for (var i = 0; i < n; i++) {
var id = Math.ceil(Math.random() * 35);
res += chars[id];
}
return res;
}
getCurrentDay() {
let date = "";
date = moment(new Date()).format("YYYYMMDD");
return date;
}
handleResetPassword = async (record) => {
try {
const id = record.id;
const password = "Exf@6666";
const public_key =
"047214fe3a249b75b6ba92ee494e0a8a68c0a19893a480b3c28bf06cd5b7d621243c7f6704caa3b43ade6be15de11cabd185611a9edfdcf1b11d7a2478c67b4c1c";
const salt = this.generateCharacter(16);
const date = this.getCurrentDay();
const newPassword = "04" + sm2.doEncrypt(password + salt, public_key, 1);
const requestId = "04" + sm2.doEncrypt(id + salt, public_key, 1);
const key = salt + date;
const sign = `id=${requestId}&password=${newPassword}&salt=${salt}&key=${key}`;
const parms = {
id: requestId,
password: newPassword,
salt: salt,
sign: md5(sign),
};
await this.props.accountUpdatePassword(parms,"reset");
} catch (error) {
console.error("重置密码时发生错误:", error);
}
};
render() {
//dataSource rowKey 报警高 给后台说加可以
// console.log(this.props.records);
......
......@@ -313,7 +313,7 @@ let actions = {
};
},
//修改用户密码
accountUpdatePassword(data) {
accountUpdatePassword(data,type) {
return dispatch => {
// accountUpdatePassword(data)
return request({
......@@ -322,7 +322,12 @@ let actions = {
})
.then(res => {
if (res.code == 1000) {
return message.success("密码修改成功");
if(type=="edit"){
return message.success("密码修改成功");
}
if(type=="reset"){
return message.success("密码重置成功");
}
}
// if (!(res.code == 1000)) {
// message.info(res.subMsg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment