Add import-ed account script
This commit is contained in:
parent
36cbba4156
commit
82d9ba9eee
|
@ -0,0 +1,21 @@
|
|||
export function request (data = {}, success = () => {}, error = () => {}, fail = () => {}) {
|
||||
fetch('./account/', {
|
||||
method: 'POST', // or 'PUT'
|
||||
body: JSON.stringify(data), // data can be `string` or {object}!
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
}).then(res => res.json())
|
||||
.then(response => {
|
||||
console.log('Success:', JSON.stringify(response));
|
||||
if (response.error) {
|
||||
error(response);
|
||||
}
|
||||
success(response);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Request Error:', err);
|
||||
fail(err);
|
||||
});
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import '../../scss/Account/main.scss';
|
||||
|
||||
import { renderLoginForm } from "./render";
|
||||
|
||||
export function showLoginForm() {
|
||||
renderLoginForm();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
import { request } from "./helpers";
|
||||
|
||||
export function logIn() {
|
||||
const email = document.getElementById('loginEmail').value.trim(),
|
||||
password = document.getElementById('loginPassword').value.trim();
|
||||
const loginErrorMessages = document.getElementById('loginErrorMessages');
|
||||
let errorHTML = '';
|
||||
|
||||
if (email === '') {
|
||||
errorHTML += '<p class="bold red">Please enter your email address.</p>';
|
||||
}
|
||||
if (password === '') {
|
||||
errorHTML += '<p class="bold red">Please enter your password.</p>';
|
||||
}
|
||||
|
||||
loginErrorMessages.innerHTML = errorHTML;
|
||||
|
||||
if (errorHTML !== '') {
|
||||
request({
|
||||
action: 'login',
|
||||
email,
|
||||
password,
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
import { setupLoginModal } from "./setupListeners";
|
||||
|
||||
export function renderLoginForm() {
|
||||
const loginModal = document.createElement('section');
|
||||
loginModal.classList.add('modal');
|
||||
loginModal.id = 'loginModal';
|
||||
loginModal.innerHTML = `<div class="modal-background"></div>
|
||||
<div class="modal-content"><a class="close-button">×︎</a>
|
||||
<section>
|
||||
<div class="split two">
|
||||
<div>
|
||||
<h2>Log In</h2>
|
||||
<label>Email<br>
|
||||
<input type="email" required id="loginEmail">
|
||||
</label>
|
||||
<label>Password<br>
|
||||
<input type="password" required id="loginPassword">
|
||||
</label>
|
||||
<section id="loginErrorMessages"></section>
|
||||
<a id="loginSubmit" class="button">Log In</a><br>
|
||||
<a id="forgotPasswordButton" class="small button">Forgot Password?</a>
|
||||
</div>
|
||||
<div>
|
||||
<h2>Create a New Account</h2>
|
||||
<p>Creating an account allows you to save and switch between as many dictionaries as you need and access them from any device for free! If you have a dictionary you've been working on loaded already, it will automatically be uploaded to your account when you log in for the first time.</p>
|
||||
<p>Plus if you allow us to send you emails, we'll make sure that you're the first to hear about any new features that get added or if any of our policies change for any reason. We'll never spam you or sell your information.</p>
|
||||
<p>By creating an account, you are indicating that you agree to the Terms of Service and that you understand Lexiconga's Privacy Policy.</p>
|
||||
<label>Email<br>
|
||||
<input type="email" id="createNewEmail">
|
||||
</label>
|
||||
<label>Password<br>
|
||||
<input type="password" id="createNewPassword">
|
||||
</label>
|
||||
<label>Confirm Password<br>
|
||||
<input type="password" id="createNewConfirm">
|
||||
</label>
|
||||
<label>Public Name<br>
|
||||
<input type="text" id="createNewPublicName">
|
||||
</label>
|
||||
<label>Allow Emails
|
||||
<input type="checkbox" id="createNewAllowEmails">
|
||||
</label>
|
||||
<a id="createAccountSubmit" class="button">Create Account</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>`;
|
||||
|
||||
document.body.appendChild(loginModal);
|
||||
|
||||
setupLoginModal(loginModal);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
import { logIn } from "./login";
|
||||
|
||||
export function setupLoginModal(modal) {
|
||||
const closeElements = modal.querySelectorAll('.modal-background, .close-button');
|
||||
Array.from(closeElements).forEach(close => {
|
||||
close.addEventListener('click', () => {
|
||||
modal.parentElement.removeChild(modal);
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('loginSubmit').addEventListener('click', logIn);
|
||||
}
|
|
@ -11,8 +11,7 @@ import { showSearchModal, clearSearchText } from './search';
|
|||
|
||||
export default function setupListeners() {
|
||||
setupDetailsTabs();
|
||||
setupSearchBar();
|
||||
setupSettingsModal();
|
||||
setupHeaderButtons();
|
||||
setupWordForm();
|
||||
setupMobileWordFormButton();
|
||||
setupInfoButtons();
|
||||
|
@ -21,6 +20,17 @@ export default function setupListeners() {
|
|||
}
|
||||
}
|
||||
|
||||
export function setupHeaderButtons() {
|
||||
setupSearchBar();
|
||||
setupSettingsModal();
|
||||
|
||||
document.getElementById('loginCreateAccountButton').addEventListener('click', () => {
|
||||
import('./account/index.js').then(account => {
|
||||
account.showLoginForm();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function setupDetailsTabs() {
|
||||
const tabs = document.querySelectorAll('#detailsSection nav li');
|
||||
tabs.forEach(tab => {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#loginModal {
|
||||
.modal-content {
|
||||
padding: $general-padding;
|
||||
width: 1000px;
|
||||
|
||||
section {
|
||||
overflow-y: auto;
|
||||
height: 100%;
|
||||
|
||||
p {
|
||||
font-size: 10pt;
|
||||
line-height: 12pt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
@import '../variables';
|
||||
|
||||
@import './structure';
|
Loading…
Reference in New Issue