-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset_password.html
87 lines (83 loc) · 3.59 KB
/
reset_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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="style2.css" />
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet" />
<title>Sign In - Charities Hub</title>
<style>
.error-message {
color: red;
}
</style>
</head>
<body>
<div class="container">
<div class="card">
<h2>Reset Password</h2>
<form id="reset-form">
<div class="input-group">
<label for="email">Email:</label>
<input type="text" id="email" name="email" placeholder="Enter your email" />
</div>
<div class="input-group">
<label for="security">What was the name of your first pet?</label>
<input type="text" id="security" name="security" placeholder="Answer your security question" />
</div>
<div class="input-group">
<label for="password">New Password:</label>
<input type="text" id="password" name="password" placeholder="Enter new password" />
</div>
<p id="error-message" class="error-message" style="display: none;">Invalid email</p>
<button type="submit">Reset Password</button>
</form>
<p>Don't have an account? <a href="register.html">Register here</a>.</p>
<p>Remembered your password? <a href="signin.html">Sign in</a>.</p>
</div>
</div>
<script>
document.getElementById("reset-form").addEventListener("submit", function (event) {
event.preventDefault(); // Prevent the form from submitting normally
var email = document.getElementById("email").value;
var security = document.getElementById("security").value;
var password = document.getElementById("password").value;
fetch('http://127.0.0.1:5001/resetPassword', {
method: 'POST',
headers: {
'Content-Type': 'application/json' // Add Content-Type header
},
body: JSON.stringify({
email: email,
security: security,
password: password
})
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
if (data && data.message === 'Reset successful!') {
// Store the authentication token securely
localStorage.setItem('token', data.token);
localStorage.setItem('name', data.name);
localStorage.setItem('charity', data.charity);
localStorage.setItem('pfp', data.pfp);
// Redirect the user to another page
window.location.href = 'index.html';
} else {
// Display error message
var errorMessageElement = document.getElementById("error-message");
errorMessageElement.style.display = "block";
}
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
// Handle error here
});
});
</script>
</body>
</html>