top of page

Forum Comments

Removing auto confirmation mail + lightbox after using wixUser.register()
In Coding with Velo
GOS
Velo Expert
Velo Expert
Jun 29, 2020
I have done similar on a site where I used this tutorial as a starting point for a members only page. https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area Then I used the signup lightbox code similar to yours. import wixUsers from 'wix-users'; import wixWindow from 'wix-window'; import wixLocation from 'wix-location'; $w.onReady(function () { $w("#registerButton").onClick( (event) => { 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": $w('#firstName').value, "lastName": $w('#lastName').value } } ) .then( (result) => { let resultStatus = result.status; wixWindow.lightbox.close(); wixLocation.to("/sign-in-status"); //Change the URL ending to whatever page you want to send the user to after they log in. } ); } ); }); NOTE: Take out this line: wixLocation.to("/sign-in-status"); replace it with this line: wixWindow.openLightbox("Login"); at end of code if you want the lightbox to close and then to open the login lightbox. This works perfectly and closes after registering details before moving the user onto the sign-in-status page, then both names will be saved in Contacts and once site member is approved the member details will be added to 'members' database, which is the same one from the tutorial. On my members only page, I modified the code to suit the site as this. import wixUsers from 'wix-users'; import wixData from 'wix-data'; import wixLocation from 'wix-location'; $w.onReady( () => { if(wixUsers.currentUser.loggedIn) { $w("#loginbutton").label = "Logout"; $w("#membersareaonlystrip").expand(); $w("#whitegapforfooter").hide(); } else { $w("#loginbutton").label = "Login"; $w("#membersareaonlystrip").collapse(); $w("#whitegapforfooter").show(); } } ); export function loginbutton_onclick(event) { // user is logged in if(wixUsers.currentUser.loggedIn) { // log the user out wixUsers.logout() .then( () => { // update buttons accordingly $w("#loginbutton").label = "Login"; $w("#membersareaonlystrip").collapse(); $w("#whitegapforfooter").show(); } ); } // user is logged out else { let userId; let userEmail; // prompt the user to log in wixUsers.promptLogin( {"mode": "signup"} ) .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("Members") .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, "email": userEmail }; // add the item to the collection wixData.insert("Members", toInsert) .catch( (err) => { console.log(err); } ); } // update buttons accordingly $w("#loginbutton").label = "Logout"; $w("#membersareaonlystrip").expand(); $w("#whitegapforfooter").hide(); } ) .catch( (err) => { console.log(err); } ); } } export function profilebutton_onclick(event) { wixLocation.to(`/Members/${wixUsers.currentUser.id}`); } export function entermembersbutton_onclick(event) { wixLocation.to(`/members-area`); } export function myaccountbutton_onclick(event) { wixLocation.to(`/account/my-account`); } export function websiteupdatebutton_onclick(event) { wixLocation.to(`/website-update`); } The login button on this page is the only place that members on this site can login and logout as well. The login lightbox code is this. import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; import wixWindow from 'wix-window'; $w.onReady(function () { $w("#forgotPassword").onClick( (event) => { //wixWindow.lightbox.close() wixUsers.promptForgotPassword() .then( ( ) => { // } ) .catch( (err) => { let errorMsg = err; //"The user closed the forgot password dialog" }); }); }); export function loginButton_onclick(event) { let email = $w("#email").value; let password = $w("#password").value; wixUsers.login(email, password) .then( () => { console.log("User is logged in"); wixWindow.lightbox.close(); wixLocation.to(wixLocation.url); //This reloads the same page and allows code to show hidden member parts. } ) .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. } ); } Note that you will see that I have used this in the Wix Location to() function to refresh the members only page after the login lightbnox is closed. This needs to be done if you use the Members Profile tutorial from Wix as it is working on the basis that you are moving the user onto another page after they have logged in. So when you come back to the first page, you are reloading the page and rerunning the code again which will then be able to know that the user is currently logged in. However, as I wanted to stay on the same page I needed the page itself to be refreshed after the member is logged in so that the page code would run again and know that the user is logged in and to show all the members only parts and to make the button change to logout. If you don't refresh the page and stay on it, then it won't register the user as being logged in and the button will not change to logout, it will stay on login etc. To have it move to a new page then just do this. import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; import wixWindow from 'wix-window'; $w.onReady(function () { $w("#forgotPassword").onClick( (event) => { //wixWindow.lightbox.close() wixUsers.promptForgotPassword() .then( ( ) => { // } ) .catch( (err) => { let errorMsg = err; //"The user closed the forgot password dialog" }); }); }); export function loginButton_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("/account/my-account"); //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(); // 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. } ); } Now here you can change the code here: wixLocation.to("/account/my-account"); To the page that you want to actually move to, which is your member profile page. This is what I have done with a simple member profile button shown on the members only page after they have logged in. export function profilebutton_onclick(event) { wixLocation.to(`/Members/${wixUsers.currentUser.id}`); } So you would just need to change yours from: wixLocation.to(`/Members/${wixUsers.currentUser.id}`); to yours as stated: wixLocation.to(`/members-first-connection/${wixUsers.currentUser.id}`);
Removing auto confirmation mail + lightbox after using wixUser.register()
In Coding with Velo
GOS
Velo Expert
Velo Expert
Jun 29, 2020
The Wix window that you are receiving here is nothing to do with your register or login code, it is a basic Wix window which appears sometimes to verify users. See this Wix Support page for more info. https://support.wix.com/en/article/email-verification-for-site-members Also, when you use Wix Users API and the register() function, please note that the user is only having the choice of being manually approved and being a pending member until then, or if being automatically approved and being a active member. https://www.wix.com/corvid/reference/wix-users.html#register This however, does not mean that they are instantly logged in, they are only then classed as an active member of the site in the Wix Users API. Therefore, in your signup lightbox code, you would need to add a close lightbox command and then an open login lightbox command, so that the user can go from the signup loghtbox to the login lightbox. https://www.wix.com/corvid/reference/wix-window.lightbox.html#close https://www.wix.com/corvid/reference/wix-window.html#openLightbox Another option would be to have a collapsed element on your signup lightbox that is expanded after the member has registered themselves and then the signup lightbox is closed after a setTimeout. Or you can simply set the lightbox to close after the user has registered themselves and you can take the newly signed up member to the members area if you have one and then have a login button that opens your login lightbox or you can use the promptLogin() function. https://www.wix.com/corvid/reference/wix-users.html#login https://www.wix.com/corvid/reference/wix-users.html#promptLogin
Content media
1
2
Multi-reference use in database
In Coding with Velo
GOS
Velo Expert
Velo Expert
Jun 29, 2020
Are you looking to do something like this? https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area Or something different? There is an example in Wix Users API that you can use to work from for querying the Wix members app collection and getting the users info. https://www.wix.com/corvid/reference/wix-users.html How can I get the current user's name? Use the currentUser property to get the current user's id. Then query the Members/PrivateMembersData collection for the item with that _id. wixData.query("Members/PrivateMembersData") \ .eq("_id", wixUsers.currentUser.id) \ .find() \ .then( (results) => { \ lastName = results.items[0].lastName; \ } ); Or look at this previous forum post. https://www.wix.com/corvid/forum/community-discussion/solved-get-any-data-from-wixusers However, if the user is currently logged in and you are using the Members/PrivateMembersData, then you can simply add a dataset element to your page and connect it to the Wix members collection. Then just connect that user input or text box to the specific field from the dataset and as the user is already logged in, the dataset will be filtered for that user only and it will only display that users data. Otherwise, you can use getCurrentItem() and set the user input or text box with that. getCurrentitem(); will return all the users data, if you want to just call a field then you need to be using getCurrentItem().fieldname; https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getCurrentItem If you autofill something like a user input, then it won't recognise a value has been entered and if you tried to save it as is, then it would just return an empty value. Therefore you would need to use the setFieldValue() or setFieldValues() with a submit button or the save() function in code to save your prefilled entries into the collection. https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValues You can see an example here from Vorbly how to do it. https://www.vorbly.com/Vorbly-Code/WIX-CODE-AUTO-FILL-FORM-WITH-USER-INPUTS
0
0
How to add preloader to each page of my website .
In Coding with Velo
Reviews not expanding and collapsing.
In Coding with Velo
GOS
Velo Expert
Velo Expert
Jun 29, 2020
If you are using the Wix Stores Ratings/Review tutorial, then it does that already as stated in the tutorial workings. https://support.wix.com/en/article/corvid-tutorial-adding-ratings-and-reviews-to-a-wix-stores-site Step 2: Set up the Shop Product Page On the Shop Product Page we added: //.... "load more" text at the bottom of the page for loading additional reviews. Step 6: Create the loadStatistics Function on the Product Page The loadStatistics function gets and displays statistics for the current product. async function loadStatistics() { const stats = await wixData.get('review-stats', product._id); if (stats) { let avgRating = (Math.round(stats.rating * 10 / stats.count) / 10); let percentRecommended = Math.round(stats.recommended / stats.count * 100); let ratings = $w('#generalRatings'); ratings.rating = avgRating; ratings.numRatings = stats.count; $w('#recoPercent').text = `${percentRecommended} % would recommend`; $w('#generalRatings').show(); } else { $w('#recoPercent').text = 'There are no reviews yet'; } $w('#recoPercent').show(); } Understanding the Code Line 2: Use the current product's ID to get the product's statistics from the review-stats collection and assign them to the stats variable. Line 3: Check whether there are any statistics related to the current product, indicating that one or more users have rated the product. If there are stats, do the following: Line 4: Calculate the average rating of the product by dividing the sum of all ratings the product received from all reviewers by the number of times the product was rated, multiplying by ten, and rounding the number. Line 5: Calculate the percentage of people who recommended the product by dividing the total number of recommendations the product received by the number of times the product was rated, multiplying by 100, and rounding the number. Line 6: Get the generalRatings ratings element and assign it to the ratings variable. Line 7: Set the ratings element's rating value to the average rating calculated above. Line 8: Set the ratings element's total number of ratings from the count field in the review-stats collection for the current product. Line 9: Set the text that displays the recommended percent. Line 10: Show the ratings element. Lines 11-14: If there are no stats (indicating that no reviewers have rated the product yet), display text stating that there are no reviews yet. Step 8: Create the showReviews Function on the Product Page showReviews expands or collapses the review strip that displays the reviews depending on whether any reviews were submitted. export function showReviews() { if ($w('#Reviews').getTotalCount() > 0) { $w('#reviewsStrip').expand(); } else { $w('#reviewsStrip').collapse(); } } Understanding the Code Line 2: Use the getTotalCount function to check whether there are any reviews in the Reviews dataset for the current product. Lines 3-5: If there are reviews, expand the review strip. If there are no reviews, collapse the review strip. Step 10: Create the resultsPages_click Function on the Product Page resultsPages_click runs when the reviewer clicks the "load more" text at the bottom of the Product page. We selected the "load more" text and, in the Properties panel, added an onClick event handler. When the visitor clicks the text, the resultsPages_click event handler loads another page (chunk) of reviews into the reviewsRepeater. Note The number of reviews displayed in each page (chunk) of the repeater is defined in the Reviews dataset. Click the dataset, click Manage Dataset and enter the Number of items to display. export function resultsPages_click(event, $w) { $w('#Reviews').loadMore(); } Understanding the Code Lines 1-2: When the event handler is triggered, the Reviews dataset loads the next page (chunk) of reviews using the loadMore function.
2
1
wixWindow.WindowSizeInfo
In Coding with Velo

GOS

Velo Expert
+4
More actions
bottom of page