closes #3271
parent
54226a86b4
commit
5ee1951245
@ -0,0 +1,81 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
nconf = require('nconf'),
|
||||
winston = require('winston'),
|
||||
db = require('./../database'),
|
||||
|
||||
meta = require('../meta'),
|
||||
emailer = require('../emailer'),
|
||||
|
||||
plugins = require('../plugins'),
|
||||
translator = require('../../public/src/modules/translator'),
|
||||
utils = require('../../public/src/utils');
|
||||
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
User.sendInvitationEmail = function(uid, email, callback) {
|
||||
callback = callback || function() {};
|
||||
var token = utils.generateUUID();
|
||||
var registerLink = nconf.get('url') + '/register?token=' + token + '&email=' + email;
|
||||
|
||||
var oneDay = 86400000;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.set('invitation:email:' + email, token, next);
|
||||
},
|
||||
function(next) {
|
||||
db.pexpireAt('invitation:email:' + email, Date.now() + oneDay, next);
|
||||
},
|
||||
function(next) {
|
||||
User.getUserField(uid, 'username', next);
|
||||
},
|
||||
function(username, next) {
|
||||
var title = meta.config.title || meta.config.browserTitle || 'NodeBB';
|
||||
translator.translate('[[email:invite, ' + title + ']]', meta.config.defaultLang, function(subject) {
|
||||
var data = {
|
||||
site_title: title,
|
||||
registerLink: registerLink,
|
||||
subject: subject,
|
||||
username: username,
|
||||
template: 'invitation'
|
||||
};
|
||||
|
||||
if (plugins.hasListeners('action:email.send')) {
|
||||
emailer.sendToEmail('invitation', email, meta.config.defaultLang, data, next);
|
||||
} else {
|
||||
winston.warn('No emailer to send verification email!');
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
User.verifyInvitation = function(query, callback) {
|
||||
if (!query.token || !query.email) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.get('invitation:email:' + query.email, next);
|
||||
},
|
||||
function(token, next) {
|
||||
if (!token || token !== query.token) {
|
||||
return next(new Error('[[error:invalid-token]]'));
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
User.deleteInvitation = function(email, callback) {
|
||||
callback = callback || function() {};
|
||||
db.delete('invitation:email:' + email, callback);
|
||||
};
|
||||
|
||||
};
|
@ -0,0 +1,14 @@
|
||||
<p>[[email:greeting_no_name]],</p>
|
||||
|
||||
<p>
|
||||
<strong>[[email:invitation.text1, {username}, {site_title}]]</strong>
|
||||
</p>
|
||||
|
||||
<blockquote>
|
||||
<a href="{registerLink}">[[email:invitation.ctr]]</a>
|
||||
</blockquote>
|
||||
|
||||
<p>
|
||||
[[email:closing]]<br />
|
||||
<strong>{site_title}</strong>
|
||||
</p>
|
@ -0,0 +1,11 @@
|
||||
[[email:greeting_no_name]],
|
||||
|
||||
[[email:invitation.text1, {username}, {site_title}]]
|
||||
|
||||
[[email:invitation.ctr]]
|
||||
|
||||
{registerLink}
|
||||
|
||||
[[email:closing]]
|
||||
{site_title}
|
||||
|
Loading…
Reference in New Issue