Get logging in mostly working;
Does not return user data for some reason.
This commit is contained in:
parent
90bdd804fe
commit
6a4d9be05a
|
@ -1,5 +1,7 @@
|
||||||
import { request } from "./helpers";
|
import { request } from "./helpers";
|
||||||
import { addMessage } from "../utilities";
|
import { addMessage } from "../utilities";
|
||||||
|
import { setupLogoutButton } from "./setupListeners";
|
||||||
|
import { renderAccountSettings } from "./render";
|
||||||
|
|
||||||
export function logIn() {
|
export function logIn() {
|
||||||
const email = document.getElementById('loginEmail').value.trim(),
|
const email = document.getElementById('loginEmail').value.trim(),
|
||||||
|
@ -16,12 +18,24 @@ export function logIn() {
|
||||||
|
|
||||||
loginErrorMessages.innerHTML = errorHTML;
|
loginErrorMessages.innerHTML = errorHTML;
|
||||||
|
|
||||||
if (errorHTML !== '') {
|
if (errorHTML === '') {
|
||||||
request({
|
request({
|
||||||
action: 'login',
|
action: 'login',
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
});
|
}, successData => {
|
||||||
|
console.log(successData);
|
||||||
|
}, errorData => {
|
||||||
|
errorHTML += errorData;
|
||||||
|
}).then(() => {
|
||||||
|
createAccountErrorMessages.innerHTML = errorHTML;
|
||||||
|
if (errorHTML === '') {
|
||||||
|
const loginModal = document.getElementById('loginModal');
|
||||||
|
loginModal.parentElement.removeChild(loginModal);
|
||||||
|
triggerLoginChanges();
|
||||||
|
addMessage(`Welcome! You are logged in.`);
|
||||||
|
}
|
||||||
|
}).catch(err => console.error(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +93,7 @@ export function createAccount() {
|
||||||
if (errorHTML === '') {
|
if (errorHTML === '') {
|
||||||
const loginModal = document.getElementById('loginModal');
|
const loginModal = document.getElementById('loginModal');
|
||||||
loginModal.parentElement.removeChild(loginModal);
|
loginModal.parentElement.removeChild(loginModal);
|
||||||
|
triggerLoginChanges();
|
||||||
addMessage('Account Created Successfully!');
|
addMessage('Account Created Successfully!');
|
||||||
addMessage(`Welcome${publicName !== '' ? ', ' + publicName : ''}! You are logged in.`);
|
addMessage(`Welcome${publicName !== '' ? ', ' + publicName : ''}! You are logged in.`);
|
||||||
}
|
}
|
||||||
|
@ -86,4 +101,17 @@ export function createAccount() {
|
||||||
}
|
}
|
||||||
}).catch(err => console.error(err));
|
}).catch(err => console.error(err));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function triggerLoginChanges() {
|
||||||
|
const loginButton = document.getElementById('loginCreateAccountButton')
|
||||||
|
const logoutButton = document.createElement('a');
|
||||||
|
logoutButton.classList.add('button');
|
||||||
|
logoutButton.id = 'logoutButton';
|
||||||
|
logoutButton.innerHTML = 'Log Out';
|
||||||
|
loginButton.parentElement.appendChild(logoutButton);
|
||||||
|
loginButton.parentElement.removeChild(loginButton);
|
||||||
|
setupLogoutButton(logoutButton);
|
||||||
|
|
||||||
|
renderAccountSettings();
|
||||||
}
|
}
|
|
@ -50,4 +50,27 @@ export function renderLoginForm() {
|
||||||
document.body.appendChild(loginModal);
|
document.body.appendChild(loginModal);
|
||||||
|
|
||||||
setupLoginModal(loginModal);
|
setupLoginModal(loginModal);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function renderAccountSettings() {
|
||||||
|
const accountSettingsColumn = document.getElementById('accountSettings');
|
||||||
|
const accountSettingsHTML = `<h3>Account Settings</h3>
|
||||||
|
<label>Email Address<br><input id="accountSettingsEmail" required maxlength="100"></label>
|
||||||
|
<label>Public Name<br><input id="accountSettingsPublicName" placeholder="Someone" maxlength="50"></label>
|
||||||
|
<label>Allow Emails <input type="checkbox" id="accountSettingsAllowEmails"></label>
|
||||||
|
<label>Change Dictionary<br><select id="accountSettingsChangeDictionary"></select></label>
|
||||||
|
<h4>Request Your Data</h4>
|
||||||
|
<p>
|
||||||
|
Per your <a href="https://www.eugdpr.org/" target="_blank">GDPR</a> rights in Articles 13–15 and 20, we allow you to request any and all data we have stored about you. The only data we have about you personally is your email address and your Public Name, if you decided to set one. All other data (your Dictionary data) is visible and accessible via the Export button under your Dictionary's Settings. Send an email to help@lexicon.ga to request your information.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h4>Delete Your Account</h4>
|
||||||
|
<p>
|
||||||
|
Per your <a href="https://www.eugdpr.org/" target="_blank">GDPR</a> rights in Articles 17, if you wish for your account to be deleted, please contact us at help@lexicon.ga, and we will delete your account and all associated dictionaries and words as quickly as possible. Note that you can delete dictionaries yourself via your Dictionary's Settings.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Anything that is deleted from our system is permanently and irretrievably removed from our system and cannot be restored, though search engines or internet archives may retain a cached version of your content (there is nothing we can do about this, and you will need to seek out removal of that information by directly contacting the services that are caching your data).
|
||||||
|
</p>
|
||||||
|
`;
|
||||||
|
accountSettingsColumn.innerHTML = accountSettingsHTML;
|
||||||
}
|
}
|
|
@ -10,4 +10,13 @@ export function setupLoginModal(modal) {
|
||||||
|
|
||||||
document.getElementById('loginSubmit').addEventListener('click', logIn);
|
document.getElementById('loginSubmit').addEventListener('click', logIn);
|
||||||
document.getElementById('createAccountSubmit').addEventListener('click', createAccount);
|
document.getElementById('createAccountSubmit').addEventListener('click', createAccount);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setupLogoutButton(logoutButton) {
|
||||||
|
logoutButton.addEventListener('click', () => {
|
||||||
|
const expire = new Date("November 1, 2015"),
|
||||||
|
path = window.location.pathname;
|
||||||
|
document.cookie = 'token=;expires=' + expire.toGMTString() + ';domain=' + document.domain + ';path=' + path; // + in front of `new Date` converts to a number
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue