Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/abstract/login/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { v4 } from "uuid";
import { ServiceCloudStorageUserFiles } from "../../v1/service/cloudStorage/CloudStorageUserFiles";
import { ServiceUserPhone } from "../../v1/service/user/UserPhone";
import { FileConvertStep, FileResourceType } from "../../model/cloudStorage/Constants";
import { ServiceUser } from "../../v1/service/user/User";

export abstract class AbstractLogin {
protected readonly userUUID: string;
Expand Down Expand Up @@ -49,6 +50,7 @@ export abstract class AbstractLogin {
...userInfo,
userUUID: this.userUUID,
hasPhone: await ServiceUserPhone.exist(this.userUUID),
hasPassword: await ServiceUser.hasPassword(this.userUUID),
}),
60 * 60,
);
Expand Down
2 changes: 2 additions & 0 deletions src/v1/controller/login/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class Login extends AbstractController<RequestType, ResponseType> {
}),
userUUID: this.userUUID,
hasPhone: await this.svc.userPhone.exist(),
hasPassword: await this.svc.user.hasPassword(),
},
};
}
Expand Down Expand Up @@ -138,4 +139,5 @@ interface ResponseType {
token: string;
userUUID: string;
hasPhone: boolean;
hasPassword: boolean;
}
2 changes: 2 additions & 0 deletions src/v1/controller/login/Process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class LoginProcess extends AbstractController<RequestType, ResponseType>
userUUID: "",
token: "",
hasPhone: false,
hasPassword: false,
},
};
}
Expand Down Expand Up @@ -89,4 +90,5 @@ type ResponseType = {
userUUID: string;
token: string;
hasPhone: boolean;
hasPassword: boolean;
};
3 changes: 3 additions & 0 deletions src/v1/controller/login/apple/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { v4 } from "uuid";
import { LoginPlatform, Status } from "../../../../constants/Project";
import { Apple } from "../../../../constants/Config";
import { ServiceUserPhone } from "../../../service/user/UserPhone";
import { ServiceUser } from "../../../service/user/User";

@Controller<RequestType, ResponseType>({
method: "post",
Expand Down Expand Up @@ -78,6 +79,7 @@ export class AppleJWT extends AbstractController<RequestType, ResponseType> {
loginSource: LoginPlatform.Apple,
}),
hasPhone: await ServiceUserPhone.exist(this.userUUID),
hasPassword: await ServiceUser.hasPassword(this.userUUID),
},
};
}
Expand All @@ -100,4 +102,5 @@ interface ResponseType {
userUUID: string;
token: string;
hasPhone: boolean;
hasPassword: boolean;
}
2 changes: 2 additions & 0 deletions src/v1/controller/login/phone/Phone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class PhoneLogin extends AbstractController<RequestType, ResponseType> {
loginSource: LoginPlatform.Phone,
}),
hasPhone: true,
hasPassword: await loginPhone.svc.user.hasPassword(),
},
} as const;

Expand Down Expand Up @@ -145,4 +146,5 @@ interface ResponseType {
userUUID: string;
token: string;
hasPhone: true;
hasPassword: boolean;
}
3 changes: 3 additions & 0 deletions src/v1/controller/login/weChat/mobile/Callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Status } from "../../../../../constants/Project";
import { parseError } from "../../../../../logger";
import { WeChat } from "../../../../../constants/Config";
import { ServiceUserPhone } from "../../../../service/user/UserPhone";
import { ServiceUser } from "../../../../service/user/User";

@Controller<RequestType, ResponseType>({
method: "get",
Expand Down Expand Up @@ -42,6 +43,7 @@ export class WechatMobileCallback extends AbstractController<RequestType, Respon
data: {
...result,
hasPhone: await ServiceUserPhone.exist(result.userUUID),
hasPassword: await ServiceUser.hasPassword(result.userUUID),
},
};
}
Expand All @@ -66,4 +68,5 @@ interface ResponseType {
userUUID: string;
token: string;
hasPhone: boolean;
hasPassword: boolean;
}
12 changes: 12 additions & 0 deletions src/v1/service/user/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import { UpdateResult } from "typeorm/query-builder/result/UpdateResult";
export class ServiceUser {
constructor(private readonly userUUID: string) {}

public async hasPassword(): Promise<boolean> {
return await ServiceUser.hasPassword(this.userUUID);
}

public static async hasPassword(userUUID: string): Promise<boolean> {
const result = await UserDAO().findOne(["user_password"], {
user_uuid: userUUID,
});

return Boolean(result && result.user_password);
}

public async create(
data: {
userName: string;
Expand Down
5 changes: 4 additions & 1 deletion src/v2/services/user/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ export class UserEmailService {

await Promise.all([createUser, createUserEmail, setupGuidePPTX]);

const result = {
const result: EmailRegisterReturn = {
name: userName,
avatarURL: "",
userUUID,
token: await jwtSign(userUUID),
hasPhone: false,
hasPassword: true,
};

await UserEmailService.clearVerificationCode(email);
Expand Down Expand Up @@ -200,6 +201,7 @@ export class UserEmailService {
userUUID: userUUIDByEmail,
token: await jwtSign(userUUIDByEmail),
hasPhone: await this.hasPhone(userUUIDByEmail),
hasPassword: true,
};
}

Expand Down Expand Up @@ -308,6 +310,7 @@ export type EmailRegisterReturn = {
userUUID: string;
token: string;
hasPhone: boolean;
hasPassword: boolean;
};

export type EmailLoginReturn = EmailRegisterReturn;
5 changes: 4 additions & 1 deletion src/v2/services/user/phone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ export class UserPhoneService {

await Promise.all([createUser, createUserPhone, setupGuidePPTX]);

const result = {
const result: PhoneRegisterReturn = {
name: userName,
avatarURL: "",
userUUID,
token: await jwtSign(userUUID),
hasPhone: true,
hasPassword: true,
};

await UserPhoneService.clearVerificationCode(safePhone);
Expand Down Expand Up @@ -200,6 +201,7 @@ export class UserPhoneService {
userUUID: userUUIDByPhone,
token: await jwtSign(userUUIDByPhone),
hasPhone: true,
hasPassword: true,
};
}

Expand Down Expand Up @@ -272,6 +274,7 @@ export type PhoneRegisterReturn = {
userUUID: string;
token: string;
hasPhone: boolean;
hasPassword: boolean;
};

export type PhoneLoginReturn = PhoneRegisterReturn;
9 changes: 9 additions & 0 deletions src/v2/services/user/rebind-phone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export class UserRebindPhoneService {
userUUID: original.user_uuid,
token: await jwtSign(original.user_uuid),
hasPhone: true,
hasPassword: await this.hasPassword(original.user_uuid),
rebind: status,
};
} else {
Expand All @@ -194,6 +195,13 @@ export class UserRebindPhoneService {
return elapsedTime > MessageIntervalSecond;
}

private async hasPassword(userUUID: string): Promise<boolean> {
const user = await userDAO.findOne(this.DBTransaction, ["user_password"], {
user_uuid: userUUID,
});
return Boolean(user?.user_password);
}

private async tryUpdate(
dao: DAO<UserPlatform>,
user_uuid: string,
Expand Down Expand Up @@ -275,5 +283,6 @@ export type UserRebindReturn = {
token: string;
userUUID: string;
hasPhone: boolean;
hasPassword: boolean;
rebind: RebindStatus;
};