首页 > 解决方案 > 使用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};
         } );
      }

我想将 register.jsw 中的激活链接放到注册页面中的消息正文中。如下图所示,请大家帮忙! 在此处输入图像描述

标签: javascriptvelowix3.7

解决方案


问题是我没有在触发的电子邮件上设置变量,https://support.wix.com/en/article/triggered-emails-getting-started 希望有人能从中受益。


推荐阅读