closes #1306
parent
de228fa67d
commit
57c2418157
@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
|
||||
/* global config, socket, define, templates, bootbox, app, ajaxify, */
|
||||
|
||||
define('admin/manage/registration', function() {
|
||||
var Registration = {};
|
||||
|
||||
Registration.init = function() {
|
||||
|
||||
$('.users-list').on('click', '[data-action]', function(ev) {
|
||||
var $this = this;
|
||||
var parent = $(this).parents('[data-username]');
|
||||
var action = $(this).attr('data-action');
|
||||
var username = parent.attr('data-username');
|
||||
var method = action === 'accept' ? 'admin.user.acceptRegistration' : 'admin.user.rejectRegistration';
|
||||
|
||||
socket.emit(method, {username: username}, function(err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
parent.remove();
|
||||
});
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
return Registration;
|
||||
});
|
@ -0,0 +1,139 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
nconf = require('nconf'),
|
||||
db = require('./../database'),
|
||||
meta = require('../meta'),
|
||||
emailer = require('../emailer'),
|
||||
notifications = require('../notifications'),
|
||||
translator = require('../../public/src/modules/translator'),
|
||||
utils = require('../../public/src/utils');
|
||||
|
||||
|
||||
module.exports = function(User) {
|
||||
|
||||
User.addToApprovalQueue = function(userData, callback) {
|
||||
userData.userslug = utils.slugify(userData.username);
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
User.isDataValid(userData, next);
|
||||
},
|
||||
function(next) {
|
||||
User.hashPassword(userData.password, next);
|
||||
},
|
||||
function(hashedPassword, next) {
|
||||
var data = {
|
||||
username: userData.username,
|
||||
email: userData.email,
|
||||
ip: userData.ip,
|
||||
hashedPassword: hashedPassword
|
||||
};
|
||||
|
||||
db.setObject('registration:queue:name:' + userData.username, data, next);
|
||||
},
|
||||
function(next) {
|
||||
db.sortedSetAdd('registration:queue', Date.now(), userData.username, next);
|
||||
},
|
||||
function(next) {
|
||||
sendNotificationToAdmins(userData.username, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
function sendNotificationToAdmins(username, callback) {
|
||||
notifications.create({
|
||||
bodyShort: '[[notifications:new_register, ' + username + ']]',
|
||||
nid: 'new_register' + username,
|
||||
path: '/admin/manage/users/registration'
|
||||
}, function(err, notification) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (notification) {
|
||||
notifications.pushGroup(notification, 'administrators', callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
User.acceptRegistration = function(username, callback) {
|
||||
var uid;
|
||||
var userData;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.getObject('registration:queue:name:' + username, next);
|
||||
},
|
||||
function(_userData, next) {
|
||||
if (!_userData) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
userData = _userData;
|
||||
User.create(userData, next);
|
||||
},
|
||||
function(_uid, next) {
|
||||
uid = _uid;
|
||||
User.setUserField(uid, 'password', userData.hashedPassword, next);
|
||||
},
|
||||
function(next) {
|
||||
var title = meta.config.title || meta.config.browserTitle || 'NodeBB';
|
||||
translator.translate('[[email:welcome-to, ' + title + ']]', meta.config.defaultLang, function(subject) {
|
||||
var data = {
|
||||
site_title: title,
|
||||
username: username,
|
||||
subject: subject,
|
||||
template: 'registration_accepted',
|
||||
uid: uid
|
||||
};
|
||||
|
||||
emailer.send('registration_accepted', uid, data, next);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
User.notifications.sendWelcomeNotification(uid, next);
|
||||
},
|
||||
function(next) {
|
||||
removeFromQueue(username, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
User.rejectRegistration = function(username, callback) {
|
||||
removeFromQueue(username, callback);
|
||||
};
|
||||
|
||||
function removeFromQueue(username, callback) {
|
||||
async.parallel([
|
||||
async.apply(db.sortedSetRemove, 'registration:queue', username),
|
||||
async.apply(db.delete, 'registration:queue:name:' + username)
|
||||
], callback);
|
||||
}
|
||||
|
||||
User.getRegistrationQueue = function(start, stop, callback) {
|
||||
var data;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.getSortedSetRevRangeWithScores('registration:queue', start, stop, next);
|
||||
},
|
||||
function(_data, next) {
|
||||
data = _data;
|
||||
var keys = data.filter(Boolean).map(function(user) {
|
||||
return 'registration:queue:name:' + user.value;
|
||||
});
|
||||
db.getObjects(keys, next);
|
||||
},
|
||||
function(users, next) {
|
||||
users.forEach(function(user, index) {
|
||||
if (user) {
|
||||
user.timestamp = utils.toISOString(data[index].score);
|
||||
}
|
||||
});
|
||||
|
||||
next(null, users);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
|
||||
};
|
@ -0,0 +1,40 @@
|
||||
<div class="registration">
|
||||
<div class="col-lg-9">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading"><i class="fa fa-group"></i> Registration Queue</div>
|
||||
<div class="panel-body">
|
||||
<table class="table table-striped users-list">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>IP</th>
|
||||
<th>Time</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<!-- BEGIN users -->
|
||||
<tr data-username="{users.username}">
|
||||
<td>
|
||||
{users.username}
|
||||
</td>
|
||||
<td>
|
||||
{users.email}
|
||||
</td>
|
||||
<td>
|
||||
{users.ip}
|
||||
</td>
|
||||
<td>
|
||||
<span class="timeago" title="{users.timestamp}"></span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group pull-right">
|
||||
<button class="btn btn-success btn-xs" data-action="accept"><i class="fa fa-check"></i></button>
|
||||
<button class="btn btn-danger btn-xs" data-action="delete"><i class="fa fa-times"></i></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- END users -->
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,12 @@
|
||||
<p>[[email:greeting_with_name, {username}]],</p>
|
||||
|
||||
<p>
|
||||
<strong>[[email:welcome.text1, {site_title}]]</strong>
|
||||
</p>
|
||||
|
||||
<p>[[email:welcome.text3]]</p>
|
||||
|
||||
<p>
|
||||
[[email:closing]]<br />
|
||||
<strong>{site_title}</strong>
|
||||
</p>
|
@ -0,0 +1,9 @@
|
||||
[[email:greeting_with_name, {username}]],
|
||||
|
||||
[[email:welcome.text1, {site_title}]]
|
||||
|
||||
[[email:welcome.text3]]
|
||||
|
||||
|
||||
[[email:closing]]
|
||||
{site_title}
|
Loading…
Reference in New Issue