upd: add FriendlyCaptcha as a captcha solution
FriendlyCaptcha is a german captcha solution which is GDPR compliant and has a non-commerical free license
This commit is contained in:
parent
8824422cb5
commit
d786e96c2b
18 changed files with 175 additions and 7 deletions
|
|
@ -10,6 +10,7 @@ import { bindThis } from '@/decorators.js';
|
|||
type CaptchaResponse = {
|
||||
success: boolean;
|
||||
'error-codes'?: string[];
|
||||
'errors'?: string[];
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
|
|
@ -73,6 +74,35 @@ export class CaptchaService {
|
|||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async verifyFriendlyCaptcha(secret: string, response: string | null | undefined): Promise<void> {
|
||||
if (response == null) {
|
||||
throw new Error('recaptcha-failed: no response provided');
|
||||
}
|
||||
|
||||
const result = await this.httpRequestService.send('https://api.friendlycaptcha.com/api/v1/siteverify', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
secret: secret,
|
||||
solution: response,
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (result.status !== 200) {
|
||||
throw new Error('frc-failed: frc didn\'t return 200 OK');
|
||||
}
|
||||
|
||||
const resp = await result.json() as CaptchaResponse;
|
||||
|
||||
if (resp.success !== true) {
|
||||
const errorCodes = resp['errors'] ? resp['errors'].join(', ') : '';
|
||||
throw new Error(`frc-failed: ${errorCodes}`);
|
||||
}
|
||||
}
|
||||
|
||||
// https://codeberg.org/Gusted/mCaptcha/src/branch/main/mcaptcha.go
|
||||
@bindThis
|
||||
public async verifyMcaptcha(secret: string, siteKey: string, instanceHost: string, response: string | null | undefined): Promise<void> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue