Allow updating account info

This commit is contained in:
Robbie Antenesse 2019-05-23 18:09:01 -06:00
parent c573ad10cd
commit 941ba76ac8
5 changed files with 47 additions and 9 deletions

View File

@ -1,7 +1,7 @@
import '../../scss/Account/main.scss';
import { renderLoginForm } from "./render";
import { validateToken } from './login';
import { validateToken, updateAccountData } from './login';
import {
uploadWords,
uploadDetails,
@ -20,6 +20,10 @@ export function loginWithToken() {
validateToken();
}
export function editAccount(accountData) {
updateAccountData(accountData);
}
export function syncImportedDictionary() {
uploadWholeDictionary(true);
}

View File

@ -139,4 +139,15 @@ export function triggerLoginChanges() {
renderAccountSettings();
renderAccountActions();
}
}
export function updateAccountData(userData) {
request({
action: 'set-user-data',
userData,
}, successData => {
addMessage('Successfully Updated Account Data');
}, error => {
addMessage(error, undefined, 'error');
});
}

View File

@ -1,8 +1,8 @@
import { SETTINGS_KEY, DEFAULT_SETTINGS } from "../constants";
import { cloneObject } from "../helpers";
import { cloneObject, removeTags } from "../helpers";
import { usePhondueDigraphs } from "./KeyboardFire/phondue/ipaField";
import { renderWords } from "./render";
import { addMessage } from "./utilities";
import { addMessage, hasToken } from "./utilities";
import { enableHotKeys, disableHotKeys } from "./hotkeys";
export function loadSettings() {
@ -29,6 +29,23 @@ export function saveSettingsModal() {
window.settings.useIPAPronunciationField = document.getElementById('settingsUseIPA').checked;
window.settings.useHotkeys = document.getElementById('settingsUseHotkeys').checked;
if (hasToken()) {
import('./account/index.js').then(account => {
const emailField = document.getElementById('accountSettingsEmail');
let email = removeTags(emailField.value).trim();
const publicName = document.getElementById('accountSettingsPublicName');
if (!/.+@.+\..+/.test(email)) {
email = window.account.email;
emailField.value = email;
}
window.account.email = email;
window.account.publicName = removeTags(publicName.value).trim();
window.account.allowEmails = document.getElementById('accountSettingsAllowEmails').checked;
account.editAccount(window.account);
});
}
saveSettings();
toggleHotkeysEnabled();
toggleIPAPronunciationFields();

View File

@ -96,11 +96,11 @@ VALUES (?, ?, ?, ?, ?)';
);
$update_success = $this->db->execute($query, $properties);
if ($update_success) {
return array(
'token' => $token,
'userData' => $user_data,
);
return true;
}
return array(
'error' => $this->db->last_error_info,
);
}
return false;

View File

@ -136,12 +136,18 @@ switch ($action) {
if ($token !== false && isset($request['userData'])) {
$user = new User();
$updated_user = $user->setUserData($token, $request['userData']);
if ($updated_user !== false) {
if ($updated_user === true) {
return Response::json(array(
'data' => $updated_user,
'error' => false,
), 200);
}
if (isset($updated_user['error'])) {
return Response::json(array(
'data' => $updated_user['error'],
'error' => false,
), 500);
}
return Response::json(array(
'data' => 'Could not set user data: missing data',
'error' => true,