使用 Wix 在电子邮件中验证 link
Verification link in email using wix
我是 wix 的新手 https://manage.wix.com。
我已经创建了一个注册页面,该页面向用户发送一封包含 link 的电子邮件,以确认他正在做的帐户。我很好地编码了电子邮件的发送,但我无法在电子邮件中放入激活 link,以便将其发送到确认页面并验证他的帐户。
这是我的代码:
验证注册页面:
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!");
}
} );
} );
注册页面:
import wixData from 'wix-data';
import wixWindow from 'wix-window';
import wixUsers from 'wix-users';
import wixUsersBackend from 'wix-users';
import {doRegistration} from 'backend/register';
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
/* send confirmation email to client to activate his account*/
function sendFormData() {
let subject = `Activate your account ${$w("#firstname").value}`;
let body = `Dear ${$w("#firstname").value} ${$w("#lastname").value},
Thank you for registering on TIMLANDS, we hope you find it rewarding!
Please note that your account at TIMLANDS needs to be activated.
Please click on the following URL: xxxxxxxxxx
If the link above does not work, try copying and pasting it into the address bar
in your browser.
This email is to confirm your registration. If you have received this email by
mistake, please notify us.
TIMLANDS Team`;
const recipient = $w("#email").value;
/* send confirmation email to client to activate his account*/
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
email.jsw
import {sendWithService} from 'backend/sendGrid';
export function sendEmail(subject, body) {
const key = "SG.IIM7kezyQXm4UD........";
const sender = "sender@gmail.com";
const recipient = "recipient@gmail.com";
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = "SG.IIM7kezyQXm4UD......";
const sender = "sender@gmail.com";
return sendWithService(key, sender, recipient, subject, body);
}
register.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://timlands/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};
} );
}
我想把 register.jsw 中的激活 link 放到注册页面的消息正文中。如下图所示
请帮忙!
问题是我没有在触发的电子邮件上设置变量,https://support.wix.com/en/article/triggered-emails-getting-started
希望有人能从中受益。
我是 wix 的新手 https://manage.wix.com。 我已经创建了一个注册页面,该页面向用户发送一封包含 link 的电子邮件,以确认他正在做的帐户。我很好地编码了电子邮件的发送,但我无法在电子邮件中放入激活 link,以便将其发送到确认页面并验证他的帐户。 这是我的代码:
验证注册页面:
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!");
}
} );
} );
注册页面:
import wixData from 'wix-data';
import wixWindow from 'wix-window';
import wixUsers from 'wix-users';
import wixUsersBackend from 'wix-users';
import {doRegistration} from 'backend/register';
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
/* send confirmation email to client to activate his account*/
function sendFormData() {
let subject = `Activate your account ${$w("#firstname").value}`;
let body = `Dear ${$w("#firstname").value} ${$w("#lastname").value},
Thank you for registering on TIMLANDS, we hope you find it rewarding!
Please note that your account at TIMLANDS needs to be activated.
Please click on the following URL: xxxxxxxxxx
If the link above does not work, try copying and pasting it into the address bar
in your browser.
This email is to confirm your registration. If you have received this email by
mistake, please notify us.
TIMLANDS Team`;
const recipient = $w("#email").value;
/* send confirmation email to client to activate his account*/
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
email.jsw
import {sendWithService} from 'backend/sendGrid';
export function sendEmail(subject, body) {
const key = "SG.IIM7kezyQXm4UD........";
const sender = "sender@gmail.com";
const recipient = "recipient@gmail.com";
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = "SG.IIM7kezyQXm4UD......";
const sender = "sender@gmail.com";
return sendWithService(key, sender, recipient, subject, body);
}
register.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://timlands/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};
} );
}
我想把 register.jsw 中的激活 link 放到注册页面的消息正文中。如下图所示
请帮忙!
问题是我没有在触发的电子邮件上设置变量,https://support.wix.com/en/article/triggered-emails-getting-started 希望有人能从中受益。