47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
import request from '../util/request.js';
|
|
import UserSession from '../../models/UserSession.js';
|
|
import {querySelector as qs} from '../util/document.js';
|
|
|
|
/**
|
|
* @typedef {import('../../models/UserSession.js')} UserSession
|
|
*/
|
|
|
|
|
|
/**
|
|
* Verify the image
|
|
* @param {UserSession} session
|
|
* @param {HTMLElement} captchaGrid
|
|
*/
|
|
export default async function verifyImage(session, captchaGrid) {
|
|
captchaGrid.classList.add('blurred');
|
|
const tds = captchaGrid.querySelectorAll('td');
|
|
const selectedTds = [];
|
|
|
|
const mat = new Array(16);
|
|
for (let i = 0; i < tds.length; i++) {
|
|
if (tds[i].classList.contains('selected')) {
|
|
mat[i] = 1;
|
|
selectedTds.push(tds[i]);
|
|
} else {
|
|
mat[i] = 0;
|
|
}
|
|
}
|
|
|
|
const body = {
|
|
's': session.getSessionId(),
|
|
'mat': mat,
|
|
};
|
|
|
|
const resp = await request('/api/verify', {_method: 'POST', _body: body});
|
|
|
|
session.deserialize(resp);
|
|
qs('#ucaptcha-caption')
|
|
.innerHTML = `Select all squares with <b>${session.getImageTag()}s</b>`;
|
|
|
|
captchaGrid.classList.remove('blurred');
|
|
|
|
selectedTds.map((td)=>{
|
|
td.classList.remove('selected');
|
|
});
|
|
}
|