xssbook/public/js/login.js
Tyler Murphy 3d71da4909 refactor
2023-02-12 14:11:50 -05:00

35 lines
No EOL
1.3 KiB
JavaScript

import { login, register } from './api.js'
async function onlogin() {
const email = document.getElementById('email').value
const password = document.getElementById('pass').value
const response = await login(email, password)
if (response.status !== 200) {
const error = document.getElementsByClassName('error')[0]
error.innerHTML = response.msg
} else {
location.href = '/home'
}
}
window.onlogin = onlogin
async function onregister() {
const first = document.getElementById('firstname').value
const last = document.getElementById('lastname').value
const email = document.getElementById('newemail').value
const pass = document.getElementById('newpass').value
const month = document.getElementById('month').value
const day = document.getElementById('day').value
const year = document.getElementById('year').value
const gender = document.querySelector('input[name="gender"]:checked').value
const response = await register(first, last, email, pass, gender, parseInt(day), parseInt(month), parseInt(year))
if (response.status !== 201) {
const error = document.getElementsByClassName('error')[1]
error.innerHTML = response.msg
} else {
location.href = '/home'
}
}
window.onregister = onregister