This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset.html
70 lines (62 loc) · 2.54 KB
/
reset.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
---
<!DOCTYPE html>
<html lang="en">
<head>
{% include meta.html %}
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
<title>Brains@Play | Reset Password</title>
</head>
<body>
<!--Navbar-->
{% include nav.html %}
<section>
<div class="fullscreen form-container">
<div id="reset-context" class="form-context">
<h3>Reset Password</h3>
<p id="reset-message" class="small2x"></p>
<div class='flex'>
<form id="reset-form" class="form" action="">
<div class="login-element">
<input type="password" name="password" autocomplete="off" placeholder="Password"/>
</div>
<div class="login-element">
<input type="password" name="confirm-password" autocomplete="off" placeholder="Confirm Password"/>
</div>
</form>
</div>
<div class="login-buttons">
<button id="reset-button" id="login-button">Reset Password</button>
</div>
</div>
</div>
</section>
</body>
<script type="module">
import {accounts} from '../js/accounts.mjs'
let resetButton = document.getElementById('reset-button')
let resetForm = document.getElementById('reset-form')
let resetContext = document.getElementById('reset-context')
let resetMessage = document.getElementById('reset-message')
const goHome = () => {
document.body.querySelector('.form-container').innerHTML = ``
window.location = '/'
}
resetButton.onclick = () => {
let formDict = {}
let formData = new FormData(resetForm);
for (var pair of formData.entries()) formDict[pair[0]] = pair[1];
if (formDict['password'] === '') document.getElementById('reset-message').innerHTML = "password is empty. please try again."
else if (formDict['password'] !== formDict['confirm-password']) document.getElementById('reset-message').innerHTML = "passwords don't match. please try again."
else accounts.completePasswordReset(formDict['password']).then(res => {
if (!res?.error) {
resetContext.innerHTML = `<h4>Your password has been reset!</h4>`
setTimeout(goHome, 500)
}
else resetMessage.innerHTML = res.error
})
}
let token = new URLSearchParams(window.location.search).get('token');
if (!token) goHome()
</script>
</html>