v1.18.x
barisusakli 10 years ago
parent 6760ce00cc
commit f9405c0423

@ -215,18 +215,18 @@ define('admin/manage/users', ['admin/modules/selectable'], function(selectable)
}
});
$('#search-user').on('keyup', function() {
$('#search-user-name, #search-user-email').on('keyup', function() {
if (timeoutId !== 0) {
clearTimeout(timeoutId);
timeoutId = 0;
}
var $this = $(this);
var type = $this.attr('id') === 'search-user-name' ? 'username' : 'email';
timeoutId = setTimeout(function() {
var username = $('#search-user').val();
$('.fa-spinner').removeClass('hidden');
socket.emit('admin.user.search', username, function(err, data) {
socket.emit('admin.user.search', {type: type, query: $this.val()}, function(err, data) {
if (err) {
return app.alertError(err.message);
}

@ -36,7 +36,7 @@ Categories.search = function(socket, data, callback) {
var username = data.username,
cid = data.cid;
user.search(username, function(err, data) {
user.search(username, 'username', function(err, data) {
if (err) {
return callback(err);
}

@ -165,15 +165,15 @@ User.deleteUsers = function(socket, uids, callback) {
}, callback);
};
User.search = function(socket, username, callback) {
user.search(username, function(err, data) {
function isAdmin(userData, next) {
user.isAdministrator(userData.uid, function(err, isAdmin) {
if(err) {
User.search = function(socket, data, callback) {
user.search(data.query, data.type, function(err, data) {
function getEmail(userData, next) {
user.getUserField(userData.uid, 'email', function(err, email) {
if (err) {
return next(err);
}
userData.administrator = isAdmin;
userData.email = email;
next();
});
}
@ -182,7 +182,7 @@ User.search = function(socket, username, callback) {
return callback(err);
}
async.each(data.users, isAdmin, function(err) {
async.each(data.users, getEmail, function(err) {
callback(err, data);
});
});

@ -66,7 +66,7 @@ SocketUser.search = function(socket, username, callback) {
if (!socket.uid) {
return callback(new Error('[[error:not-logged-in]]'));
}
user.search(username, callback);
user.search(username, 'username', callback);
};
// Password Reset

@ -1,28 +1,34 @@
'use strict';
var db = require('./../database');
var db = require('../database');
module.exports = function(User) {
User.search = function(query, callback) {
User.search = function(query, type, callback) {
if (!query || query.length === 0) {
return callback(null, {timing:0, users:[]});
}
var start = process.hrtime();
db.getObject('username:uid', function(err, usernamesHash) {
var set = 'username:uid';
if (type === 'email') {
set = 'email:uid';
}
db.getObject(set, function(err, hash) {
if (err) {
return callback(null, {timing: 0, users:[]});
}
query = query.toLowerCase();
var usernames = Object.keys(usernamesHash);
var values = Object.keys(hash);
var uids = [];
for(var i=0; i<usernames.length; ++i) {
if (usernames[i].toLowerCase().indexOf(query) === 0) {
uids.push(usernames[i]);
for(var i=0; i<values.length; ++i) {
if (values[i].toLowerCase().indexOf(query) === 0) {
uids.push(values[i]);
}
}
@ -31,7 +37,7 @@ module.exports = function(User) {
return a > b;
})
.map(function(username) {
return usernamesHash[username];
return hash[username];
});
User.getUsers(uids, function(err, userdata) {

@ -32,9 +32,16 @@
<br />
<div class="search {search_display} well">
<input class="form-control" id="search-user" type="text" placeholder="Enter a username to search"/><br />
<label>By User Name</label>
<input class="form-control" id="search-user-name" type="text" placeholder="Enter a username to search"/><br />
<label>By Email </label>
<input class="form-control" id="search-user-email" type="text" placeholder="Enter a email to search"/><br />
<i class="fa fa-spinner fa-spin hidden"></i>
<span id="user-notfound-notify" class="label label-danger hide">User not found!</span><br/>
</div>
@ -54,7 +61,10 @@
</div>
</div>
<a href="{relative_path}/user/{users.userslug}" target="_blank">{users.username} ({users.uid})</a>
<a href="{relative_path}/user/{users.userslug}" target="_blank">{users.username} ({users.uid})</a><br/>
<!-- IF users.email -->
<small><span title="{users.email}">{users.email}</span></small>
<!-- ENDIF users.email -->
</div>
<!-- END users -->
</ul>

Loading…
Cancel
Save