meteor-email-verifier
Email verification package that works with iron router.
Description
Based on https://github.com/ideaq/meteor-email
To use:
-
Add the package
meteor add cunneen:email-verifier
-
Put code similar to the following in your application, so that
- Users are sent a verification email when they register
- Users can't login until their email address has been verified.
(Note: This uses the accounts-entry package, with pull request #350 ).
1 if (Meteor.isServer) { 2 Accounts.config({ 3 "sendVerificationEmail": true, 4 "loginExpirationInDays": 5 5 }); 6 if (AccountsEntry) { 7 AccountsEntry.config({ 8 "signupCode": "secretS1gnupC0de", 9 "passwordSignupFields": "USERNAME_AND_EMAIL" 10 }); 11 } 12 //Copy all of the properties in the settings over to the emailTemplates 13 _.extend(Accounts.emailTemplates, { 14 "siteName": "My Fantastic Site", 15 "from": "no-reply@example.com" 16 }); 17 18 var loginAttemptVerifier = function (parameters) { 19 if (parameters.user && parameters.user.emails && (parameters.user.emails.length > 0)) { 20 // is the user an admin ? 21 var adminUser = (parameters.user.username === "admin"); 22 if (adminUser) { 23 return parameters.allowed; 24 } 25 // return true if verified email, false otherwise. 26 var found = _.find(parameters.user.emails, function (thisEmail) { 27 return thisEmail.verified; 28 }); 29 if (!found) { 30 throw new Meteor.Error(500, 'We sent you an email.'); 31 } 32 return found && parameters.allowed; 33 } else { 34 console.log("user has no registered emails."); 35 return false; 36 } 37 }; 38 Accounts.validateLoginAttempt(loginAttemptVerifier); 39 }
-
Ensure your email is configured:
- In your server/server.js file add the following MAIL_URL config line:
1 process.env.MAIL_URL="smtp://xxxxx%40gmail.com:yyyyy@smtp.gmail.com:465/";
Where xxxxx is your gmail username and yyyyy is your gmail password.