mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 17:55:17 -04:00

Co-authored-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu>
32 lines
948 B
TypeScript
32 lines
948 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
import { CanActivate, Inject, Injectable } from '@nestjs/common';
|
|
|
|
import authConfiguration, { AuthConfig } from '../../../config/auth.config';
|
|
import { FeatureDisabledError } from '../../../errors/errors';
|
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
|
|
|
@Injectable()
|
|
export class RegistrationEnabledGuard implements CanActivate {
|
|
constructor(
|
|
private readonly logger: ConsoleLoggerService,
|
|
@Inject(authConfiguration.KEY)
|
|
private authConfig: AuthConfig,
|
|
) {
|
|
this.logger.setContext(RegistrationEnabledGuard.name);
|
|
}
|
|
|
|
canActivate(): boolean {
|
|
if (!this.authConfig.local.enableRegister) {
|
|
throw new FeatureDisabledError(
|
|
'User registration is disabled',
|
|
this.logger.getContext(),
|
|
'canActivate',
|
|
);
|
|
}
|
|
return true;
|
|
}
|
|
}
|