Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Change The Text of The Email Verification Sent Via User.verify(...) in Loopback.js

I appreciate all the need-to-haves that come right out of the box with Loopback.js but one area that could use some flexibility is the email verification that is sent upon user creation. This GitHub project helps illustrate this feature--but no where on SO or the Google Groups or in the documentation (yes, I checked there first) does it show how the actual text of the email verification can be changed.

I implemented the exact same code (as found at the previously referred-to GitHub project) in "verify.ejs"...namely:

<%= text %>

Right now the text that is inserted says:

Please verify your email by opening this link in a web browser:

I would like to refer to this user-interaction as "account activation"--not "email verification". The project has its own requirements that compels me to implement the change in semantics. Thank you in advance.

like image 308
TWright Avatar asked Dec 02 '22 16:12

TWright


1 Answers

(You know open source rocks for so many reasons...the top reason for me right now is self-documented code.)

I looked at the source of User.verify(...) and discovered that the options which can be passed in are much more expansive than documented.

In the following code snippets (from Loopback's User model) you'll see what I mean:

options.host = options.host || (app && app.get('host')) || 'localhost';
    options.port = options.port || (app && app.get('port')) || 3000;

// ### (later) ### //

options.text = options.text || 'Please verify your email by opening this link in a web browser:\n\t{href}';

options.text = options.text.replace('{href}', options.verifyHref);

So, in short, set these parameters in the options object passed in to User.verify():

var options = { 
  host: 'http://some.domain.com',
  port: 5000,
  text: 'Please activate your account by clicking on this link or copying and pasting it in a new browser window:\n\t{href}'
}

Source code for User.verify(..) found at: https://github.com/strongloop/loopback/blob/master/common/models/user.js

like image 117
TWright Avatar answered May 04 '23 23:05

TWright