Finished up with email password reset system.

This commit is contained in:
rainbow napkin 2024-12-28 15:36:42 -05:00
parent 3671b43789
commit 478edeeddf
13 changed files with 233 additions and 34 deletions

View file

@ -54,7 +54,7 @@ class registerPrompt{
this.verification = event.detail.payload;
}
register(){
async register(){
//If altcha verification isn't complete
if(this.verification == null){
//don't bother
@ -63,7 +63,7 @@ class registerPrompt{
//If we're initiating a password change request
if(this.initiating){
await utils.ajax.requestPasswordReset(this.user.value, this.verification);
//If we're completing a password change
}else{
//if the confirmation password doesn't match
@ -74,7 +74,7 @@ class registerPrompt{
}
//Send the registration informaiton off to the server
utils.ajax.resetPassword(this.token , this.pass.value , this.passConfirm.value , this.verification);
await utils.ajax.resetPassword(this.token , this.pass.value , this.passConfirm.value , this.verification);
}
}
}

View file

@ -66,4 +66,4 @@ class registerPrompt{
}
}
const registerForm = new resetPrompt();
const registerForm = new registerPrompt();

View file

@ -481,6 +481,27 @@ class canopyAjaxUtils{
}
}
async requestPasswordReset(user, verification){
const response = await fetch(`/api/account/passwordResetRequest`,{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({user, verification})
});
//If we received a successful response
if(response.status == 200){
//Create pop-up
const popup = new canopyUXUtils.popup("A password reset link has been sent to the email associated with the account requested assuming it has one!");
//Go to home-page on pop-up closure
popup.popupDiv.addEventListener("close", ()=>{window.location = '/'});
//Otherwise
}else{
utils.ux.displayResponseError(await response.json());
}
}
async resetPassword(token, pass, confirmPass, verification){
const response = await fetch(`/api/account/passwordReset`,{
method: "POST",
@ -493,7 +514,7 @@ class canopyAjaxUtils{
//If we received a successful response
if(response.status == 200){
//Create pop-up
const popup = new canopyUXUtils.popup("Your password has been reset!");
const popup = new canopyUXUtils.popup("Your password has been reset, and all devices have been logged out of your account!");
//Go to home-page on pop-up closure
popup.popupDiv.addEventListener("close", ()=>{window.location = '/'});
//Otherwise