Meteor, questions about verification email
-
26-12-2019 - |
Question
I have some questions about sending verification email and popup dialogs.
- How to change verification email content? I have to add text in Russian
- How to avoid auto logging in after user registration? I would like to forbid user logging in if the email address is not verified.
- How to change content and style of popup dialogs, like Email verified?
I'm using iron-router, accounts-* packages/
Solution
To change the verification email follow the template used at : https://github.com/meteor/meteor/blob/devel/packages/accounts-password/email_templates.js
Customizing the email template
E.g (taken from the url above), there's lots to customise.
Accounts.emailTemplates.verifyEmail = {
subject: function(user) {
return "How to verify email address on " + Accounts.emailTemplates.siteName;
},
text: function(user, url) {
var greeting = (user.profile && user.profile.name) ?
("Hello " + user.profile.name + ",") : "Hello,";
return greeting + "\n"
+ "\n"
+ "To verify your account email, simply click the link below.\n"
+ "\n"
+ url + "\n"
+ "\n"
+ "Thanks.\n";
}
}
How to avoid auto logging in after user registration
To register don't use Accounts.createUser
on the client side. Use a method/call to proxy your message to the server
Client side
Meteor.call("registerMe", username, password, function(err, result) {
});
Server Side:
Meteor.methods({
registerMe: function(username, password) {
return Accounts.createUser({username: username, password: password});
}
});
How to change content and style of popup dialogs, like Email verified?
You can customize accounts-ui stuff by removing accounts-ui from your project and adding in an unstyled one, followed by adding in styles seperately
meteor remove accounts-ui
meteor add accounts-ui-unstyled
meteor add less
Then use the .less
file at https://github.com/meteor/meteor/blob/devel/packages/accounts-ui/login_buttons.less into your project and customize it to your preferences.
OTHER TIPS
Accounts.validateLoginAttempt(function(type){
if(type.user && type.user.emails && !type.user.emails[0].verified )
throw new Meteor.Error(100002, "email not verified" );
return true;
});