Allow changing password from account settings
This commit is contained in:
parent
c8a01d854a
commit
d665f861a2
|
@ -146,6 +146,7 @@ export function updateAccountData(userData) {
|
|||
action: 'set-user-data',
|
||||
userData,
|
||||
}, successData => {
|
||||
document.getElementById('accountSettingsNewPassword').value = '';
|
||||
addMessage('Successfully Updated Account Data');
|
||||
}, error => {
|
||||
addMessage(error, undefined, 'error');
|
||||
|
|
|
@ -58,7 +58,9 @@ export function renderAccountSettings() {
|
|||
const accountSettingsHTML = `<h3>Account Settings</h3>
|
||||
<label>Email Address<br><input id="accountSettingsEmail" required maxlength="100" value="${window.account.email}"></label>
|
||||
<label>Public Name<br><input id="accountSettingsPublicName" placeholder="Someone" maxlength="50" value="${window.account.publicName}"></label>
|
||||
<label>Allow Emails <input type="checkbox" id="accountSettingsAllowEmails"${window.account.allowEmails ? ' checked' : ''}></label>`;
|
||||
<label>Allow Emails <input type="checkbox" id="accountSettingsAllowEmails"${window.account.allowEmails ? ' checked' : ''}></label>
|
||||
<label>New Password <small>Only fill if changing!</small><br><input type="password" id="accountSettingsNewPassword" placeholder="Leave Blank to Prevent Change"></label>
|
||||
`;
|
||||
accountSettingsColumn.innerHTML = accountSettingsHTML;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,9 @@ export function saveSettingsModal() {
|
|||
window.account.publicName = removeTags(publicName.value).trim();
|
||||
window.account.allowEmails = document.getElementById('accountSettingsAllowEmails').checked;
|
||||
|
||||
account.editAccount(window.account);
|
||||
const newPassword = document.getElementById('accountSettingsNewPassword').value;
|
||||
|
||||
account.editAccount(Object.assign({ newPassword }, window.account));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -87,13 +87,18 @@ VALUES (?, ?, ?, ?, ?)';
|
|||
$token_data = $this->token->decode($token);
|
||||
if ($token_data !== false) {
|
||||
$user_id = $token_data->id;
|
||||
$query = 'UPDATE users SET email=?, public_name=?, allow_email=? WHERE id=?';
|
||||
$query = 'UPDATE users SET email=?, public_name=?, allow_email=?';
|
||||
$properties = array(
|
||||
$user_data['email'],
|
||||
$user_data['publicName'],
|
||||
$user_data['allowEmails'],
|
||||
$user_id,
|
||||
);
|
||||
if (isset($user_data['newPassword']) && $user_data['newPassword'] !== '') {
|
||||
$query .= ', password=?';
|
||||
$properties[] = password_hash($user_data['newPassword'], PASSWORD_DEFAULT);
|
||||
}
|
||||
$query .= ' WHERE id=?';
|
||||
$properties[] = $user_id;
|
||||
$update_success = $this->db->execute($query, $properties);
|
||||
if ($update_success) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue