mirror of
https://github.com/certd/certd.git
synced 2026-06-28 22:47:35 +08:00
perf: 优化邀请注册流程
This commit is contained in:
@@ -8,7 +8,6 @@ import { LoginService } from "../../../modules/login/service/login-service.js";
|
||||
import { OauthBoundService } from "../../../modules/login/service/oauth-bound-service.js";
|
||||
import { AddonGetterService } from "../../../modules/pipeline/service/addon-getter-service.js";
|
||||
import { UserEntity } from "../../../modules/sys/authority/entity/user.js";
|
||||
import { UserService } from "../../../modules/sys/authority/service/user-service.js";
|
||||
import { IOauthProvider } from "../../../plugins/plugin-oauth/api.js";
|
||||
|
||||
type OauthProviderSetting = {
|
||||
@@ -42,8 +41,6 @@ export class ConnectController extends BaseController {
|
||||
loginService: LoginService;
|
||||
@Inject()
|
||||
codeService: CodeService;
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
|
||||
@Inject()
|
||||
oauthBoundService: OauthBoundService;
|
||||
@@ -199,7 +196,7 @@ export class ConnectController extends BaseController {
|
||||
}
|
||||
|
||||
@Post("/autoRegister", { description: Constants.per.guest })
|
||||
public async autoRegister(@Body(ALL) body: { validationCode: string; type: string }) {
|
||||
public async autoRegister(@Body(ALL) body: { validationCode: string; type: string; inviteCode?: string }) {
|
||||
const validationValue = this.codeService.getValidationValue(body.validationCode);
|
||||
if (!validationValue) {
|
||||
throw new Error("第三方认证授权已过期");
|
||||
@@ -212,7 +209,7 @@ export class ConnectController extends BaseController {
|
||||
newUser.nickName = userInfo.nickName || simpleNanoId(6);
|
||||
newUser.email = userInfo.email || "";
|
||||
|
||||
newUser = await this.userService.register("username", newUser, async txManager => {
|
||||
newUser = await this.loginService.register("username", newUser, body.inviteCode, async txManager => {
|
||||
const oauthBound: OauthBoundEntity = new OauthBoundEntity();
|
||||
oauthBound.userId = newUser.id;
|
||||
oauthBound.type = oauthType;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { ALL, Body, Controller, Inject, Post, Provide, RequestIP } from "@midwayjs/core";
|
||||
import { BaseController, Constants, SysSettingsService } from "@certd/lib-server";
|
||||
import { RegisterType, UserService } from "../../../modules/sys/authority/service/user-service.js";
|
||||
import { RegisterType } from "../../../modules/sys/authority/service/user-service.js";
|
||||
import { CodeService } from "../../../modules/basic/service/code-service.js";
|
||||
import { checkComm, checkPlus } from "@certd/plus-core";
|
||||
import { InviteService } from "@certd/commercial-core";
|
||||
import { LoginService } from "../../../modules/login/service/login-service.js";
|
||||
|
||||
export type RegisterReq = {
|
||||
type: RegisterType;
|
||||
@@ -24,16 +24,13 @@ export type RegisterReq = {
|
||||
@Controller("/api/")
|
||||
export class RegisterController extends BaseController {
|
||||
@Inject()
|
||||
userService: UserService;
|
||||
loginService: LoginService;
|
||||
@Inject()
|
||||
codeService: CodeService;
|
||||
|
||||
@Inject()
|
||||
sysSettingsService: SysSettingsService;
|
||||
|
||||
@Inject()
|
||||
inviteService: InviteService;
|
||||
|
||||
@Post("/register", { description: Constants.per.guest })
|
||||
public async register(
|
||||
@Body(ALL)
|
||||
@@ -62,9 +59,7 @@ export class RegisterController extends BaseController {
|
||||
username: body.username,
|
||||
password: body.password,
|
||||
} as any;
|
||||
const newUser = await this.userService.register(body.type, registerUser, async txManager => {
|
||||
await this.inviteService.bindInvitee({ manager: txManager }, { inviteeUserId: registerUser.id, inviteCode: body.inviteCode });
|
||||
});
|
||||
const newUser = await this.loginService.register(body.type, registerUser, body.inviteCode);
|
||||
return this.ok(newUser);
|
||||
} else if (body.type === "mobile") {
|
||||
if (sysPublicSettings.mobileRegisterEnabled === false) {
|
||||
@@ -84,9 +79,7 @@ export class RegisterController extends BaseController {
|
||||
mobile: body.mobile,
|
||||
password: body.password,
|
||||
} as any;
|
||||
const newUser = await this.userService.register(body.type, registerUser, async txManager => {
|
||||
await this.inviteService.bindInvitee({ manager: txManager }, { inviteeUserId: registerUser.id, inviteCode: body.inviteCode });
|
||||
});
|
||||
const newUser = await this.loginService.register(body.type, registerUser, body.inviteCode);
|
||||
return this.ok(newUser);
|
||||
} else if (body.type === "email") {
|
||||
if (sysPublicSettings.emailRegisterEnabled === false) {
|
||||
@@ -103,9 +96,7 @@ export class RegisterController extends BaseController {
|
||||
email: body.email,
|
||||
password: body.password,
|
||||
} as any;
|
||||
const newUser = await this.userService.register(body.type, registerUser, async txManager => {
|
||||
await this.inviteService.bindInvitee({ manager: txManager }, { inviteeUserId: registerUser.id, inviteCode: body.inviteCode });
|
||||
});
|
||||
const newUser = await this.loginService.register(body.type, registerUser, body.inviteCode);
|
||||
return this.ok(newUser);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user