javascript - 使用wix的电子邮件中的验证链接
问题描述
我是 wix https://manage.wix.com的新手。我已经创建了一个注册页面,该页面向用户发送一封电子邮件,其中包含一个链接,以确认他正在做的帐户。我很好地编码了电子邮件的发送,但我无法在电子邮件中放置激活链接,以便将其发送到确认页面并验证他的帐户。这是我的代码:
验证注册页面:
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));
}
电子邮件.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);
}
注册.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};
} );
}
解决方案
问题是我没有在触发的电子邮件上设置变量,https://support.wix.com/en/article/triggered-emails-getting-started 希望有人能从中受益。
推荐阅读
- php - 从 Wordpress 搜索中排除多个自定义分类术语
- python - 谁能帮我我的代码有什么问题?
- c# - C# Entity Framework 递归层次结构查询
- android - 从 html 为旧的 android 设备创建 pdf
- android - 如何访问使用Retrofit2获取的android中JSON响应中键内键的值?
- jasper-reports - Jasper HTML 输出宽度问题
- java - hibernate 为表名添加前缀,因此找不到它
- python - 了解 iter() 是如何工作的,不会调用对象的 __iter__()
- javascript - JSON 循环数组,它是一个对象的值
- ios - 删除行时很少发生的 Tableview 错误 - 核心数据和 FetchedResultsController