Skip to content
Snippets Groups Projects
Commit f3e43a0f authored by tamaina's avatar tamaina
Browse files

refactor

parent b3ec47c3
No related branches found
No related tags found
No related merge requests found
......@@ -80,14 +80,16 @@ export class SignupService {
throw new Error('USED_USERNAME');
}
if (!opts.ignorePreservedUsernames) {
const isTheFirstUser = (await this.usersRepository.countBy({ host: IsNull() })) === 0;
if (!opts.ignorePreservedUsernames || !isTheFirstUser) {
const instance = await this.metaService.fetch(true);
const isPreserved = instance.preservedUsernames.map(x => x.toLowerCase()).includes(username.toLowerCase());
if (isPreserved) {
throw new Error('USED_USERNAME');
}
}
const keyPair = await new Promise<string[]>((res, rej) =>
generateKeyPair('rsa', {
modulusLength: 4096,
......@@ -123,9 +125,7 @@ export class SignupService {
usernameLower: username.toLowerCase(),
host: this.utilityService.toPunyNullable(host),
token: secret,
isRoot: (await this.usersRepository.countBy({
host: IsNull(),
})) === 0,
isRoot: isTheFirstUser,
}));
await transactionalEntityManager.save(new UserKeypair({
......
......@@ -169,7 +169,6 @@ export class SignupApiService {
try {
const { account, secret } = await this.signupService.signup({
username, password, host,
ignorePreservedUsernames: (await this.usersRepository.countBy({ host: IsNull() })) === 0,
});
const res = await this.userEntityService.pack(account, account, {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment