summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/SignupService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/core/SignupService.ts')
-rw-r--r--packages/backend/src/core/SignupService.ts21
1 files changed, 12 insertions, 9 deletions
diff --git a/packages/backend/src/core/SignupService.ts b/packages/backend/src/core/SignupService.ts
index 9fc0c2b34a..f1dd0f0503 100644
--- a/packages/backend/src/core/SignupService.ts
+++ b/packages/backend/src/core/SignupService.ts
@@ -15,13 +15,14 @@ import { MiUserProfile } from '@/models/UserProfile.js';
import { IdService } from '@/core/IdService.js';
import { MiUserKeypair } from '@/models/UserKeypair.js';
import { MiUsedUsername } from '@/models/UsedUsername.js';
-import generateUserToken from '@/misc/generate-native-user-token.js';
+import { generateNativeUserToken } from '@/misc/token.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
-import { InstanceActorService } from '@/core/InstanceActorService.js';
import { bindThis } from '@/decorators.js';
import UsersChart from '@/core/chart/charts/users.js';
import { UtilityService } from '@/core/UtilityService.js';
import { UserService } from '@/core/UserService.js';
+import { SystemAccountService } from '@/core/SystemAccountService.js';
+import { MetaService } from '@/core/MetaService.js';
@Injectable()
export class SignupService {
@@ -42,7 +43,8 @@ export class SignupService {
private userService: UserService,
private userEntityService: UserEntityService,
private idService: IdService,
- private instanceActorService: InstanceActorService,
+ private systemAccountService: SystemAccountService,
+ private metaService: MetaService,
private usersChart: UsersChart,
) {
}
@@ -77,7 +79,7 @@ export class SignupService {
}
// Generate secret
- const secret = generateUserToken();
+ const secret = generateNativeUserToken();
// Check username duplication
if (await this.usersRepository.exists({ where: { usernameLower: username.toLowerCase(), host: IsNull() } })) {
@@ -89,9 +91,7 @@ export class SignupService {
throw new Error('USED_USERNAME');
}
- const isTheFirstUser = !await this.instanceActorService.realLocalUsersPresent();
-
- if (!opts.ignorePreservedUsernames && !isTheFirstUser) {
+ if (!opts.ignorePreservedUsernames && this.meta.rootUserId != null) {
const isPreserved = this.meta.preservedUsernames.map(x => x.toLowerCase()).includes(username.toLowerCase());
if (isPreserved) {
throw new Error('USED_USERNAME');
@@ -132,8 +132,7 @@ export class SignupService {
usernameLower: username.toLowerCase(),
host: this.utilityService.toPunyNullable(host),
token: secret,
- isRoot: isTheFirstUser,
- approved: isTheFirstUser || (opts.approved ?? !this.meta.approvalRequiredForSignup),
+ approved: opts.approved ?? !this.meta.approvalRequiredForSignup,
signupReason: reason,
enableRss: false,
}));
@@ -159,6 +158,10 @@ export class SignupService {
this.usersChart.update(account, true);
this.userService.notifySystemWebhook(account, 'userCreated');
+ if (this.meta.rootUserId == null) {
+ await this.metaService.update({ rootUserId: account.id });
+ }
+
return { account, secret };
}
}