返回 AiToEarn
user.class.ts
根目录 / project / aitoearn-electron / server / src / user / class / user.class.ts
1 /*
2 * @Author: nevin
3 * @Date: 2024-06-28 11:00:39
4 * @LastEditTime: 2025-02-26 09:37:18
5 * @LastEditors: nevin
6 * @Description:
7 */
8 import { User } from '../../db/schema/user.schema';
9 import { getRandomString } from '../../util';
10 import { encryptPassword } from '../../util/password.util';
11 import { WxInfo } from '../interfaces/wx-info.interface';
12
13 export class NewUserByPassword extends User {
14 constructor(phone: string, inPassword: string) {
15 super();
16
17 this.name = `用户_${Date.now()}`;
18 this.phone = phone;
19 const { password, salt } = encryptPassword(inPassword);
20 this.password = password;
21 this.salt = salt;
22 }
23 }
24
25 export class NewUserByPhone extends User {
26 constructor(phone: string) {
27 super();
28 this.phone = phone;
29 this.name = `用户_${getRandomString(8)}`;
30 }
31 }
32
33 export class NewUserByMail extends User {
34 constructor(mail: string, inPassword: string) {
35 super();
36 this.mail = mail;
37 this.name = `用户_${getRandomString(8)}`;
38 const { password, salt } = encryptPassword(inPassword);
39 this.password = password;
40 this.salt = salt;
41 }
42 }
43
44 export class NewUserByWx extends User {
45 constructor(wxInfo: WxInfo) {
46 super();
47 this.wxOpenid = wxInfo.openid;
48 this.wxUnionid = wxInfo.unionid;
49 this.name = `用户_${getRandomString(8)}`;
50 }
51 }
52
52 lines TYPESCRIPT