Hi,
I need some help updating my Login panel to request the user first and last name so the contact list will have them as well as the email and password.
Any help will be very much appreciated
Pierre
ibmretraitesqc
Here my code:
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;
import {getUser} from ‘backend/getID’;
$w.onReady( () => {
$w(‘#horizontalMenu1’).hide();
$w(“#button29”).hide();
$w(“#button40”).hide();
$w(“#text25”).hide();
$w(“#anchor1”).scrollTo();
$w(“#text24”).hide()
if(wixUsers.currentUser.loggedIn) {
$w(“#button4”).label = “Déconnexion de votre compte actuel”;
$w(“#text24”).show()
$w(“#button3”).show();
}
else {
$w(“#button4”).label = “Connexion / Inscription”;
$w(“#button3”).hide();
$w(“#text24”).hide();
}
});
export function button4_onClick(event) {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#button4”).label = “Connexion / inscription”;
$w(“#button3”).hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;
// prompt the user to log in with French panel
let options = {"mode": "login", "lang": "fr"};
wixUsers.promptLogin(options)
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query("ListeMembres")
.eq("_id", userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
"_id": userId,
"adresseCourriel": userEmail,
"autorisation": "À valider",//write label to evaluate application as a member
};
// add the item to the collection
wixData.insert("ListeMembres", toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w("#button4").label = "Déconnexion de votre compte actuel";
$w("#button3").show();
$w("#text24").show();
} )
.catch( (err) => {
console.log(err);
} );
}
}
// Go to the profile page
export function button3_onclick(event) {
//console.log (wixUsers.currentUser.id)
//wixLocation.to(/ListeMembres/Update/${wixUsers.currentUser.id}
);
redirect();
}
function redirect () {
let id = wixUsers.currentUser.id
//console.log (“ICI”)
console.log (id)
getUser(id).then(product => { //This is waht you get from the backend
//console.log (product.autorisation)
console.log(product.autorisation)
console.log (product.infoComplet)
if (product.autorisation === ‘ok’ && product.infoComplet === “0”)
{
//console.log (“ici”)
wixLocation.to(“/accueil”)} //Your page if the profile is complete
else {
if (product.autorisation === 'À valider' && product.infoComplet === "0")
{
//console.log ("ici2")
$w("#text25").show();
$w("#text25").text = "Désolé, pas encore autorisé pour l'accès au site. Un courriel vous sera envoyé pour vous confirmer."
}
else {wixLocation.to(`/ListeMembres/Update/${wixUsers.currentUser.id}`);
//your page if the profile is imcomplete
//console.log (“ici3)”)
}}
// .catch(error => {
// console.log(error);
})}