1.1.0 • Published 8 months ago
@deamtest/captcha-react v1.1.0
@deamtest/captcha-react
A Deamtest component for React
Installation
yarn add @deamtest/captcha-react
npm install @deamtest/captcha-react --save
Usage
frontend (ReactJS)
import Captcha from '@deamtest/captcha-react';
const deamAppId = '**********';
const deamApiKey = 'deamtest-*******************************************';
export default () => {
const onVerify = token => console.log(token);
return (
<Captcha lang="en-US" appId={deamAppId} apiKey={deamApiKey} onVerify={onVerify} />
)
};
backend (NodeJs)
import express from 'express';
import axios from 'axios';
import crypto from 'crypto';
const deamApiUrl = 'https://api.deamtest.com';
const deamAppId = '**********';
const deamApiKey = 'deamtest-*******************************************';
const deamApiSecret = '******************'
const verifyCaptcha = async (captchaToken: string) => {
try {
const src = new TextEncoder().encode(deamApiSecret.slice(0,16));
const iv = Buffer.from(src.buffer, src.byteOffset, src.byteLength);
let buf = deamApiKey.slice(9).split('').map((c) => {
switch (c) {
case '-': return '+';
case '_': return '/';
default: return c;
}
}).join('');
const key = crypto.createSecretKey(Buffer.from(buf, 'base64'));
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
const data = Buffer.concat([
cipher.update(new TextEncoder().encode(captchaToken)), cipher.final()
]).toString('base64');
const response = await axios.post(deamApiUrl, {
jsonrpc: "2.0",
id: Math.round(Math.random() * 1e6),
method: 'deam-verify',
params: [deamAppId, data]
});
if (response.data.error) return response.data.error;
if (response.data.result) return response.data.result;
} catch (error) {
console.log(error);
}
}
const router = express.Router();
router.post("/",async (req: express.Request, res: express.Response) => {
const {captcha} = req.body as {captcha: string};
const captchaResult = await verifyCaptcha(captcha);
if (captchaResult===true) {
res.json({status: 'ok'});
} else {
res.json({status: 'failed'});
}
})
How can I get API Key freely?
What's new in v1.1.0?
- added default dark them and supported custom theme
- supported multi language
Code | Name |
---|---|
en-US | English |
af | Afrikaans |
ar | Arabic |
az | Azeri (Latin) |
az-AZ | Azeri (Latin) (Azerbaijan) |
be-BY | Belarusian (Belarus) |
bg-BG | Bulgarian (Bulgaria) |
bs-BA | Bosnian (Bosnia and Herzegovina) |
ca-ES | Catalan (Spain) |
cs-CZ | Czech (Czech Republic) |
cy-GB | Welsh (United Kingdom) |
da-DK | Danish (Denmark) |
de-DE | German (Germany) |
el-GR | Greek (Greece) |
es-ES | Spanish (Spain) |
et-EE | Estonian (Estonia) |
eu-ES | Basque (Spain) |
fi-FI | Finnish (Finland) |
fr-FR | French (France) |
gl-ES | Galician (Spain) |
gu-IN | Gujarati (India) |
he-IL | Hebrew (Israel) |
hi-IN | Hindi (India) |
hr-HR | Croatian (Croatia) |
hu-HU | Hungarian (Hungary) |
hy-AM | Armenian (Armenia) |
id-ID | Indonesian (Indonesia) |
is-IS | Icelandic (Iceland) |
it-IT | Italian (Italy) |
ja-JP | Japanese (Japan) |
ka-GE | Georgian (Georgia) |
kk-KZ | Kazakh (Kazakhstan) |
kn-IN | Kannada (India) |
ko-KR | Korean (Korea) |
kok-IN | Konkani (India) |
ky-KG | Kyrgyz (Kyrgyzstan) |
lt-LT | Lithuanian (Lithuania) |
lv-LV | Latvian (Latvia) |
mi-NZ | Maori (New Zealand) |
mk-MK | Macedonian |
mn-MN | Mongolian (Mongolia) |
mr-IN | Marathi (India) |
ms-MY | Malay (Malaysia) |
mt-MT | Maltese (Malta) |
nn-NO | Norwegian (Nynorsk) (Norway) |
nl-NL | Dutch (Netherlands) |
pa-IN | Punjabi (India) |
pl-PL | Polish (Poland) |
ps-AR | Pashto (Afghanistan) |
pt-PT | Portuguese (Portugal) |
qu | Quechua |
ro-RO | Romanian (Romania) |
ru-RU | Russian (Russia) |
sa-IN | Sanskrit (India) |
sk-SK | Slovak (Slovakia) |
sl-SI | Slovenian (Slovenia) |
sq-AL | Albanian (Albania) |
sr-SP | Serbian (Cyrillic) |
sv-SE | Swedish (Sweden) |
ta-IN | Tamil (India) |
te-IN | Telugu (India) |
th-TH | Thai (Thailand) |
tr-TR | Turkish (Turkey) |
tt-RU | Tatar (Russia) |
ts | Tsonga |
uk-UA | Ukrainian (Ukraine) |
ur-PK | Urdu (Islamic Republic of Pakistan) |
uz-UZ | Uzbek (Latin) (Uzbekistan) |
vi-VN | Vietnamese (Viet Nam) |
xh-ZA | Xhosa (South Africa) |
zh-CN | Chinese (S) |
zh-TW | Chinese (T) |
zu-ZA | Zulu (South Africa) |