Merge branch 'master' of github.com:psychobunny/node-forum

v1.18.x
Julian Lam 12 years ago
commit 97f87ee003

@ -118,7 +118,8 @@ var ajaxify = {};
}
head.insertBefore(script, head.firstChild);
head.removeChild(script);
//TODO: remove from head before inserting?, doing this breaks scripts in safari so commented out for now
//head.removeChild(script);
};
var scripts = [],

@ -0,0 +1,104 @@
(function() {
jQuery('document').ready(function() {
var yourid = templates.get('yourid');
var url = window.location.href,
parts = url.split('/'),
active = parts[parts.length-1];
jQuery('.nav-pills li').removeClass('active');
jQuery('.nav-pills li a').each(function() {
if (this.getAttribute('href').match(active)) {
jQuery(this.parentNode).addClass('active');
return false;
}
});
jQuery('#search-user').on('keyup', function () {
console.log('derp');
jQuery('.icon-spinner').removeClass('none');
console.log($('#search-user').val());
socket.emit('api:admin.user.search', $('#search-user').val());
});
function isUserAdmin(element) {
var parent = $(element).parents('.users-box');
return (parent.attr('data-admin') !== "0");
}
function getUID(element) {
var parent = $(element).parents('.users-box');
return parent.attr('data-uid');
}
jQuery('.admin-btn').each(function(index, element) {
var adminBtn = $(element);
var isAdmin = isUserAdmin(adminBtn);
if(isAdmin)
adminBtn.addClass('btn-success');
else
adminBtn.removeClass('btn-success');
});
jQuery('.delete-btn').each(function(index, element) {
var deleteBtn = $(element);
var isAdmin = isUserAdmin(deleteBtn);
if(isAdmin)
deleteBtn.addClass('disabled');
else
deleteBtn.show();
});
jQuery('.admin-btn').on('click', function() {
var adminBtn = $(this);
var isAdmin = isUserAdmin(adminBtn);
var parent = adminBtn.parents('.users-box');
var uid = getUID(adminBtn);
if(isAdmin) {
socket.emit('api:admin.user.removeAdmin', uid);
adminBtn.removeClass('btn-success');
parent.find('.delete-btn').removeClass('disabled');
parent.attr('data-admin', 0);
}
else {
bootbox.confirm('Do you really want to make "' + parent.attr('data-username') +'" an admin?', function(confirm) {
if(confirm) {
socket.emit('api:admin.user.makeAdmin', uid);
adminBtn.addClass('btn-success');
parent.find('.delete-btn').addClass('disabled');
parent.attr('data-admin', 1);
}
});
}
return false;
});
jQuery('.delete-btn').on('click', function() {
var deleteBtn = $(this);
var isAdmin = isUserAdmin(deleteBtn);
var parent = deleteBtn.parents('.users-box');
var uid = getUID(deleteBtn);
if(!isAdmin) {
bootbox.confirm('Do you really want to delete "' + parent.attr('data-username') +'"?', function(confirm) {
socket.emit('api:admin.user.deleteUser', uid);
});
}
return false;
});
});
}());

@ -132,6 +132,9 @@
socket.emit('api:notifications.hasFlag');
require(['mobileMenu'], function(mobileMenu) {
mobileMenu.init();
});

@ -1,3 +1,5 @@
(function() {
// Alternate Logins
var altLoginEl = document.querySelector('.alt-logins');
@ -12,7 +14,6 @@
}
});
$('#login').on('click', function() {
var loginData = {
@ -32,7 +33,9 @@
error : function(data, textStatus, jqXHR) {
$('#login-error-notify').show().delay(1000).fadeOut(250);
},
dataType: 'json'
dataType: 'json',
async: true,
timeout: 2000
});
return false;

@ -63,7 +63,7 @@
<li class="nav-header">NodeBB</li>
<li class='active'><a href='/admin/index'><i class='icon-home'></i> Home</a></li>
<li class=''><a href='/admin/categories'><i class='icon-folder-close-alt'></i> Categories</a></li>
<li class=''><a href='/admin/users'><i class='icon-user'></i> Users</a></li>
<li class=''><a href='/admin/users/latest'><i class='icon-user'></i> Users</a></li>
<li class=''><a href='/admin/topics'><i class='icon-book'></i> Topics</a></li>
<li class=''><a href='/admin/themes'><i class='icon-th'></i> Themes</a></li>
<li class=''><a href='/admin/settings'><i class='icon-cogs'></i> Settings</a></li>

@ -41,4 +41,9 @@
app.enter_room('admin');
socket.emit('api:get_all_rooms');
socket.on('api:admin.user.search', function(data) {
console.log(data);
});
</script>

@ -1,7 +1,7 @@
<h1>Users</h1>
<hr />
<ul class="nav nav-pills">
<li class='active'><a href='/admin/users'>Latest Users</a></li>
<li class='active'><a href='/admin/users/latest'>Latest Users</a></li>
<li class=''><a href='/admin/users/sort-posts'>Top Posters</a></li>
<li class=''><a href='/admin/users/sort-reputation'>Most Reputation</a></li>
<li class=''><a href='/admin/users/search'>Search</a></li>
@ -9,12 +9,12 @@
<div class="search {search_display} well">
<input type="text" placeholder="Enter a username to search" onkeypress="jQuery('.icon-spinner').removeClass('none');" /><br />
<input id="search-user" type="text" placeholder="Enter a username to search"/><br />
<i class="icon-spinner icon-spin none"></i>
</div>
<!-- BEGIN users -->
<div class="users-box well" data-uid="{users.uid}">
<div class="users-box well" data-uid="{users.uid}" data-admin="{users.administrator}" data-username="{users.username}">
<a href="/users/{users.userslug}">
<img src="{users.picture}" class="user-8080-picture"/>
</a>
@ -30,71 +30,16 @@
<i class='icon-pencil'></i>
</div>
<div>
<a href="#" class="btn admin-btn" data-admin="{users.administrator}" data-username="{users.username}">Admin</a>
<a href="#" class="btn admin-btn">Admin</a>
</div>
<br/>
<div>
<a href="#" class="btn delete-btn btn-danger">Delete</a>
</div>
</div>
<!-- END users -->
<input type="hidden" template-variable="yourid" value="{yourid}" />
<script type="text/javascript">
//DRY Failure. this needs to go into an ajaxify onready style fn. Currently is copy pasted into every single function so after ACP is off the ground fix asap
(function() {
jQuery('document').ready(function() {
var yourid = templates.get('yourid');
var url = window.location.href,
parts = url.split('/'),
active = parts[parts.length-1];
jQuery('.nav-pills li').removeClass('active');
jQuery('.nav-pills li a').each(function() {
if (this.getAttribute('href').match(active)) {
jQuery(this.parentNode).addClass('active');
return false;
}
});
jQuery('.admin-btn').each(function(index, element) {
var adminBtn = $(element);
var isAdmin = adminBtn.attr('data-admin') !== "0";
if(isAdmin)
adminBtn.addClass('btn-success');
else
adminBtn.removeClass('btn-success');
});
jQuery('.admin-btn').on('click', function() {
var adminBtn = $(this);
var isAdmin = adminBtn.attr('data-admin') !== "0";
var parent = adminBtn.parents('.users-box');
var uid = parent.attr('data-uid');
if(isAdmin) {
socket.emit('api:admin.user.removeAdmin', uid);
adminBtn.removeClass('btn-success');
adminBtn.attr('data-admin', 0);
}
else {
bootbox.confirm('Do you really want to make "' + adminBtn.attr('data-username') +'" an admin?', function(confirm) {
if(confirm) {
socket.emit('api:admin.user.makeAdmin', uid);
adminBtn.addClass('btn-success');
adminBtn.attr('data-admin', 1);
}
});
}
return false;
});
});
}());
</script>
<script type="text/javascript" src="../../src/forum/admin/users.js"></script>

@ -7,12 +7,12 @@
<strong>Failed Login Attempt</strong> <p></p>
</div>
<form>
<div>
<label>Username</label><input type="text" placeholder="Enter Username" name="username" id="username" /><br />
<label>Password</label><input type="password" placeholder="Enter Password" name="password" id="password" /><br />
<input type="hidden" name="_csrf" value="{token}" id="csrf-token" />
<button class="btn btn-primary" id="login" type="submit">Login</button> &nbsp; <a href="/reset">Forgot Password?</a>
</form>
</div>
<span id="login-error-notify" class="label label-important hide">Invalid username/password</span><br/>
</div>

@ -35,5 +35,25 @@ var RDB = require('./../redis.js'),
});
};
UserAdmin.deleteUser = function(uid, theirid, socket) {
user.isAdministrator(uid, function(amIAdmin) {
user.isAdministrator(theirid, function(areTheyAdmin){
if(amIAdmin && !areTheyAdmin) {
user.delete(theirid, function(data) {
socket.emit('event:alert', {
title: 'User Deleted',
message: 'This user is deleted!',
type: 'success',
timeout: 2000
});
});
}
});
});
};
}(exports));

@ -40,7 +40,32 @@ var user = require('./../user.js'),
case 'users' :
if (req.params.tab == 'search') {
res.json({search_display: 'block', users: []});
} else {
}
else if(req.params.tab == 'latest') {
user.getUserList(function(data) {
data = data.sort(function(a, b) {
return b.joindate - a.joindate;
});
res.json({search_display: 'none', users:data, yourid:req.user.uid});
});
}
else if(req.params.tab == 'sort-posts') {
user.getUserList(function(data) {
data = data.sort(function(a, b) {
return b.postcount - a.postcount;
});
res.json({search_display: 'none', users:data, yourid:req.user.uid});
});
}
else if(req.params.tab == 'sort-reputation') {
user.getUserList(function(data) {
data = data.sort(function(a, b) {
return b.reputation - a.reputation;
});
res.json({search_display: 'none', users:data, yourid:req.user.uid});
});
}
else {
user.getUserList(function(data) {
res.json({search_display: 'none', users:data, yourid:req.user.uid});
});

@ -253,6 +253,30 @@ var utils = require('./../public/src/utils.js'),
});
}
User.search = function(username, callback) {
console.log('searching '+username);
RDB.keys('username:'+ username + '*:uid', function(err, keys) {
if(err === null) {
//console.log(data);
/*var keys = [];
for(var i=0, ii=data.length; i<ii; ++i) {
keys.push('')
}*/
RDB.mget(keys, function(err, uids) {
console.log(uids);
User.getDataForUsers(uids, function(userdata) {
callback(userdata);
});
});
}
else
console.log(err);
});
}
User.sendConfirmationEmail = function (email) {
if (global.config['email:host'] && global.config['email:port'] && global.config['email:from']) {
var confirm_code = utils.generateUUID(),

@ -441,6 +441,20 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
admin.user.removeAdmin(uid, theirid, socket);
}
});
socket.on('api:admin.user.deleteUser', function(theirid) {
if(uid && uid > 0) {
admin.user.deleteUser(uid, theirid, socket);
}
});
socket.on('api:admin.user.search', function(username) {
if(uid && uid > 0) {
user.search(username, function(data) {
socket.emit('api:admin.user.search', data);
});
}
});
});
}(SocketIO));

Loading…
Cancel
Save