Fix #8: Don't use JavaScript for join form
This commit is contained in:
parent
375086c30b
commit
9536b40543
|
@ -17,16 +17,15 @@
|
||||||
<p>
|
<p>
|
||||||
Welcome! Please use only lowercase letters and numbers for your username. After you have an account, <a href="https://exozy.me/about/">learn more about exozyme</a> or try our <a href="https://exozy.me/quickstart/">quickstart guide</a>.
|
Welcome! Please use only lowercase letters and numbers for your username. After you have an account, <a href="https://exozy.me/about/">learn more about exozyme</a> or try our <a href="https://exozy.me/quickstart/">quickstart guide</a>.
|
||||||
</p>
|
</p>
|
||||||
<form method="post" enctype="multipart/form-data">
|
<form method="post" action="/api/join">
|
||||||
<input type="text" placeholder="Secret code" name="code">
|
<input type="text" placeholder="Secret code" name="code" required>
|
||||||
<input type="text" placeholder="First name" name="firstname">
|
<input type="text" placeholder="First name" name="firstname" required>
|
||||||
<input type="text" placeholder="Last name" name="lastname">
|
<input type="text" placeholder="Last name" name="lastname" required>
|
||||||
<input type="text" placeholder="Email" name="email">
|
<input type="email" placeholder="Email" name="email" required>
|
||||||
<input type="text" placeholder="Username" name="username">
|
<input type="text" pattern="[a-z][a-z0-9]*" placeholder="Username" name="username" required>
|
||||||
<input type="password" placeholder="Strong password" name="password">
|
<input type="password" placeholder="Strong password" name="password" required>
|
||||||
<input type="password" placeholder="Confirm password" name="confirmpassword">
|
<input type="password" placeholder="Confirm password" name="confirmpassword" required>
|
||||||
<input type="submit" value="Join!" style="font-family:monospace;" name="submit">
|
<input type="submit" value="Join!" style="font-family:monospace;" name="submit">
|
||||||
</form>
|
</form>
|
||||||
<script src="script.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
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)
|
|
||||||
})
|
|
||||||
})
|
|
Reference in a new issue