|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { client, navigateTo } from '../index.js';
|
|
|
|
|
import { clear, fill_errors } from '../utils/formUtils.js';
|
|
|
|
|
import {client, lang} from '../index.js';
|
|
|
|
|
import {clearElements, fill_errors} from '../utils/formUtils.js'
|
|
|
|
|
import AbstractAuthenticatedView from './abstracts/AbstractAuthenticatedView.js';
|
|
|
|
|
|
|
|
|
|
export default class extends AbstractAuthenticatedView
|
|
|
|
@ -14,10 +14,25 @@ export default class extends AbstractAuthenticatedView
|
|
|
|
|
{
|
|
|
|
|
this.avatarInit();
|
|
|
|
|
this.usernameInit();
|
|
|
|
|
|
|
|
|
|
// document.getElementById('delete-account-button').onclick = () => this.delete_account();
|
|
|
|
|
this.passwordInit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
passwordInit() {
|
|
|
|
|
document.getElementById('currentPasswordInput').onkeydown = e => {
|
|
|
|
|
if (e.key === 'Enter')
|
|
|
|
|
this.savePassword();
|
|
|
|
|
};
|
|
|
|
|
document.getElementById('newPasswordInput').onkeydown = e => {
|
|
|
|
|
if (e.key === 'Enter')
|
|
|
|
|
this.savePassword();
|
|
|
|
|
};
|
|
|
|
|
document.getElementById('newPassword2Input').onkeydown = e => {
|
|
|
|
|
if (e.key === 'Enter')
|
|
|
|
|
this.savePassword();
|
|
|
|
|
};
|
|
|
|
|
document.getElementById('passwordSave').onclick = this.savePassword;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usernameInit() {
|
|
|
|
|
const usernameInput = document.getElementById('usernameInput');
|
|
|
|
|
const usernameSave = document.getElementById('usernameSave');
|
|
|
|
@ -54,50 +69,47 @@ export default class extends AbstractAuthenticatedView
|
|
|
|
|
async displayAvatar() {
|
|
|
|
|
let avatar = document.getElementById('avatar');
|
|
|
|
|
avatar.src = client.me.avatar_url + '?t=' + new Date().getTime();
|
|
|
|
|
console.log(avatar.src);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async delete_account()
|
|
|
|
|
{
|
|
|
|
|
let current_password = document.getElementById('current_password-input').value;
|
|
|
|
|
|
|
|
|
|
let response_data = await client.account.delete(current_password);
|
|
|
|
|
async savePassword() {
|
|
|
|
|
const currentPasswordInput = document.getElementById('currentPasswordInput');
|
|
|
|
|
const currentPassword = currentPasswordInput.value;
|
|
|
|
|
const currentPasswordDetail = document.getElementById('currentPasswordDetail');
|
|
|
|
|
const newPasswordInput = document.getElementById('newPasswordInput');
|
|
|
|
|
const newPassword = newPasswordInput.value;
|
|
|
|
|
const newPasswordDetail = document.getElementById('newPasswordDetail');
|
|
|
|
|
const newPassword2Input = document.getElementById('newPassword2Input');
|
|
|
|
|
const newPassword2 = newPassword2Input.value;
|
|
|
|
|
const newPassword2Detail = document.getElementById('newPassword2Detail');
|
|
|
|
|
const passwordDetail = document.getElementById('passwordDetail');
|
|
|
|
|
|
|
|
|
|
if (response_data === null || response_data === 'user deleted')
|
|
|
|
|
{
|
|
|
|
|
navigateTo('/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
clear('innerHTML', ['current_password-input']);
|
|
|
|
|
fill_errors({'current_password-input': response_data.password}, 'innerHTML');
|
|
|
|
|
}
|
|
|
|
|
clearElements('innerHTML', [currentPasswordDetail,
|
|
|
|
|
newPasswordDetail,
|
|
|
|
|
newPassword2Detail,
|
|
|
|
|
passwordDetail
|
|
|
|
|
]);
|
|
|
|
|
if (!currentPassword.length)
|
|
|
|
|
currentPasswordDetail.innerHTML = lang.get('errorEmptyField');
|
|
|
|
|
if (!newPassword.length)
|
|
|
|
|
newPasswordDetail.innerHTML = lang.get('errorEmptyField');
|
|
|
|
|
if (!newPassword2.length)
|
|
|
|
|
newPassword2Detail.innerHTML = lang.get('errorEmptyField');
|
|
|
|
|
if (!currentPassword.length || !newPassword.length || !newPassword2.length)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
async save_account()
|
|
|
|
|
{
|
|
|
|
|
let username = document.getElementById('username-input').value;
|
|
|
|
|
let new_password = document.getElementById('new_password-input').value;
|
|
|
|
|
let current_password = document.getElementById('current_password-input').value;
|
|
|
|
|
|
|
|
|
|
let data = {};
|
|
|
|
|
|
|
|
|
|
data.username = username;
|
|
|
|
|
if (new_password.length != 0)
|
|
|
|
|
data.new_password = new_password;
|
|
|
|
|
|
|
|
|
|
let response_data = await client.account.update(data, current_password);
|
|
|
|
|
|
|
|
|
|
if (response_data === null)
|
|
|
|
|
{
|
|
|
|
|
navigateTo('/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (response_data === 'data has been alterate')
|
|
|
|
|
response_data = {'save-account': 'saved'};
|
|
|
|
|
|
|
|
|
|
clear('innerHTML', ['username', 'new_password', 'current_password', 'save-account', 'delete-account']);
|
|
|
|
|
fill_errors(response_data, 'innerHTML');
|
|
|
|
|
}
|
|
|
|
|
const error = await client.account.updatePassword(currentPassword, newPassword, newPassword2);
|
|
|
|
|
if (!error) {
|
|
|
|
|
passwordDetail.classList.remove('text-danger');
|
|
|
|
|
passwordDetail.classList.add('text-success');
|
|
|
|
|
passwordDetail.innerHTML = lang.get('passwordSaved');
|
|
|
|
|
setTimeout(_ => passwordDetail.innerHTML = '', 3000);
|
|
|
|
|
clearElements('value', [currentPasswordInput, newPasswordInput, newPassword2Input]);
|
|
|
|
|
} else {
|
|
|
|
|
passwordDetail.classList.add('text-danger');
|
|
|
|
|
passwordDetail.classList.remove('text-success');
|
|
|
|
|
fill_errors(error, 'innerHTML');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async saveUsername()
|
|
|
|
|
{
|
|
|
|
@ -110,13 +122,13 @@ export default class extends AbstractAuthenticatedView
|
|
|
|
|
|
|
|
|
|
const error = await client.account.updateUsername(username);
|
|
|
|
|
if (!error) {
|
|
|
|
|
usernameDetail.classList.remove('text-danger');
|
|
|
|
|
usernameDetail.classList.remove('text-danger', 'd-none');
|
|
|
|
|
usernameDetail.classList.add('text-success');
|
|
|
|
|
usernameDetail.innerHTML = 'Username Saved.';
|
|
|
|
|
setTimeout(_ => usernameDetail.innerHTML = '', 2000);
|
|
|
|
|
setTimeout(_ => usernameDetail.add('d-none'), 2000);
|
|
|
|
|
document.getElementById('usernameSave').classList.add('disabled');
|
|
|
|
|
} else {
|
|
|
|
|
usernameDetail.classList.remove('text-success');
|
|
|
|
|
usernameDetail.classList.remove('text-success', 'd-none');
|
|
|
|
|
usernameDetail.classList.add('text-danger');
|
|
|
|
|
usernameDetail.innerHTML = error;
|
|
|
|
|
document.getElementById('usernameSave').classList.add('disabled');
|
|
|
|
@ -183,44 +195,58 @@ export default class extends AbstractAuthenticatedView
|
|
|
|
|
const avatarUnchanged = client.me.avatar_url === '/static/avatars/default.avif';
|
|
|
|
|
|
|
|
|
|
return /* HTML */ `
|
|
|
|
|
<div class='container col-sm-10 col-8 d-flex rounded border border-2 bg-light-subtle py-3'>
|
|
|
|
|
<div class='row col-4 bg-body-tertiary border rounded p-2 m-2 d-flex justify-content-center align-items-center'>
|
|
|
|
|
<h2 class='border-bottom'>Avatar</h2>
|
|
|
|
|
<img id='avatar' class='rounded p-0' src=${client.me.avatar_url} style='cursor: pointer;'>
|
|
|
|
|
<input id='avatarInput' class='d-none' type='file' accept='image/*'>
|
|
|
|
|
<div class='d-flex gap-2 mt-1 px-0'>
|
|
|
|
|
<span class='my-auto ms-1 me-auto' id='avatarDetail'></span>
|
|
|
|
|
<button class='btn btn-primary d-none' id='avatarUpload'>Save</button>
|
|
|
|
|
<button class='btn btn-danger${avatarUnchanged ? ' d-none' : ''}' id='avatarDelete'>Delete</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class='flex-grow-1'>
|
|
|
|
|
<h1 class='border-bottom ps-1 mb-3'>Account</h1>
|
|
|
|
|
<div>
|
|
|
|
|
<div class='input-group'>
|
|
|
|
|
<div class='form-floating'>
|
|
|
|
|
<input type='text' class='form-control' id='usernameInput' placeholder='username' value=${client.me.username}>
|
|
|
|
|
<label for='usernameInput'>Username</label>
|
|
|
|
|
</div>
|
|
|
|
|
<button class='input-group-text btn btn-success disabled' id='usernameSave'>Save</button>
|
|
|
|
|
</div>
|
|
|
|
|
<span class='form-text' id='usernameDetail'></span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class='container-fluid col-lg-8 d-flex rounded border border-2 bg-light-subtle py-3'>
|
|
|
|
|
<div class='row col-4 bg-body-tertiary border rounded p-2 m-2 d-flex justify-content-center align-items-center'>
|
|
|
|
|
<h2 class='border-bottom'>Avatar</h2>
|
|
|
|
|
<img id='avatar' class='rounded p-0' src=${client.me.avatar_url} style='cursor: pointer;'>
|
|
|
|
|
<input id='avatarInput' class='d-none' type='file' accept='image/*'>
|
|
|
|
|
<div class='d-flex gap-2 mt-1 px-0'>
|
|
|
|
|
<span class='my-auto ms-1 me-auto' id='avatarDetail'></span>
|
|
|
|
|
<button class='btn btn-primary d-none' id='avatarUpload'>Save</button>
|
|
|
|
|
<button class='btn btn-danger${avatarUnchanged ? ' d-none' : ''}' id='avatarDelete'>Delete</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class='flex-grow-1'>
|
|
|
|
|
<h1 class='border-bottom ps-1 mb-3'>Account settings</h1>
|
|
|
|
|
<div class='d-flex flex-column gap-2'>
|
|
|
|
|
<div>
|
|
|
|
|
<div class='input-group'>
|
|
|
|
|
<div class='form-floating'>
|
|
|
|
|
<input type='text' class='form-control' id='usernameInput' placeholder='username' value=${client.me.username}>
|
|
|
|
|
<label for='usernameInput'>Username</label>
|
|
|
|
|
</div>
|
|
|
|
|
<button class='input-group-text btn btn-success disabled' id='usernameSave'>Save</button>
|
|
|
|
|
</div>
|
|
|
|
|
<span class='form-text' id='usernameDetail'></span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class='flex-grow-1 p-1 border rounded bg-body-tertiary'>
|
|
|
|
|
<h5 class='ps-1 border-bottom'>Change password</h5>
|
|
|
|
|
<div class='d-flex flex-column gap-1'>
|
|
|
|
|
<div class='form-floating'>
|
|
|
|
|
<input type='password' class='form-control' id='currentPasswordInput' placeholder='Current password'>
|
|
|
|
|
<label for='currentPasswordInput'>Current password</label>
|
|
|
|
|
</div>
|
|
|
|
|
<span class='text-danger ps-1' id='currentPasswordDetail'></span>
|
|
|
|
|
<div class='form-floating'>
|
|
|
|
|
<input type='password' class='form-control' id='newPasswordInput' placeholder='New password'>
|
|
|
|
|
<label for='newPassword2Input'>New password</label>
|
|
|
|
|
</div>
|
|
|
|
|
<span class='text-danger ps-1' id='newPasswordDetail'></span>
|
|
|
|
|
<div class='form-floating'>
|
|
|
|
|
<input type='password' class='form-control' id='newPassword2Input' placeholder='Repeat new password'>
|
|
|
|
|
<label for='newPassword2Input'>Repeat new password</label>
|
|
|
|
|
</div>
|
|
|
|
|
<span class='text-danger ps-1' id='newPassword2Detail'></span>
|
|
|
|
|
<div class='d-flex flex-row'>
|
|
|
|
|
<span class='ps-1 my-auto text-danger' id='passwordDetail'></span>
|
|
|
|
|
<button class='btn btn-success ms-auto' id='passwordSave'>Save</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<button class='btn btn-outline-danger'>Delete account</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
// <input class='form-control' type='text' placeholder='Username' id='username-input' value=${client.me.username}>
|
|
|
|
|
// <h1>Settings</h1>
|
|
|
|
|
// <input class='form-control d-inline-block' type='text' placeholder='Username' id='username-input' value=${client.me.username}>
|
|
|
|
|
// <span id='username'></span>
|
|
|
|
|
// <input type=password placeholder='New Password' id='new_password-input'>
|
|
|
|
|
// <span id='new_password'></span>
|
|
|
|
|
// <input type=password placeholder='Current Password' id='current_password-input'>
|
|
|
|
|
// <span id='current_password'></span>
|
|
|
|
|
// <input type='button' value='Save Credentials' id='save-account-button'>
|
|
|
|
|
// <span id='save-account'></span>
|
|
|
|
|
//
|
|
|
|
|
// <input type='button' value='Delete Account' id='delete-account-button'>
|
|
|
|
|
// <span id='delete-account'></span>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|