2024-03-16 20:26:21 +08:00
|
|
|
$.pjax.defaults.scrollTo = false;
|
2024-03-07 20:35:50 +08:00
|
|
|
$(document).ready(function () {
|
|
|
|
$('#deleteConfirm').change(function () {
|
|
|
|
if (this.checked) {
|
2024-03-04 16:51:19 +08:00
|
|
|
$('#deleteButton').prop('disabled', false);
|
|
|
|
} else {
|
|
|
|
$('#deleteButton').prop('disabled', true);
|
|
|
|
}
|
|
|
|
});
|
2024-03-07 20:35:50 +08:00
|
|
|
$('#totp-enabled').change(function () {
|
|
|
|
if (this.checked) {
|
|
|
|
$('#totpSetupModal').modal('show');
|
2024-03-09 13:32:35 +08:00
|
|
|
} else {
|
2024-03-07 20:35:50 +08:00
|
|
|
$.post('index.php?r=user%2Fremove-two-factor', function () {
|
|
|
|
location.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('#totpSetupModal').on('hidden.bs.modal', function () {
|
|
|
|
$('#totp-enabled').prop('checked', false);
|
|
|
|
});
|
2024-03-09 13:32:35 +08:00
|
|
|
$('#useDarkTheme').change(function () {
|
2024-03-08 16:20:22 +08:00
|
|
|
var darkMode = this.checked ? 1 : 0;
|
2024-03-09 13:32:35 +08:00
|
|
|
$.post('index.php?r=user%2Fset-theme', {dark_mode: darkMode}, function () {
|
2024-03-08 16:20:22 +08:00
|
|
|
location.reload();
|
|
|
|
});
|
|
|
|
});
|
2024-03-07 20:35:50 +08:00
|
|
|
|
2024-03-09 13:32:35 +08:00
|
|
|
$('#followSystemTheme').change(function () {
|
2024-03-08 16:20:22 +08:00
|
|
|
$('#useDarkTheme').prop('checked', false);
|
|
|
|
var darkMode = this.checked ? 2 : 0;
|
2024-03-09 13:32:35 +08:00
|
|
|
$.post('index.php?r=user%2Fset-theme', {dark_mode: darkMode}, function () {
|
2024-03-08 16:20:22 +08:00
|
|
|
location.reload();
|
|
|
|
});
|
|
|
|
});
|
2024-03-09 13:32:35 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
document.querySelector('.avatar-container').addEventListener('click', function () {
|
|
|
|
$('#avatarModal').modal('show');
|
2024-03-09 14:38:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
document.querySelector('.editable-username').addEventListener('click', function () {
|
|
|
|
// 在这里添加你的代码来显示一个模态框或其他你想要的东西
|
|
|
|
$('#changeAccountName').modal('show');
|
2024-03-14 20:27:13 +08:00
|
|
|
});
|
|
|
|
|
2024-03-16 20:26:21 +08:00
|
|
|
document.querySelector('#webauthn_detail').addEventListener('click', function () {
|
|
|
|
$.ajax({
|
2024-03-17 17:24:26 +08:00
|
|
|
url: 'index.php?r=user%2Fcredential-list',
|
2024-03-16 20:26:21 +08:00
|
|
|
method: 'GET',
|
|
|
|
success: function(data) {
|
|
|
|
$('#pjax-container').html(data);
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
$('#credentialModal').modal('show');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2024-03-14 20:27:13 +08:00
|
|
|
// WebAuthn registration #BEGIN
|
|
|
|
const { startRegistration } = SimpleWebAuthnBrowser;
|
|
|
|
|
|
|
|
// <button>
|
|
|
|
const elemBegin = document.getElementById('webauthn_add');
|
|
|
|
// <span>/<p>/etc...
|
|
|
|
const elemSuccess = document.getElementById('webauthn_success');
|
|
|
|
// <span>/<p>/etc...
|
|
|
|
const elemError = document.getElementById('webauthn_error');
|
|
|
|
|
|
|
|
// Start registration when the user clicks a button
|
|
|
|
elemBegin.addEventListener('click', async () => {
|
|
|
|
// Reset success/error messages
|
|
|
|
elemSuccess.innerHTML = '';
|
|
|
|
elemError.innerHTML = '';
|
|
|
|
elemSuccess.parentElement.hidden = true;
|
|
|
|
elemError.parentElement.hidden = true;
|
|
|
|
|
|
|
|
// GET registration options from the endpoint that calls
|
|
|
|
const resp = await fetch('index.php?r=user%2Fcreate-credential-options');
|
|
|
|
|
|
|
|
let attResp;
|
|
|
|
try {
|
|
|
|
// Pass the options to the authenticator and wait for a response
|
|
|
|
attResp = await startRegistration(await resp.json());
|
|
|
|
} catch (error) {
|
|
|
|
// Some basic error handling
|
|
|
|
if (error.name === 'InvalidStateError') {
|
|
|
|
elemError.innerText = 'Error: Authenticator was probably already registered by user';
|
|
|
|
} else {
|
|
|
|
elemError.innerText = error;
|
|
|
|
}
|
|
|
|
elemError.parentElement.hidden = false;
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
2024-03-17 17:24:26 +08:00
|
|
|
attResp.fido_name = document.getElementById('fido_name').value;
|
2024-03-14 20:27:13 +08:00
|
|
|
// POST the response to the endpoint that calls
|
|
|
|
const verificationResp = await fetch('index.php?r=user%2Fcreate-credential', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'X-CSRF-Token': csrfToken
|
|
|
|
},
|
|
|
|
body: JSON.stringify(attResp),
|
|
|
|
});
|
|
|
|
|
|
|
|
// Wait for the results of verification
|
|
|
|
const verificationJSON = await verificationResp.json();
|
|
|
|
|
|
|
|
// Show UI appropriate for the `verified` status
|
|
|
|
if (verificationJSON && verificationJSON.verified) {
|
|
|
|
elemSuccess.innerHTML = 'Success!';
|
|
|
|
elemSuccess.parentElement.hidden = false;
|
|
|
|
} else {
|
|
|
|
elemError.innerHTML = `Oh no, something went wrong! Response: <pre>${JSON.stringify(
|
|
|
|
verificationJSON,
|
|
|
|
)}</pre>`;
|
|
|
|
elemError.parentElement.hidden = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const { startAuthentication } = SimpleWebAuthnBrowser;
|
|
|
|
|
|
|
|
// <button>
|
|
|
|
const elemBegin_v = document.getElementById('webauthn_verify');
|
|
|
|
|
|
|
|
// Start authentication when the user clicks a button
|
|
|
|
elemBegin_v.addEventListener('click', async () => {
|
|
|
|
// Reset success/error messages
|
|
|
|
elemSuccess.innerHTML = '';
|
|
|
|
elemError.innerHTML = '';
|
|
|
|
elemSuccess.parentElement.hidden = true;
|
|
|
|
elemError.parentElement.hidden = true;
|
|
|
|
|
|
|
|
// GET authentication options from the endpoint that calls
|
|
|
|
// @simplewebauthn/server -> generateAuthenticationOptions()
|
|
|
|
const resp = await fetch('index.php?r=user%2Frequest-assertion-options');
|
|
|
|
|
|
|
|
let asseResp;
|
|
|
|
try {
|
|
|
|
// Pass the options to the authenticator and wait for a response
|
|
|
|
asseResp = await startAuthentication(await resp.json());
|
|
|
|
} catch (error) {
|
|
|
|
// Some basic error handling
|
|
|
|
elemError.innerText = error;
|
|
|
|
elemError.parentElement.hidden = false;
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
|
|
|
// POST the response to the endpoint that calls
|
|
|
|
// @simplewebauthn/server -> verifyAuthenticationResponse()
|
|
|
|
const verificationResp = await fetch('index.php?r=user%2Fverify-assertion', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'X-CSRF-Token': csrfToken
|
|
|
|
},
|
|
|
|
body: JSON.stringify(asseResp),
|
|
|
|
});
|
|
|
|
|
|
|
|
// Wait for the results of verification
|
|
|
|
const verificationJSON = await verificationResp.json();
|
|
|
|
|
|
|
|
// Show UI appropriate for the `verified` status
|
|
|
|
if (verificationJSON && verificationJSON.verified) {
|
|
|
|
elemSuccess.innerHTML = 'Success!';
|
|
|
|
elemSuccess.parentElement.hidden = false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
elemError.innerHTML = `Oh no, something went wrong! Response: <pre>${JSON.stringify(
|
|
|
|
verificationJSON,
|
|
|
|
)}</pre>`;
|
|
|
|
elemError.parentElement.hidden = false;
|
|
|
|
}
|
2024-03-04 16:51:19 +08:00
|
|
|
});
|