-
Notifications
You must be signed in to change notification settings - Fork 0
/
change-password.html
43 lines (39 loc) · 1.04 KB
/
change-password.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>Change Password</h1>
<form id="reg-form">
<input type="password" autocomplete="off" id="password" placeholder="Password" />
<input type="submit" value="Submit Form" />
</form>
<script>
const form = document.getElementById('reg-form')
form.addEventListener('submit', registerUser)
async function registerUser(event) {
event.preventDefault()
const password = document.getElementById('password').value
const result = await fetch('/api/change-password', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
newpassword: password,
token: localStorage.getItem('token')
})
}).then((res) => res.json())
if (result.status === 'ok') {
// everythign went fine
alert('Success')
} else {
alert(result.error)
}
}
</script>
</body>
</html>