Allow updating account info
This commit is contained in:
parent
c573ad10cd
commit
941ba76ac8
|
@ -1,7 +1,7 @@
|
||||||
import '../../scss/Account/main.scss';
|
import '../../scss/Account/main.scss';
|
||||||
|
|
||||||
import { renderLoginForm } from "./render";
|
import { renderLoginForm } from "./render";
|
||||||
import { validateToken } from './login';
|
import { validateToken, updateAccountData } from './login';
|
||||||
import {
|
import {
|
||||||
uploadWords,
|
uploadWords,
|
||||||
uploadDetails,
|
uploadDetails,
|
||||||
|
@ -20,6 +20,10 @@ export function loginWithToken() {
|
||||||
validateToken();
|
validateToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function editAccount(accountData) {
|
||||||
|
updateAccountData(accountData);
|
||||||
|
}
|
||||||
|
|
||||||
export function syncImportedDictionary() {
|
export function syncImportedDictionary() {
|
||||||
uploadWholeDictionary(true);
|
uploadWholeDictionary(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,3 +140,14 @@ export function triggerLoginChanges() {
|
||||||
renderAccountSettings();
|
renderAccountSettings();
|
||||||
renderAccountActions();
|
renderAccountActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateAccountData(userData) {
|
||||||
|
request({
|
||||||
|
action: 'set-user-data',
|
||||||
|
userData,
|
||||||
|
}, successData => {
|
||||||
|
addMessage('Successfully Updated Account Data');
|
||||||
|
}, error => {
|
||||||
|
addMessage(error, undefined, 'error');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { SETTINGS_KEY, DEFAULT_SETTINGS } from "../constants";
|
import { SETTINGS_KEY, DEFAULT_SETTINGS } from "../constants";
|
||||||
import { cloneObject } from "../helpers";
|
import { cloneObject, removeTags } from "../helpers";
|
||||||
import { usePhondueDigraphs } from "./KeyboardFire/phondue/ipaField";
|
import { usePhondueDigraphs } from "./KeyboardFire/phondue/ipaField";
|
||||||
import { renderWords } from "./render";
|
import { renderWords } from "./render";
|
||||||
import { addMessage } from "./utilities";
|
import { addMessage, hasToken } from "./utilities";
|
||||||
import { enableHotKeys, disableHotKeys } from "./hotkeys";
|
import { enableHotKeys, disableHotKeys } from "./hotkeys";
|
||||||
|
|
||||||
export function loadSettings() {
|
export function loadSettings() {
|
||||||
|
@ -29,6 +29,23 @@ export function saveSettingsModal() {
|
||||||
window.settings.useIPAPronunciationField = document.getElementById('settingsUseIPA').checked;
|
window.settings.useIPAPronunciationField = document.getElementById('settingsUseIPA').checked;
|
||||||
window.settings.useHotkeys = document.getElementById('settingsUseHotkeys').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();
|
saveSettings();
|
||||||
toggleHotkeysEnabled();
|
toggleHotkeysEnabled();
|
||||||
toggleIPAPronunciationFields();
|
toggleIPAPronunciationFields();
|
||||||
|
|
|
@ -96,11 +96,11 @@ VALUES (?, ?, ?, ?, ?)';
|
||||||
);
|
);
|
||||||
$update_success = $this->db->execute($query, $properties);
|
$update_success = $this->db->execute($query, $properties);
|
||||||
if ($update_success) {
|
if ($update_success) {
|
||||||
return array(
|
return true;
|
||||||
'token' => $token,
|
|
||||||
'userData' => $user_data,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
return array(
|
||||||
|
'error' => $this->db->last_error_info,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -136,12 +136,18 @@ switch ($action) {
|
||||||
if ($token !== false && isset($request['userData'])) {
|
if ($token !== false && isset($request['userData'])) {
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$updated_user = $user->setUserData($token, $request['userData']);
|
$updated_user = $user->setUserData($token, $request['userData']);
|
||||||
if ($updated_user !== false) {
|
if ($updated_user === true) {
|
||||||
return Response::json(array(
|
return Response::json(array(
|
||||||
'data' => $updated_user,
|
'data' => $updated_user,
|
||||||
'error' => false,
|
'error' => false,
|
||||||
), 200);
|
), 200);
|
||||||
}
|
}
|
||||||
|
if (isset($updated_user['error'])) {
|
||||||
|
return Response::json(array(
|
||||||
|
'data' => $updated_user['error'],
|
||||||
|
'error' => false,
|
||||||
|
), 500);
|
||||||
|
}
|
||||||
return Response::json(array(
|
return Response::json(array(
|
||||||
'data' => 'Could not set user data: missing data',
|
'data' => 'Could not set user data: missing data',
|
||||||
'error' => true,
|
'error' => true,
|
||||||
|
|
Loading…
Reference in New Issue