Trying Register a user sending an email for confirmation

I’m not a web-developer.

So, i’m trying to Register a user sending an email for confirmation like
https://www.wix.com/corvid/forum/community-discussion/register-a-user-sending-an-email-for-confirmation-1
https://www.wix.com/corvid/forum/community-discussion/confirmation-verification-email-question?origin=auto_suggest

and others.

Now i have:

rebrandy.net - test web-site on wix

Log-in page - standard user registration form with code (maybe i should create my own new page with form? don’t know)

register.jsw - I created this file and put the code in it, replacing only the address of the verify link

Verification page - I created empty page with address rebrandy.net/verificationpage and put the code in it

I also changed the type of user registration from “Everyone” to " Only manually approved by me "

I also created a triggered email , which is sent to the user after registration in this form (but i don’t know what code i should write in that email)

So, now it works like that -

  1. You enter email and password in registration form, click the button and get the message
    “Success! Your member login request has been sent and is awaiting approval. The site administrator will notify you via email (***) once your request has been approved.”
  2. You receive email with no verification code (obviously)
  3. thats it, nothing else you can do

I want to link all the components together so that the user fills out the registration form, clicks on the button, sees the message “we sent you a verification link”, received a letter at his mailbox, clicked on the verification link and became a verified user on my site.

What i’m doing wrong?
Thanks in advance!

Code for login page

/*********************************
* client-side registration code *
*********************************/
import wixUsers from 'wix-users';
import {doRegistration} from 'backend/register';
export function button_click(event) {
let email = $w('#email').value; // the user's email address
let password = $w('#password').value; // the user's password
doRegistration(email, password)
.then( () => {
console.log("Confirmation email sent.");
} );
}

Code for register.jsw

/*******************************
* backend code - register.jsw *
*******************************/
import wixUsers from 'wix-users-backend';
export function doRegistration(email, password, firstName, lastName) {
// register the user
return wixUsers.register(email, password, {
"contactInfo": {
"firstName": firstName,
"lastName": lastName
}
} )
.then( (results) => {
// user is now registered and pending approval
// send a registration verification email
wixUsers.emailUser('verifyRegistration', results.user.id, {
"variables": {
"name": firstName,
"verifyLink": `http://rebrandy.net/verificationpage?token=${results.approvalToken}`
}
} );
} );
}
export function doApproval(token) {
// approve the user
return wixUsers.approveByToken(token)
// user is now active, but not logged in
// return the session token to log in the user client-side
.then( (sessionToken) => {
return {sessionToken, "approved": true};
} )
.catch( (error) => {
return {"approved": false, "reason": error};
} );
}

Code for Verification page

/**************************************
* client-side post-registration code *
**************************************/
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import {doApproval} from 'backend/register';
$w.onReady( () => {
// get the token from the URL
let token = wixLocation.query.token;
doApproval(token)
.then( (result) => {
if (result.approved){
// log the user in
wixUsers.applySessionToken(result.sessionToken);
console.log("Approved");
}
else {
console.log("Not approved!");
}
} );
} );

You need to change your signup window from the Wix Custom option to the Wix Corvid option as shown here.
https://support.wix.com/en/article/about-the-member-signup-form

If you use the Wix default or custom window, then the signup is being done automatically for you when the user clicks on the submit button in the window.

To do it through code, then you will need to make up your own Corvid form for your signup and login lightboxes so that you can use the register function in your code.
https://www.wix.com/corvid/reference/wix-users-backend.html#register
https://www.wix.com/corvid/reference/wix-users-backend.html#approveByEmail

This old post should give you a hand with it too.
https://www.wix.com/corvid/forum/community-discussion/tutorial-email-approval-token

“1. Set up a ‘Triggered Email’ - In your WiX Dashboard, go to ‘Marketing Tools’, then to ‘Triggered Emails’ right at the bottom and create a new triggered email. Give it the ID: ’ verifyRegistration’ - we will use this ID in our code.”

Where can i find that ID field?
Because i can’t find it on the page with triggered emails.

Or now it is the name of the process?

Also, now i created the my own corvid singup form, write the code, gave the IDs to the fields and the button. But after filling out my form and clicking the button, nothing happens at all, users are not added to the list of users and a verification email is not sent, and no changes occur on the page after the button is clicked.

About my first question “Where can i find that ID field?”
The problem was in Russian version of the Wix Panel.
That field is only in En version.

Okay, so have you actually connected the button with a onClick event handler from the properties panel or did you simply just copy and paste the code?

See here for more info.
https://support.wix.com/en/article/corvid-working-with-the-properties-panel
https://support.wix.com/en/article/corvid-reacting-to-user-actions-using-events

I think my button is connected now.

If i understand correctly - i also need a dataset which will collect all members data?
Now it working like that - after btn click members data from the fields are writing to that dataset, but no email sending.

Also, with your code listed above in your code block, please make sure that you double check it with the code from the Wix API reference as you are missing out a few important bits.
https://www.wix.com/corvid/reference/wix-users-backend.html#approveByEmail

Backend JSW

import wixUsersBackend from 'wix-users-backend';
return wixUsersBackend.register(email, password, {
wixUsersBackend.emailUser('verifyRegistration', results.user.id, {
return wixUsersBackend.approveByToken(token)

Login Page

import wixUsersBackend from 'wix-users';

Post page

import wixUsersBackend from 'wix-users';
wixUsersBackend.applySessionToken(result.sessionToken);

From your later pics, it does look like you have changed some, however please check that they are all done.

You do not need to use a dataset as when users register on your site all the info is saved into the Wix CRM and then you can see it in your Contacts List on your Wix Dashboard.

Delete the dataset and the link from the submit button itself,

Although, you might need to add custom fields if you want ones that are not there already.
https://support.wix.com/en/article/adding-custom-fields-to-contacts

If you have used the Wix Members app on your site, then that has its own collection that is read only and only the specific site member can see their own data.
https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields

However, you can workaround this with Wix Data Options in the backend.
https://www.wix.com/corvid/reference/wix-data.html#WixDataOptions

Just note that site members use Wix Users whereas users who have just contacted you will be using the Wix CRM.

What’s the difference between wix-crm and wix-users?
The CRM API contains functionality for working with your site’s contacts. The Users API contains functionality for working with users who are logged-in members. Note that all members are also contacts, but contacts are not necessarily members.

https://www.wix.com/corvid/reference/wix-crm.html
https://www.wix.com/corvid/reference/wix-crm-backend.html

https://www.wix.com/corvid/reference/wix-users.html
https://www.wix.com/corvid/reference/wix-users-backend.html

You can add your own dataset for getting members data like as in this Wix tutorial for your own member profile page.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

Ok, now:
after btn click user shown in members list in status “pending”

And even email sending, but link is dead


In editor it looks like

Sorry to bother you, but as I said earlier, I’m not a developer.

Now I fix the link (as i think), and i go that page, but i’m still “pending”

about the code now

Reg page

import wixUsersBackend from 'wix-users';
import {doRegistration} from 'backend/register';
export function button_click(event) {
let email = $w('#email').value; // the user's email address
let password = $w('#password').value; // the user's password
let firstName = $w('#firstname').value; // the user's first name
let lastName = $w('#lastname').value; // the user's last name
doRegistration(email, password)
.then( () => {
console.log("Confirmation email sent.");
} );
}

Reg jsw

import wixUsersBackend from 'wix-users-backend';
export function doRegistration(email, password, firstName, lastName) {
// register the user
return wixUsersBackend.register(email, password, {
"contactInfo": {
"firstName": firstName,
"lastName": lastName
}
} )
.then( (results) => {
// user is now registered and pending approval
// send a registration verification email
wixUsersBackend.emailUser('verifyRegistration', results.user.id, {
"variables": {
"name": firstName,
"verifyLink": `http://rebrandy.net/verificationpage?token=${results.approvalToken}`
}
} );
} );
}
export function doApproval(token) {
// approve the user
return wixUsersBackend.approveByToken(token)
// user is now active, but not logged in
// return the session token to log in the user client-side
.then( (sessionToken) => {
return {sessionToken, "approved": true};
} )
.catch( (error) => {
return {"approved": false, "reason": error};
} );
}

Verification page

import wixLocation from 'wix-location';
import wixUsersBackend from 'wix-users';
import {doApproval} from 'backend/register';
$w.onReady( () => {
// get the token from the URL
let token = wixLocation.query.token;
doApproval(token)
.then( (result) => {
if (result.approved){
// log the user in
wixUsersBackend.applySessionToken(result.sessionToken);
console.log("Approved");
}
else {
console.log("Not approved!");
}
} );
} );

Omg

Now it is working.
User get an email, and verification link working, and aproval working via that link.

But still a lot of questions.

Several more questions:

  1. Now i have my custom corvid reg form, and for login i use standard form. How can i change the design of that standard login form? Because i can change the design of old standard reg form, but i can’t switch between reg and login form in website editor.

  1. In my new corvid reg form - How can i check if both fields (email and pass) are filled and make the button active or inactive?

  1. How can i check with corvid code if current user is logged or not, and depending on that show or collapse some elements on any page?

3rd problem is solved.

Guys i am also trying do similar stuff.I have used " Register a user sending an email for confirmation" do i need to create email trigger separately ?

Steps i followed:

  1. Changed the login setup to Corvid.
  2. Created registration light box with code for The page code for the page where users register
  3. Created A backend web module named register.jsw
    4. Created " The page code for the page where users confirm their registration"

But still email is not getting triggered? User is getting registered and status is ACTIVE in dataset.

Email is getting triggered now. Once we click link, it goes to approval page but in console it shows as not approved.
@ ab4583325
#corvidmaster
Kindly help