javascript - Meteor: Accounts.sendVerificationEmail customising behavior -


can please provide correct method send email verification upon user creation? important part...

a) user have immediate access upon signing up. if user has not yet clicked clicked on verification link within 48 hours, deny them logging in until have clicked on link.

my code far sends email verification user has continuos access application or without clicking on verification link (so code of course incomplete).

client.js

template.join.events({ 'submit #join-form': function(e,t){  e.preventdefault();   var firstname=  t.find('#join-firstname').value,   lastname=  t.find('#join-lastname').value,   email = t.find('#join-email').value,   password = t.find('#join-password').value,   username = firstname.substring(0) + '.' + lastname.substring(0),   profile = {     fullname: firstname + ' ' + lastname   };   accounts.createuser({     email: email,     username: username,     password: password,     usertype: // 'reader' or 'publisher'     createdat: new date(),     profile: profile  }, function(error) { if (error) {   alert(error); } else {   router.go('home');        }     });    } }); 

server.js

meteor.startup(function () { process.env.mail_url = 'smtp://postmaster.....'; accounts.emailtemplates.from = "no-reply@mydomain.com"; accounts.emailtemplates.sitename = "my site name";  accounts.emailtemplates.verifyemail.subject = function(user) {   return 'please confirm tour email address' ; }, accounts.emailtemplates.verifyemail.text = function(user, url) {   return 'click on link below verify address: ' + url; } accounts.config({   sendverificationemail: true }); 

my attempt have been made through own readings on meteor docs , looking @ other code on so. stuck guys. support.

i think basic idea have validation code eg in accounts.validateloginattempt want check every time before user logs in. can store date&time when user signs in user.profile.joindate. if user tries login

  • check if email address has been verified or
  • check if user logging within grace period of 48 hrs
iswithingraceperiod = function(user) {        ** tbd returning true or false.           can tricky when           have multiple instances in           different time-zones.        ** } 

and

accounts.validateloginattempt(function(attempt){   if (attempt.user && attempt.user.emails && !attempt.user.emails[0].verified ) {     console.log('no verification action received yet.');     return iswithingraceperiod(attempt.user);    }   return true; }); 

further, here html/spacebars stuff:

<body>     {{ > start }} </body>  <template name="start">   {{#if currentuser}}{{>showuserprofile}}{{else}}{{> login}}{{/if}} </template>  <template name="login">    ## grab username/password here </template> 

if login template created, can try capture verification code after user clicked verification link. note that, if no user logged in, login rendered, attach login via

template.login.created = function() {   if (accounts._verifyemailtoken) {     accounts.verifyemail(accounts._verifyemailtoken, function(err) {       if (err != null) {         if (err.message = 'verify email link expired [403]') {           var message ='sorry verification link has expired.';           console.log(message);               alertbox = blaze.renderwithdata(template.alert, {message: message}, $("body").get(0));         }       } else {         var message = "thank you! email address has been confirmed.";         console.log(message);         alertbox = blaze.renderwithdata(template.alert, {message: message}, $("body").get(0));       }     });   } }; 

the verification link send in "hook" accounts.createuser:

accounts.oncreateuser(function(options, user) {    user.profile = {};    meteor.settimeout(function() {    accounts.sendverificationemail(user._id);      }, 2 * 3000);   return user; }); 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -