mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
@@ -1,9 +1,18 @@
|
||||
import { defineStartupConfig, ModuleConfig } from '../../fundamentals/config';
|
||||
import {
|
||||
defineRuntimeConfig,
|
||||
defineStartupConfig,
|
||||
ModuleConfig,
|
||||
} from '../../fundamentals/config';
|
||||
import { CaptchaConfig } from './types';
|
||||
|
||||
declare module '../config' {
|
||||
interface PluginsConfig {
|
||||
captcha: ModuleConfig<CaptchaConfig>;
|
||||
captcha: ModuleConfig<
|
||||
CaptchaConfig,
|
||||
{
|
||||
enable: boolean;
|
||||
}
|
||||
>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,3 +30,10 @@ defineStartupConfig('plugins.captcha', {
|
||||
bits: 20,
|
||||
},
|
||||
});
|
||||
|
||||
defineRuntimeConfig('plugins.captcha', {
|
||||
enable: {
|
||||
desc: 'Check captcha challenge when user authenticating the app.',
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import {
|
||||
Config,
|
||||
getRequestResponseFromContext,
|
||||
GuardProvider,
|
||||
} from '../../fundamentals';
|
||||
@@ -18,11 +19,18 @@ export class CaptchaGuardProvider
|
||||
{
|
||||
name = 'captcha' as const;
|
||||
|
||||
constructor(private readonly captcha: CaptchaService) {
|
||||
constructor(
|
||||
private readonly captcha: CaptchaService,
|
||||
private readonly config: Config
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async canActivate(context: ExecutionContext) {
|
||||
if (!(await this.config.runtime.fetch('plugins.captcha/enable'))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const { req } = getRequestResponseFromContext(context);
|
||||
|
||||
// require headers, old client send through query string
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import './config';
|
||||
|
||||
import { AuthModule } from '../../core/auth';
|
||||
import { ServerFeature } from '../../core/config';
|
||||
import { Plugin } from '../registry';
|
||||
|
||||
Reference in New Issue
Block a user