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