mirror of
https://github.com/xfarrow/blink
synced 2025-02-16 08:00:35 +01:00
forgot-password.html working
This commit is contained in:
parent
97783ab96a
commit
175ca90ba5
@ -9,12 +9,13 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="alert alert-success" role="alert" style="display: none;">
|
||||
An e-mail has been sent to reset your password
|
||||
|
||||
<div class="alert alert-success" role="alert" id="successAlert" style="display: none;">
|
||||
</div>
|
||||
<div class="alert alert-danger" role="alert" style="display: none;">
|
||||
This is a danger alert—check it out!
|
||||
|
||||
<div class="alert alert-danger" role="alert" id="errorAlert" style="display: none;">
|
||||
</div>
|
||||
|
||||
<div class="container d-flex flex-column">
|
||||
<div class="row align-items-center justify-content-center
|
||||
min-vh-100 g-0">
|
||||
@ -26,24 +27,84 @@
|
||||
<p class="mb-2">Enter your registered email to reset the password
|
||||
</p>
|
||||
</div>
|
||||
<form>
|
||||
<div class="mb-3">
|
||||
<input type="email" id="email" class="form-control" name="email"
|
||||
placeholder="Enter Your Email" required="">
|
||||
<div class="mb-3">
|
||||
<input type="email" id="email" class="form-control" name="email"
|
||||
placeholder="Enter Your Email" onblur="emailFieldLosesFocus();">
|
||||
<div class="invalid-feedback">
|
||||
Please enter an email address
|
||||
</div>
|
||||
<div class="mb-3 d-grid">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Continue
|
||||
</button>
|
||||
</div>
|
||||
<span>Don't have an account? <a href="login.html">sign in</a></span>
|
||||
</form>
|
||||
</div>
|
||||
<div class="mb-3 d-grid">
|
||||
<button type="button" class="btn btn-primary" onclick="proceed();">
|
||||
Continue
|
||||
</button>
|
||||
</div>
|
||||
<span>Don't have an account? <a href="login.html">sign in</a></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../js/constants.js"></script>
|
||||
<script src="../js/utils.js"></script>
|
||||
<script>
|
||||
async function proceed() {
|
||||
if (!validateFields()) {
|
||||
return;
|
||||
}
|
||||
const email = document.getElementById("email").value;
|
||||
const response = await fetch(`${API_URL}/resetpassword/request`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
email
|
||||
}),
|
||||
headers: createHeaders(null)
|
||||
});
|
||||
if(response.ok){
|
||||
showSuccessAlert('An email has been sent to reset your password');
|
||||
}
|
||||
else{
|
||||
showErrorAlert('Something went wrong. Try again later')
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function gets called when the e-mail field loses focus. This is
|
||||
* done to inform the user whether the entered e-mail is in a valid format
|
||||
*/
|
||||
function emailFieldLosesFocus() {
|
||||
const emailField = document.getElementById("email");
|
||||
if (!emailField.value || !validateEmail(emailField.value)) {
|
||||
emailField.classList.add("is-invalid");
|
||||
} else {
|
||||
emailField.classList.remove("is-invalid");
|
||||
}
|
||||
}
|
||||
|
||||
function validateFields() {
|
||||
const emailField = document.getElementById("email");
|
||||
var isFormValid = true;
|
||||
if (!emailField.value || !validateEmail(emailField.value)) {
|
||||
emailField.classList.add("is-invalid");
|
||||
isFormValid = false;
|
||||
}
|
||||
return isFormValid;
|
||||
}
|
||||
|
||||
function showSuccessAlert(message) {
|
||||
const successAlert = document.getElementById('successAlert');
|
||||
successAlert.innerHTML = message;
|
||||
successAlert.style.display = 'block';
|
||||
}
|
||||
|
||||
function showErrorAlert(message) {
|
||||
const errorAlert = document.getElementById('errorAlert');
|
||||
errorAlert.innerHTML = message;
|
||||
errorAlert.style.display = 'block';
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
@ -102,12 +102,12 @@
|
||||
* This function is responsible for the log-in process
|
||||
*/
|
||||
async function login() {
|
||||
const email = document.getElementById("email").value;
|
||||
const password = document.getElementById("password").value;
|
||||
|
||||
if (!validateFields()) {
|
||||
return;
|
||||
}
|
||||
const email = document.getElementById("email").value;
|
||||
const password = document.getElementById("password").value;
|
||||
|
||||
|
||||
const response = await fetch(`${API_URL}/persons/me/token`, {
|
||||
method: "POST",
|
||||
|
Loading…
x
Reference in New Issue
Block a user