Skip to content

Commit 4776c28

Browse files
authored
refactor(sensitive): log user name and wechat name usage (#726)
1 parent 21aa4bb commit 4776c28

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

src/model/user/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export enum SensitiveType {
22
Phone = "phone",
33
Avatar = "avatar",
4+
Name = "name",
5+
WeChatName = "wechat_name",
46
}

src/v1/controller/login/platforms/LoginWechat.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ServiceCloudStorageFiles } from "../../../service/cloudStorage/CloudSto
1010
import { ServiceCloudStorageConfigs } from "../../../service/cloudStorage/CloudStorageConfigs";
1111
import { ServiceCloudStorageUserFiles } from "../../../service/cloudStorage/CloudStorageUserFiles";
1212
import { dataSource } from "../../../../thirdPartyService/TypeORMService";
13+
import { ServiceUserSensitive } from "../../../service/user/UserSensitive";
1314

1415
@Login()
1516
export class LoginWechat extends AbstractLogin {
@@ -21,6 +22,7 @@ export class LoginWechat extends AbstractLogin {
2122
this.svc = {
2223
user: new ServiceUser(this.userUUID),
2324
userWeChat: new ServiceUserWeChat(this.userUUID),
25+
userSensitive: new ServiceUserSensitive(this.userUUID),
2426
cloudStorageFiles: new ServiceCloudStorageFiles(),
2527
cloudStorageConfigs: new ServiceCloudStorageConfigs(this.userUUID),
2628
cloudStorageUserFiles: new ServiceCloudStorageUserFiles(this.userUUID),
@@ -32,10 +34,12 @@ export class LoginWechat extends AbstractLogin {
3234
const createUser = this.svc.user.create(info, t);
3335

3436
const createUserWeChat = this.svc.userWeChat.create(info, t);
37+
const createUserSensitive = this.svc.userSensitive.wechatName({ name: info.userName }, t);
3538

3639
return await Promise.all([
3740
createUser,
3841
createUserWeChat,
42+
createUserSensitive,
3943
this.setGuidePPTX(this.svc, t),
4044
]);
4145
});
@@ -80,7 +84,7 @@ export class LoginWechat extends AbstractLogin {
8084
};
8185
}
8286

83-
private static async wechatRequest<T>(url: string): Promise<T> {
87+
private static async wechatRequest<T extends {}>(url: string): Promise<T> {
8488
const response: AxiosResponse<T | WeChatRequestFailed> = await ax.get(url);
8589

8690
if ("errmsg" in response.data) {
@@ -94,6 +98,7 @@ export class LoginWechat extends AbstractLogin {
9498
interface RegisterService {
9599
user: ServiceUser;
96100
userWeChat: ServiceUserWeChat;
101+
userSensitive: ServiceUserSensitive,
97102
cloudStorageFiles: ServiceCloudStorageFiles;
98103
cloudStorageUserFiles: ServiceCloudStorageUserFiles;
99104
cloudStorageConfigs: ServiceCloudStorageConfigs;

src/v1/controller/user/binding/platform/wechat/Binding.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ServiceUserWeChat } from "../../../../../service/user/UserWeChat";
1010
import { ControllerError } from "../../../../../../error/ControllerError";
1111
import { ErrorCode } from "../../../../../../ErrorCode";
1212
import { Status } from "../../../../../../constants/Project";
13+
import { ServiceUserSensitive } from "../../../../../service/user/UserSensitive";
1314

1415
@Controller<RequestType, any>({
1516
method: "get",
@@ -124,6 +125,7 @@ const wechatCallback = async (
124125
}
125126

126127
const wechatSVC = new ServiceUserWeChat(userUUID);
128+
const sensitiveSVC = new ServiceUserSensitive(userUUID);
127129

128130
const exist = await wechatSVC.exist();
129131
if (exist) {
@@ -139,6 +141,7 @@ const wechatCallback = async (
139141
}
140142

141143
await wechatSVC.create(userInfo);
144+
await sensitiveSVC.wechatName({ name: userInfo.userName });
142145
};
143146

144147
interface RequestType {

src/v1/controller/user/rename/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Status } from "../../../../constants/Project";
66
import { aliGreenText } from "../../../utils/AliGreen";
77
import { ControllerError } from "../../../../error/ControllerError";
88
import { ErrorCode } from "../../../../ErrorCode";
9+
import { ServiceUserSensitive } from "../../../service/user/UserSensitive";
910

1011
@Controller<RequestType, ResponseType>({
1112
method: "post",
@@ -29,13 +30,15 @@ export class Rename extends AbstractController<RequestType, ResponseType> {
2930

3031
public readonly svc: {
3132
user: ServiceUser;
33+
userSensitive: ServiceUserSensitive;
3234
};
3335

3436
public constructor(params: ControllerClassParams) {
3537
super(params);
3638

3739
this.svc = {
3840
user: new ServiceUser(this.userUUID),
41+
userSensitive: new ServiceUserSensitive(this.userUUID),
3942
};
4043
}
4144

@@ -45,6 +48,7 @@ export class Rename extends AbstractController<RequestType, ResponseType> {
4548
}
4649

4750
await this.svc.user.updateName(this.body.name);
51+
await this.svc.userSensitive.name({ name: this.body.name });
4852

4953
return {
5054
status: Status.Success,

src/v1/service/user/UserSensitive.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,31 @@ export class ServiceUserSensitive {
3434
content: data.avatarURL,
3535
});
3636
}
37+
38+
public async name(
39+
data: {
40+
name: string;
41+
},
42+
t?: EntityManager,
43+
): Promise<InsertResult> {
44+
return await UserSensitiveDAO(t).insert({
45+
user_uuid: this.userUUID,
46+
type: SensitiveType.Name,
47+
content: data.name,
48+
});
49+
}
50+
51+
public async wechatName(
52+
data: {
53+
name: string;
54+
},
55+
t?: EntityManager,
56+
): Promise<InsertResult> {
57+
return await UserSensitiveDAO(t).insert({
58+
user_uuid: this.userUUID,
59+
type: SensitiveType.WeChatName,
60+
content: data.name,
61+
});
62+
}
63+
3764
}

src/v2/services/user/update.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export class UserUpdateService {
2525
user_uuid: this.userUUID,
2626
},
2727
);
28+
await userSensitiveDAO.insert(this.DBTransaction, {
29+
user_uuid: this.userUUID,
30+
type: SensitiveType.Name,
31+
content: newUserName,
32+
});
2833
this.logger.debug("user name updated", {
2934
userUpdate: {
3035
newUserName,

0 commit comments

Comments
 (0)