summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/SignupApiService.ts
diff options
context:
space:
mode:
authorMar0xy <marie@kaifa.ch>2023-10-18 02:41:36 +0200
committerMar0xy <marie@kaifa.ch>2023-10-18 02:41:36 +0200
commit2f2d88dcfc76bac6815d60fa9915b8e797853292 (patch)
treefa3e903e9444ee4b92d91a6ff58264a4387d7523 /packages/backend/src/server/api/SignupApiService.ts
parentchore: change some misskey references to sharkey (diff)
downloadsharkey-2f2d88dcfc76bac6815d60fa9915b8e797853292.tar.gz
sharkey-2f2d88dcfc76bac6815d60fa9915b8e797853292.tar.bz2
sharkey-2f2d88dcfc76bac6815d60fa9915b8e797853292.zip
add: Require Approval for Signup
Diffstat (limited to 'packages/backend/src/server/api/SignupApiService.ts')
-rw-r--r--packages/backend/src/server/api/SignupApiService.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/backend/src/server/api/SignupApiService.ts b/packages/backend/src/server/api/SignupApiService.ts
index 02e5cd4fdf..53f770e172 100644
--- a/packages/backend/src/server/api/SignupApiService.ts
+++ b/packages/backend/src/server/api/SignupApiService.ts
@@ -22,6 +22,7 @@ import { bindThis } from '@/decorators.js';
import { L_CHARS, secureRndstr } from '@/misc/secure-rndstr.js';
import { SigninService } from './SigninService.js';
import type { FastifyRequest, FastifyReply } from 'fastify';
+import instance from './endpoints/charts/instance.js';
@Injectable()
export class SignupApiService {
@@ -63,6 +64,7 @@ export class SignupApiService {
host?: string;
invitationCode?: string;
emailAddress?: string;
+ reason?: string;
'hcaptcha-response'?: string;
'g-recaptcha-response'?: string;
'turnstile-response'?: string;
@@ -100,6 +102,7 @@ export class SignupApiService {
const password = body['password'];
const host: string | null = process.env.NODE_ENV === 'test' ? (body['host'] ?? null) : null;
const invitationCode = body['invitationCode'];
+ const reason = body['reason'];
const emailAddress = body['emailAddress'];
if (instance.emailRequiredForSignup) {
@@ -115,6 +118,13 @@ export class SignupApiService {
}
}
+ if (instance.approvalRequiredForSignup) {
+ if (reason == null || typeof reason !== 'string') {
+ reply.code(400);
+ return;
+ }
+ }
+
let ticket: MiRegistrationTicket | null = null;
if (instance.disableRegistration) {
@@ -170,6 +180,7 @@ export class SignupApiService {
email: emailAddress!,
username: username,
password: hash,
+ reason: reason,
}).then(x => this.userPendingsRepository.findOneByOrFail(x.identifiers[0]));
const link = `${this.config.url}/signup-complete/${code}`;
@@ -187,6 +198,19 @@ export class SignupApiService {
reply.code(204);
return;
+ } else if (instance.approvalRequiredForSignup) {
+ await this.signupService.signup({
+ username, password, host, reason,
+ });
+
+ if (emailAddress) {
+ this.emailService.sendEmail(emailAddress, 'Approval pending',
+ 'Congratulations! Your account is now pending approval. You will get notified when you have been accepted.',
+ 'Congratulations! Your account is now pending approval. You will get notified when you have been accepted.');
+ }
+
+ reply.code(204);
+ return;
} else {
try {
const { account, secret } = await this.signupService.signup({
@@ -222,12 +246,15 @@ export class SignupApiService {
const code = body['code'];
+ const instance = await this.metaService.fetch(true);
+
try {
const pendingUser = await this.userPendingsRepository.findOneByOrFail({ code });
const { account, secret } = await this.signupService.signup({
username: pendingUser.username,
passwordHash: pendingUser.password,
+ reason: pendingUser.reason,
});
this.userPendingsRepository.delete({
@@ -250,6 +277,11 @@ export class SignupApiService {
pendingUserId: null,
});
}
+
+ if (instance.approvalRequiredForSignup) {
+ reply.code(204);
+ return;
+ }
return this.signinService.signin(request, reply, account as MiLocalUser);
} catch (err) {