37 lines
966 B
JavaScript
37 lines
966 B
JavaScript
const url = 'https://exozy.me/api/'
|
|
const form = document.querySelector('form')
|
|
|
|
form.addEventListener('submit', (e) => {
|
|
e.preventDefault()
|
|
|
|
const data = new Object()
|
|
data['type'] = 'new'
|
|
|
|
for (const s of ['code', 'firstname', 'lastname', 'email', 'username', 'password']) {
|
|
data[s] = document.getElementsByName(s)[0].value
|
|
if (data[s] == '') {
|
|
alert('Please fill out the form completely')
|
|
return
|
|
}
|
|
}
|
|
|
|
if (/^[a-z0-9]+$/.test(data['username']) === false || (data['username'][0] >= '0' && data['username'][0] <= '9')) {
|
|
alert('Username can only contain lowercase letters and numbers and can\'t start with a number')
|
|
return
|
|
}
|
|
|
|
if (data['password'] != document.getElementsByName('confirmpassword')[0].value) {
|
|
alert('Passwords don\'t match')
|
|
return
|
|
}
|
|
|
|
console.log(data)
|
|
|
|
fetch(url, {
|
|
method: 'POST',
|
|
body: JSON.stringify(data),
|
|
}).then((response) => {
|
|
alert(response.statusText)
|
|
})
|
|
})
|