37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
#include device/verify.js
|
|
|
|
(() => {
|
|
const authoriseButtons = document.querySelectorAll('.js-authorise-action');
|
|
|
|
for(const button of authoriseButtons) {
|
|
button.disabled = false;
|
|
|
|
button.onclick = () => {
|
|
for(const other of authoriseButtons)
|
|
other.disabled = true;
|
|
|
|
const body = [];
|
|
for(const name in button.dataset)
|
|
body.push(encodeURIComponent(name) + '=' + encodeURIComponent(button.dataset[name]));
|
|
|
|
const xhr = new XMLHttpRequest;
|
|
xhr.responseType = 'json';
|
|
xhr.open('POST', '/oauth2/authorise');
|
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
xhr.onload = () => {
|
|
if(xhr.response.redirect)
|
|
location.assign(xhr.response.redirect);
|
|
else
|
|
location.assign('/oauth2/error?error=invalid_request');
|
|
};
|
|
xhr.onerror = () => {
|
|
for(const other of authoriseButtons)
|
|
other.disabled = false;
|
|
};
|
|
xhr.send(body.join('&'));
|
|
};
|
|
}
|
|
|
|
if(location.pathname === '/oauth2/device/verify')
|
|
HanyuuOAuth2DeviceVerify();
|
|
})();
|