Commit 2c3bc432 authored by nanahira's avatar nanahira

add vaptcha

parent c93db18d
......@@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="index.css"/>
<link rel="icon" href="https://moecube.com/favicon.ico">
<script src="https://v-cn.vaptcha.com/v3.js"></script>
</head>
<body>
......
......@@ -18,6 +18,7 @@ export async function register(params) {
return request('/signup', {
method: 'POST',
body: JSON.stringify(params),
vaptcha: true,
});
}
......@@ -25,6 +26,7 @@ export async function reset(params) {
return request('/reset', {
method: 'PATCH',
body: JSON.stringify(params),
vaptcha: true,
});
}
......
......@@ -19,5 +19,6 @@ export async function updateAccount(params) {
Authorization: `Bearer ${params.token}`,
'content-type': 'application/json',
},
vaptcha: true,
});
}
......@@ -22,6 +22,16 @@ async function checkStatus(response) {
throw error;
}
let vaptchaObj = null;
vaptcha({
vid: '668bf0efd3784602950e94a8',
type: 'invisible',
scene: 0,
area: 'auto',
}).then((v) => {
vaptchaObj = v;
});
/**
* Requests a URL, returning a promise.
*
......@@ -30,6 +40,27 @@ async function checkStatus(response) {
* @return {object} An object containing either "data" or "err"
*/
export default function request(relativeUrl, options) {
if (options.vaptcha) {
return new Promise((resolve, reject) => {
vaptchaObj.listen('pass', () => {
options.vaptcha = undefined;
const token = vaptchaObj.getServerToken();
console.log('vaptcha pass', token.server, token.token);
options.headers = {
...options.headers || { 'content-type': 'application/json' },
'x-vaptcha-server': token.server,
'x-vaptcha-token': token.token,
};
request(relativeUrl, options).then(resolve).catch(reject);
vaptchaObj.reset();
});
vaptchaObj.listen('close', () => {
console.log('vaptcha close');
reject(new Error('vaptcha close'));
})
vaptchaObj.validate();
});
}
const url = `${config.apiRoot}${relativeUrl}`;
if (options && !options.headers) {
Object.assign(options, {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment