fix: 注册用户、修改用户密码MD5
This commit is contained in:
parent
daa896d7de
commit
9adb8adede
@ -1,3 +1,4 @@
|
||||
import { Md5 } from 'ts-md5';
|
||||
import { $t } from '@/locales';
|
||||
|
||||
/**
|
||||
@ -84,3 +85,15 @@ export function tagColor(index: number) {
|
||||
|
||||
return tagMap[index % 5];
|
||||
}
|
||||
|
||||
/**
|
||||
* MD-5 哈希
|
||||
*
|
||||
* @param text 明文
|
||||
* @returns md5哈希
|
||||
*/
|
||||
export function md5(text: string): string {
|
||||
const md5Digest = new Md5();
|
||||
md5Digest.appendAsciiStr(text);
|
||||
return md5Digest.end() as string;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive } from 'vue';
|
||||
import { Md5 } from 'ts-md5';
|
||||
import { md5 } from '@/utils/common';
|
||||
import { $t } from '@/locales';
|
||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||
import { useAuthStore } from '@/store/modules/auth';
|
||||
@ -32,9 +32,7 @@ const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||
|
||||
async function handleSubmit() {
|
||||
await validate();
|
||||
const md5 = new Md5();
|
||||
md5.appendAsciiStr(model.password);
|
||||
const password: string = md5.end() as string;
|
||||
const password = md5(model.password);
|
||||
await authStore.login(model.userName, password);
|
||||
}
|
||||
</script>
|
||||
|
@ -4,6 +4,7 @@ import type { OptionValue } from 'naive-ui/es/transfer/src/interface';
|
||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||
import OperateDrawer from '@/components/common/operate-drawer.vue';
|
||||
import { $t } from '@/locales';
|
||||
import { md5 } from '@/utils/common';
|
||||
import { fetchAddUser, fetchEditUser, fetchGetAllGroupConfigList } from '@/service/api';
|
||||
import { groupConfigYesOrNoOptions, roleRecordOptions } from '@/constants/business';
|
||||
import Permission = Api.UserManager.Permission;
|
||||
@ -101,14 +102,31 @@ async function handleSubmit() {
|
||||
// request
|
||||
if (props.operateType === 'add') {
|
||||
const { username, password, checkPassword, role, permissions } = model;
|
||||
const { error } = await fetchAddUser({ username, password, checkPassword, role, permissions });
|
||||
const passwordMd5 = md5(password);
|
||||
const checkPasswordMd5 = md5(checkPassword);
|
||||
const { error } = await fetchAddUser({
|
||||
username,
|
||||
password: passwordMd5,
|
||||
checkPassword: checkPasswordMd5,
|
||||
role,
|
||||
permissions
|
||||
});
|
||||
if (error) return;
|
||||
window.$message?.success($t('common.addSuccess'));
|
||||
}
|
||||
|
||||
if (props.operateType === 'edit') {
|
||||
const { id, username, password, checkPassword, role, permissions } = model;
|
||||
const { error } = await fetchEditUser({ id, username, password, checkPassword, role, permissions });
|
||||
const passwordMd5 = md5(password);
|
||||
const checkPasswordMd5 = md5(checkPassword);
|
||||
const { error } = await fetchEditUser({
|
||||
id,
|
||||
username,
|
||||
password: passwordMd5,
|
||||
checkPassword: checkPasswordMd5,
|
||||
role,
|
||||
permissions
|
||||
});
|
||||
if (error) return;
|
||||
window.$message?.success($t('common.updateSuccess'));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user