chore: change password

pull/21/merge
xiaojunnuo 2023-06-28 23:15:37 +08:00
parent f5493c542b
commit 2bcab76f5a
7 changed files with 177 additions and 9 deletions

View File

@ -20,9 +20,7 @@
"axios": "^1.4.0",
"node-forge": "^1.3.1",
"nodemailer": "^6.9.3",
"qs": "^6.11.2",
"react-native-get-random-values": "^1.9.0",
"uuid": "^8.3.2"
"qs": "^6.11.2"
},
"devDependencies": {
"@certd/acme-client": "^1.1.1",

View File

@ -7,10 +7,6 @@ import { IEmailService } from "../service";
import { IContext } from "../core";
import { AxiosInstance } from "axios";
//解决 uuid random-values not support 问题
// https://github.com/uuidjs/uuid#getrandomvalues-not-supported
import "react-native-get-random-values";
import { v4 as uuidv4 } from "uuid";
export enum ContextScope {
global,
pipeline,
@ -82,16 +78,19 @@ export abstract class AbstractTaskPlugin implements ITaskPlugin {
this.ctx = ctx;
}
randomFileId() {
return Math.random().toString(36).substring(2, 9);
}
linkFile(file: FileItem) {
this._result.files!.push({
...file,
id: uuidv4(),
id: this.randomFileId(),
});
}
saveFile(filename: string, file: Buffer) {
const filePath = this.ctx.fileStore.writeFile(filename, file);
this._result.files!.push({
id: uuidv4(),
id: this.randomFileId(),
filename,
path: filePath,
});

View File

@ -55,6 +55,16 @@ export const certdResources = [
icon: "ion:mail-outline",
auth: true
}
},
{
title: "账号信息",
name: "userProfile",
path: "/certd/mine/user-profile",
component: "/certd/mine/user-profile.vue",
meta: {
icon: "ion:person-outline",
auth: true
}
}
]
}

View File

@ -0,0 +1,16 @@
import { request } from "/src/api/service";
export async function getMineInfo() {
return request({
url: "/mine/info",
method: "POST"
});
}
export async function changePassword(form: any) {
return request({
url: "/mine/changePassword",
method: "POST",
data: form
});
}

View File

@ -0,0 +1,98 @@
<template>
<fs-page>
<div class="p-4">
<a-descriptions title="我的信息" bordered>
<a-descriptions-item label="用户名">{{ userInfo.userInfoname }}</a-descriptions-item>
<a-descriptions-item label="昵称">{{ userInfo.nickName }}</a-descriptions-item>
<a-descriptions-item label="邮箱">{{ userInfo.email }}</a-descriptions-item>
<a-descriptions-item label="手机号">{{ userInfo.phoneCode }}{{ userInfo.mobile }}</a-descriptions-item>
<a-descriptions-item label="修改密码">
<a-button type="primary" @click="changePassword"></a-button>
</a-descriptions-item>
</a-descriptions>
</div>
</fs-page>
</template>
<script lang="ts" setup>
import * as api from "./api";
import { Ref, ref } from "vue";
import { CrudOptions, useColumns, useFormWrapper } from "@fast-crud/fast-crud";
const userInfo: Ref = ref({});
const getUserInfo = async () => {
userInfo.value = await api.getMineInfo();
};
getUserInfo();
let passwordFormRef = ref();
const validatePass1 = async (rule: any, value: any) => {
if (value === "") {
throw new Error("请输入密码");
}
if (passwordFormRef.value.getFormData().confirmNewPassword !== "") {
passwordFormRef.value.formRef.formRef.validateFields(["confirmNewPassword"]);
}
};
const validatePass2 = async (rule: any, value: any) => {
if (value === "") {
throw new Error("请再次输入密码");
} else if (value !== passwordFormRef.value.getFormData().newPassword) {
throw new Error("两次输入密码不一致!");
}
};
const { openDialog } = useFormWrapper();
const { buildFormOptions } = useColumns();
const passwordFormOptions: CrudOptions = {
form: {
col: {
span: 24
},
wrapper: {
width: "500px"
},
async doSubmit({ form }) {
await api.changePassword(form);
}
},
columns: {
password: {
title: "旧密码",
type: "password",
form: {
rules: [{ required: true, message: "请输入旧密码" }]
}
},
newPassword: {
title: "新密码",
type: "password",
form: {
rules: [
{ required: true, message: "请输入确认密码" },
//@ts-ignore
{ validator: validatePass1, trigger: "blur" }
]
}
},
confirmNewPassword: {
title: "确认新密码",
type: "password",
form: {
rules: [
{ required: true, message: "请输入确认密码" },
//@ts-ignore
{ validator: validatePass2, trigger: "blur" }
]
}
}
}
};
async function changePassword() {
const formOptions = buildFormOptions(passwordFormOptions);
formOptions.newInstance = true; //
passwordFormRef.value = await openDialog(formOptions);
}
</script>

View File

@ -142,4 +142,17 @@ export class UserService extends BaseService<UserEntity> {
delete newUser.password;
return newUser;
}
async changePassword(userId: any, form: any) {
const user = await this.info(userId);
if (!this.checkPassword(form.password, user.password)) {
throw new CommonException('原密码错误');
}
const param = {
id: userId,
password: form.newPassword,
};
await this.update(param);
}
}

View File

@ -0,0 +1,34 @@
import {
ALL,
Body,
Controller,
Inject,
Post,
Provide,
} from '@midwayjs/decorator';
import { BaseController } from '../../../basic/base-controller';
import { Constants } from '../../../basic/constants';
import { UserService } from '../../authority/service/user-service';
/**
*/
@Provide()
@Controller('/api/mine')
export class MineController extends BaseController {
@Inject()
userService: UserService;
@Post('/info', { summary: Constants.per.authOnly })
public async info() {
const userId = this.getUserId();
const user = await this.userService.info(userId);
delete user.password;
return this.ok(user);
}
@Post('/changePassword', { summary: Constants.per.authOnly })
public async changePassword(@Body(ALL) body: any) {
const userId = this.getUserId();
await this.userService.changePassword(userId, body);
return this.ok({});
}
}