(improvement)(login) encrypt password (#1081) (#1116)

This commit is contained in:
zhaodongsheng
2024-06-09 08:16:45 +08:00
committed by GitHub
parent dcb7f21241
commit 5bc88b78a9
15 changed files with 289 additions and 95 deletions

View File

@@ -13,6 +13,7 @@ import { postUserLogin, userRegister } from './services';
import { AUTH_TOKEN_KEY } from '@/common/constants';
import { queryCurrentUser } from '@/services/user';
import { history, useModel } from 'umi';
import {encryptPassword} from "@/utils/utils";
const { Item } = Form;
const LoginPage: React.FC = () => {
@@ -43,21 +44,24 @@ const LoginPage: React.FC = () => {
message.success(msg);
};
// 处理登录按钮响应
const handleLogin = async () => {
const { validateFields } = form;
const content = await validateFields();
await loginDone(content);
await loginDone({...content, password: encryptPassword(content.password)});
};
// 处理注册弹窗确定按钮
const handleRegister = async (values: RegisterFormDetail) => {
const { code } = await userRegister({ ...values });
const enCodeValues = { ...values, password: encryptPassword(values.password) };
const { code } = await userRegister(enCodeValues);
if (code === 200) {
message.success('注册成功');
setCreateModalVisible(false);
// 注册完自动帮用户登录
await loginDone(values);
await loginDone(enCodeValues);
}
};
@@ -103,7 +107,7 @@ const LoginPage: React.FC = () => {
<Input
size="large"
type="password"
placeholder="密码: admin"
placeholder="密码: admin123"
onPressEnter={handleLogin}
prefix={<LockOutlined />}
/>