I need a forgot password prompt for my login page and right now I have to have a signup function attached to the code too and its getting on someones nerves having to link the forgot password text to another page with a button that then opens the prompt as you can see on my login page at https://sewellstephens.com/login
Login page:
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
export function button25_click(event) {
let email = $w("#email").value;
let password = $w("#password").value;
wixUsers.login(email, password)
.then( () => {
console.log("User is logged in");
wixLocation.to("https://sewellstephens.com/dashboard"); //Change the URL ending to whatever page you want to send the user to after they log in.
} )
.catch( (err) => {
console.log(err);
$w("#errorMessage").expand();
} );
}
export function page1_viewportEnter(event) {
$w("#email").focus();
}
export function email_focus(event) {
$w("#placeholderE").hide();
$w('#emailtxt').show();
}
export function password_focus(event) {
$w("#placeholderP").hide();
$w('#passwordtxt').show();
}
export function button64_click(event) {
$w('#box').show();
}
export function password_blur(event) {
$w("#placeholderP").show();
$w('#passwordtxt').hide();
}
export function email_blur(event) {
$w("#placeholderE").show();
$w('#emailtxt').hide();
}
Signup page:
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
$w.onReady(function(){
$w('#button25').onClick(function (){
let email = $w('#email').value;
let password = $w('#password').value;
wixUsers.register(email,password)
.then(()=>{
wixLocation.to('/verify');
})
.catch( (err) => {
console.log(err);
$w("#errorMessage").expand(); // You can delete this line if you are not going to add an error message. Use a regular text element set to 'collapse on load' from the Properties Panel.
} );
})
})
if (wixUsers.currentUser.loggedIn) {
wixLocation.to("https://sewellstephens.com/verify"); //Change the URL ending to the page you want to redirect the user if they are already logged in
}
export function input2_focus(event) {
$w("#placeholderF").hide();
$w('#firstnametxt').show();
}
export function input3_focus(event) {
$w("#placeholderL").hide();
$w('#lastnametxt').show();
}
export function password_focus(event) {
$w("#placeholderP").hide();
$w('#passwordtxt').show();
}
export function email_focus(event) {
$w("#placeholderE").hide();
$w('#emailtxt').show();
}
export function input4_focus(event) {
$w("#placeholderO").hide();
$w('#phonetxt').show();
}
export function input2_blur(event) {
$w("#placeholderF").show();
$w('#firstnametxt').hide();
}
export function input3_blur(event) {
$w("#placeholderL").show();
$w('#lastnametxt').hide();
}
export function email_blur(event) {
$w("#placeholderE").show();
$w('#emailtxt').hide();
}
export function password_blur(event) {
$w("#placeholderP").show();
$w('#passwordtxt').hide();
}
export function input4_blur(event) {
$w("#placeholderO").show();
$w('#phonetxt').hide();
}
Forgot password page:
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import wixData from 'wix-data';
let registration;
$w.onReady(function () {
$w("#forgotPassword").onClick((event) => {
wixUsers.promptForgotPassword()
.then(() => {
//
})
.catch((err) => {
let errorMsg = err;
});
});
if (wixUsers.currentUser.loggedIn) {
wixLocation.to("/dashboard"); //Change the URL ending to the page you want to redirect the user if they are already logged in
}
$w("#password").onKeyPress((event) => {
let key = event.key;
$w('#errorMessage').hide();
$w('#emailExists').hide();
if (key === "Enter") {
console.log("Pressed Enter key on Password field"); //You can change the text of this line or delete it
if ($w("#email").valid && $w("#password").valid && $w("#firstName").valid && $w("#lastName").valid) {
let email = $w("#email").value;
let password = $w("#password").value;
let first = $w("#firstName").value;
let last = $w("#lastName").value;
wixUsers.register(email, password, {
contactInfo: {
"firstName": first,
"lastName": last
}
})
.then((result) => {
wixLocation.to("/account/member-home"); //Change the URL ending to the page you want to redirect the user after they successfully register
})
.catch((err) => {
let errorMsg = err;
console.log(errorMsg);
$w('#emailExists').show();
});
} else {
console.log("Some inputs are invalid"); //You can change the text of this line or delete it
$w('#errorMessage').show();
}
} else {
console.log("Did not press Enter key."); //You can change the text of this line or delete it
}
});
$w("#registrationButton").onClick((event) => {
console.log("Button was clicked"); //You can change the text of this line or delete it
$w('#errorMessage').hide(); //We want to hide all error messages when the person attempts to register again
$w('#emailExists').hide(); //We want to hide all error messages when the person attempts to register again
if ($w("#email").valid && $w("#password").valid && $w("#firstName").valid && $w("#lastName").valid) {
registerPerson();
console.log("Trying to register"); //You can change the text of this line or delete it
} else {
$w('#errorMessage').show(); //This is were we prompt the message to show up again ONLY if there is an error
console.log("Missing information"); //You can change the text of this line or delete it
}
});
});
function registerPerson() {
let email = $w("#email").value;
let password = $w("#password").value;
let first = $w("#firstName").value;
let last = $w("#lastName").value;
wixUsers.register(email, password, {
contactInfo: {
"firstName": first,
"lastName": last
}
})
.then((result) => {
wixLocation.to("/account/member-home"); //Change the URL ending to the page you want to redirect the user after they successfully register
})
.catch((err) => {
let errorMsg = err;
console.log(err);
$w('#emailExists').show(); //This is were we prompt the message to show up again ONLY if there is an error
});
}
To understand the code please open this page: https://sewellstephens.com/login