* Rework user.js and User object to ES6
* Update download stats for user when web download is completed
This commit is contained in:
parent
6406d32165
commit
058ff3f367
|
@ -196,19 +196,18 @@ function initialize(cb) {
|
||||||
// * We do this every time as the op is free to change this information just
|
// * We do this every time as the op is free to change this information just
|
||||||
// like any other user
|
// like any other user
|
||||||
//
|
//
|
||||||
const user = require('./user.js');
|
const User = require('./user.js');
|
||||||
|
|
||||||
async.waterfall(
|
async.waterfall(
|
||||||
[
|
[
|
||||||
function getOpUserName(next) {
|
function getOpUserName(next) {
|
||||||
return user.getUserName(1, next);
|
return User.getUserName(1, next);
|
||||||
},
|
},
|
||||||
function getOpProps(opUserName, next) {
|
function getOpProps(opUserName, next) {
|
||||||
const propLoadOpts = {
|
const propLoadOpts = {
|
||||||
userId : 1,
|
|
||||||
names : [ 'real_name', 'sex', 'email_address', 'location', 'affiliation' ],
|
names : [ 'real_name', 'sex', 'email_address', 'location', 'affiliation' ],
|
||||||
};
|
};
|
||||||
user.loadProperties(propLoadOpts, (err, opProps) => {
|
User.loadProperties(User.RootUserID, propLoadOpts, (err, opProps) => {
|
||||||
return next(err, opUserName, opProps);
|
return next(err, opUserName, opProps);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
const term = require('./client_term.js');
|
const term = require('./client_term.js');
|
||||||
const ansi = require('./ansi_term.js');
|
const ansi = require('./ansi_term.js');
|
||||||
const user = require('./user.js');
|
const User = require('./user.js');
|
||||||
const Config = require('./config.js').config;
|
const Config = require('./config.js').config;
|
||||||
const MenuStack = require('./menu_stack.js');
|
const MenuStack = require('./menu_stack.js');
|
||||||
const ACS = require('./acs.js');
|
const ACS = require('./acs.js');
|
||||||
|
@ -77,7 +77,7 @@ function Client(input, output) {
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
this.user = new user.User();
|
this.user = new User();
|
||||||
this.currentTheme = { info : { name : 'N/A', description : 'None' } };
|
this.currentTheme = { info : { name : 'N/A', description : 'None' } };
|
||||||
this.lastKeyPressMs = Date.now();
|
this.lastKeyPressMs = Date.now();
|
||||||
this.menuStack = new MenuStack(this);
|
this.menuStack = new MenuStack(this);
|
||||||
|
|
|
@ -9,6 +9,10 @@ const FileEntry = require('./file_entry.js');
|
||||||
const getServer = require('./listening_server.js').getServer;
|
const getServer = require('./listening_server.js').getServer;
|
||||||
const Errors = require('./enig_error.js').Errors;
|
const Errors = require('./enig_error.js').Errors;
|
||||||
const ErrNotEnabled = require('./enig_error.js').ErrorReasons.NotEnabled;
|
const ErrNotEnabled = require('./enig_error.js').ErrorReasons.NotEnabled;
|
||||||
|
const StatLog = require('./stat_log.js');
|
||||||
|
const User = require('./user.js');
|
||||||
|
const Log = require('./logger.js').log;
|
||||||
|
const getConnectionByUserId = require('./client_connections.js').getConnectionByUserId;
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const hashids = require('hashids');
|
const hashids = require('hashids');
|
||||||
|
@ -277,7 +281,7 @@ class FileAreaWebAccess {
|
||||||
|
|
||||||
resp.on('finish', () => {
|
resp.on('finish', () => {
|
||||||
// transfer completed fully
|
// transfer completed fully
|
||||||
// :TODO: we need to update the users stats - bytes xferred, credit stuff, etc.
|
this.updateDownloadStatsForUserId(servedItem.userId, stats.size);
|
||||||
});
|
});
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
|
@ -293,6 +297,37 @@ class FileAreaWebAccess {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDownloadStatsForUserId(userId, dlBytes, cb) {
|
||||||
|
async.waterfall(
|
||||||
|
[
|
||||||
|
function fetchActiveUser(callback) {
|
||||||
|
const clientForUserId = getConnectionByUserId(userId);
|
||||||
|
if(clientForUserId) {
|
||||||
|
return callback(null, clientForUserId.user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// not online now - look 'em up
|
||||||
|
User.getUser(userId, (err, assocUser) => {
|
||||||
|
return callback(err, assocUser);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function updateStats(user, callback) {
|
||||||
|
StatLog.incrementUserStat(user, 'dl_total_count', 1);
|
||||||
|
StatLog.incrementUserStat(user, 'dl_total_bytes', dlBytes);
|
||||||
|
StatLog.incrementSystemStat('dl_total_count', 1);
|
||||||
|
StatLog.incrementSystemStat('dl_total_bytes', dlBytes);
|
||||||
|
|
||||||
|
return callback(null);
|
||||||
|
}
|
||||||
|
],
|
||||||
|
err => {
|
||||||
|
if(cb) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new FileAreaWebAccess();
|
module.exports = new FileAreaWebAccess();
|
|
@ -9,7 +9,7 @@ const theme = require('./theme.js');
|
||||||
const Message = require('./message.js');
|
const Message = require('./message.js');
|
||||||
const updateMessageAreaLastReadId = require('./message_area.js').updateMessageAreaLastReadId;
|
const updateMessageAreaLastReadId = require('./message_area.js').updateMessageAreaLastReadId;
|
||||||
const getMessageAreaByTag = require('./message_area.js').getMessageAreaByTag;
|
const getMessageAreaByTag = require('./message_area.js').getMessageAreaByTag;
|
||||||
const getUserIdAndName = require('./user.js').getUserIdAndName;
|
const User = require('./user.js');
|
||||||
const cleanControlCodes = require('./string_util.js').cleanControlCodes;
|
const cleanControlCodes = require('./string_util.js').cleanControlCodes;
|
||||||
const StatLog = require('./stat_log.js');
|
const StatLog = require('./stat_log.js');
|
||||||
const stringFormat = require('./string_format.js');
|
const stringFormat = require('./string_format.js');
|
||||||
|
@ -373,7 +373,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
|
||||||
callback(null);
|
callback(null);
|
||||||
} else {
|
} else {
|
||||||
// we need to look it up
|
// we need to look it up
|
||||||
getUserIdAndName(self.message.toUserName, function userInfo(err, toUserId) {
|
User.getUserIdAndName(self.message.toUserName, function userInfo(err, toUserId) {
|
||||||
if(err) {
|
if(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,7 +17,6 @@ global args:
|
||||||
where <command> is one of:
|
where <command> is one of:
|
||||||
user : user utilities
|
user : user utilities
|
||||||
config : config file management
|
config : config file management
|
||||||
file-base
|
|
||||||
fb : file base management
|
fb : file base management
|
||||||
|
|
||||||
`,
|
`,
|
||||||
|
@ -39,7 +38,7 @@ valid args:
|
||||||
--new : generate a new/initial configuration
|
--new : generate a new/initial configuration
|
||||||
`,
|
`,
|
||||||
FileBase :
|
FileBase :
|
||||||
`usage: oputil.js file-base <action> [<args>] [<action_specific>]
|
`usage: oputil.js fb <action> [<args>] [<action_specific>]
|
||||||
|
|
||||||
where <action> is one of:
|
where <action> is one of:
|
||||||
scan <args> AREA_TAG : (re)scan area specified by AREA_TAG for new files
|
scan <args> AREA_TAG : (re)scan area specified by AREA_TAG for new files
|
||||||
|
@ -47,6 +46,8 @@ where <action> is one of:
|
||||||
|
|
||||||
valid scan <args>:
|
valid scan <args>:
|
||||||
--tags TAG1,TAG2,... : specify tag(s) to assign to discovered entries
|
--tags TAG1,TAG2,... : specify tag(s) to assign to discovered entries
|
||||||
|
|
||||||
|
ARE_TAG can optionally contain @STORAGE_TAG; for example: retro_pc@bbs
|
||||||
`
|
`
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ module.exports = function() {
|
||||||
handleConfigCommand();
|
handleConfigCommand();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'file-base' :
|
|
||||||
case 'fb' :
|
case 'fb' :
|
||||||
handleFileBaseCommand();
|
handleFileBaseCommand();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7,8 +7,8 @@ const ExitCodes = require('./oputil_common.js').ExitCodes;
|
||||||
const argv = require('./oputil_common.js').argv;
|
const argv = require('./oputil_common.js').argv;
|
||||||
const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases;
|
const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases;
|
||||||
|
|
||||||
|
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
exports.handleUserCommand = handleUserCommand;
|
exports.handleUserCommand = handleUserCommand;
|
||||||
|
|
||||||
|
@ -55,13 +55,13 @@ function handleUserCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUser(userName, cb) {
|
function getUser(userName, cb) {
|
||||||
const user = require('./core/user.js');
|
const User = require('../../core/user.js');
|
||||||
user.getUserIdAndName(argv.user, function userNameAndId(err, userId) {
|
User.getUserIdAndName(argv.user, function userNameAndId(err, userId) {
|
||||||
if(err) {
|
if(err) {
|
||||||
process.exitCode = ExitCodes.BAD_ARGS;
|
process.exitCode = ExitCodes.BAD_ARGS;
|
||||||
return cb(new Error('Failed to retrieve user'));
|
return cb(new Error('Failed to retrieve user'));
|
||||||
} else {
|
} else {
|
||||||
let u = new user.User();
|
let u = new User();
|
||||||
u.userId = userId;
|
u.userId = userId;
|
||||||
return cb(null, u);
|
return cb(null, u);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ function setAccountStatus(userName, active) {
|
||||||
initAndGetUser(argv.user, callback);
|
initAndGetUser(argv.user, callback);
|
||||||
},
|
},
|
||||||
function activateUser(user, callback) {
|
function activateUser(user, callback) {
|
||||||
const AccountStatus = require('./core/user.js').User.AccountStatus;
|
const AccountStatus = require('../../core/user.js').AccountStatus;
|
||||||
user.persistProperty('account_status', active ? AccountStatus.active : AccountStatus.inactive, callback);
|
user.persistProperty('account_status', active ? AccountStatus.active : AccountStatus.inactive, callback);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
const user = require('./user.js');
|
const User = require('./user.js');
|
||||||
const Config = require('./config.js').config;
|
const Config = require('./config.js').config;
|
||||||
|
|
||||||
exports.validateNonEmpty = validateNonEmpty;
|
exports.validateNonEmpty = validateNonEmpty;
|
||||||
|
@ -38,7 +38,7 @@ function validateUserNameAvail(data, cb) {
|
||||||
} else if(/^[0-9]+$/.test(data)) {
|
} else if(/^[0-9]+$/.test(data)) {
|
||||||
return cb(new Error('Username cannot be a number'));
|
return cb(new Error('Username cannot be a number'));
|
||||||
} else {
|
} else {
|
||||||
user.getUserIdAndName(data, function userIdAndName(err) {
|
User.getUserIdAndName(data, function userIdAndName(err) {
|
||||||
if(!err) { // err is null if we succeeded -- meaning this user exists already
|
if(!err) { // err is null if we succeeded -- meaning this user exists already
|
||||||
return cb(new Error('Username unavailable'));
|
return cb(new Error('Username unavailable'));
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ function validateUserNameExists(data, cb) {
|
||||||
return cb(invalidUserNameError);
|
return cb(invalidUserNameError);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getUserIdAndName(data, (err) => {
|
User.getUserIdAndName(data, (err) => {
|
||||||
return cb(err ? invalidUserNameError : null);
|
return cb(err ? invalidUserNameError : null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ function validateEmailAvail(data, cb) {
|
||||||
return cb(new Error('Invalid email address'));
|
return cb(new Error('Invalid email address'));
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getUserIdsWithProperty('email_address', data, function userIdsWithEmail(err, uids) {
|
User.getUserIdsWithProperty('email_address', data, function userIdsWithEmail(err, uids) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return cb(new Error('Internal system error'));
|
return cb(new Error('Internal system error'));
|
||||||
} else if(uids.length > 0) {
|
} else if(uids.length > 0) {
|
||||||
|
|
973
core/user.js
973
core/user.js
File diff suppressed because it is too large
Load Diff
|
@ -7,7 +7,7 @@ const getModDatabasePath = require('../core/database.js').getModDatabasePath;
|
||||||
const ViewController = require('../core/view_controller.js').ViewController;
|
const ViewController = require('../core/view_controller.js').ViewController;
|
||||||
const ansi = require('../core/ansi_term.js');
|
const ansi = require('../core/ansi_term.js');
|
||||||
const theme = require('../core/theme.js');
|
const theme = require('../core/theme.js');
|
||||||
const getUserName = require('../core/user.js').getUserName;
|
const User = require('../core/user.js');
|
||||||
const stringFormat = require('../core/string_format.js');
|
const stringFormat = require('../core/string_format.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
|
@ -284,7 +284,7 @@ exports.getModule = class BBSListModule extends MenuModule {
|
||||||
},
|
},
|
||||||
function getUserNames(entriesView, callback) {
|
function getUserNames(entriesView, callback) {
|
||||||
async.each(self.entries, (entry, next) => {
|
async.each(self.entries, (entry, next) => {
|
||||||
getUserName(entry.submitterUserId, (err, username) => {
|
User.getUserName(entry.submitterUserId, (err, username) => {
|
||||||
if(username) {
|
if(username) {
|
||||||
entry.submitter = username;
|
entry.submitter = username;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,9 +5,7 @@
|
||||||
const MenuModule = require('../core/menu_module.js').MenuModule;
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
||||||
const ViewController = require('../core/view_controller.js').ViewController;
|
const ViewController = require('../core/view_controller.js').ViewController;
|
||||||
const StatLog = require('../core/stat_log.js');
|
const StatLog = require('../core/stat_log.js');
|
||||||
const getUserName = require('../core/user.js').getUserName;
|
const User = require('../core/user.js');
|
||||||
const loadProperties = require('../core/user.js').loadProperties;
|
|
||||||
const isRootUserId = require('../core/user.js').isRootUserId;
|
|
||||||
const stringFormat = require('../core/string_format.js');
|
const stringFormat = require('../core/string_format.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
|
@ -73,7 +71,7 @@ exports.getModule = class LastCallersModule extends MenuModule {
|
||||||
|
|
||||||
if(self.menuConfig.config.hideSysOpLogin) {
|
if(self.menuConfig.config.hideSysOpLogin) {
|
||||||
const noOpLoginHistory = loginHistory.filter(lh => {
|
const noOpLoginHistory = loginHistory.filter(lh => {
|
||||||
return false === isRootUserId(parseInt(lh.log_value)); // log_value=userId
|
return false === User.isRootUserId(parseInt(lh.log_value)); // log_value=userId
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -106,11 +104,10 @@ exports.getModule = class LastCallersModule extends MenuModule {
|
||||||
item.userId = parseInt(item.log_value);
|
item.userId = parseInt(item.log_value);
|
||||||
item.ts = moment(item.timestamp).format(dateTimeFormat);
|
item.ts = moment(item.timestamp).format(dateTimeFormat);
|
||||||
|
|
||||||
getUserName(item.userId, (err, userName) => {
|
User.getUserName(item.userId, (err, userName) => {
|
||||||
item.userName = userName;
|
item.userName = userName;
|
||||||
getPropOpts.userId = item.userId;
|
|
||||||
|
|
||||||
loadProperties(getPropOpts, (err, props) => {
|
User.loadProperties(item.userId, getPropOpts, (err, props) => {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
item.location = props.location;
|
item.location = props.location;
|
||||||
item.affiliation = item.affils = props.affiliation;
|
item.affiliation = item.affils = props.affiliation;
|
||||||
|
|
|
@ -2,13 +2,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule;
|
var FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule;
|
||||||
var Message = require('../core/message.js');
|
|
||||||
var messageArea = require('../core/message_area.js');
|
|
||||||
var user = require('../core/user.js');
|
|
||||||
|
|
||||||
var _ = require('lodash');
|
|
||||||
var async = require('async');
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
exports.getModule = AreaReplyFSEModule;
|
exports.getModule = AreaReplyFSEModule;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
const MenuModule = require('../core/menu_module.js').MenuModule;
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
||||||
const user = require('../core/user.js');
|
const User = require('../core/user.js');
|
||||||
const theme = require('../core/theme.js');
|
const theme = require('../core/theme.js');
|
||||||
const login = require('../core/system_menu_method.js').login;
|
const login = require('../core/system_menu_method.js').login;
|
||||||
const Config = require('../core/config.js').config;
|
const Config = require('../core/config.js').config;
|
||||||
|
@ -61,7 +61,7 @@ exports.getModule = class NewUserAppModule extends MenuModule {
|
||||||
// Submit handlers
|
// Submit handlers
|
||||||
//
|
//
|
||||||
submitApplication : function(formData, extraArgs, cb) {
|
submitApplication : function(formData, extraArgs, cb) {
|
||||||
const newUser = new user.User();
|
const newUser = new User();
|
||||||
|
|
||||||
newUser.username = formData.value.username;
|
newUser.username = formData.value.username;
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ exports.getModule = class NewUserAppModule extends MenuModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
// :TODO: User.create() should validate email uniqueness!
|
// :TODO: User.create() should validate email uniqueness!
|
||||||
newUser.create( { password : formData.value.password }, err => {
|
newUser.create(formData.value.password, err => {
|
||||||
if(err) {
|
if(err) {
|
||||||
self.client.log.info( { error : err, username : formData.value.username }, 'New user creation failed');
|
self.client.log.info( { error : err, username : formData.value.username }, 'New user creation failed');
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ exports.getModule = class NewUserAppModule extends MenuModule {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(user.User.AccountStatus.inactive === self.client.user.properties.account_status) {
|
if(User.AccountStatus.inactive === self.client.user.properties.account_status) {
|
||||||
return self.gotoMenu(extraArgs.inactive, cb);
|
return self.gotoMenu(extraArgs.inactive, cb);
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const MenuModule = require('../core/menu_module.js').MenuModule;
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
||||||
const getUserList = require('../core/user.js').getUserList;
|
const User = require('../core/user.js');
|
||||||
const ViewController = require('../core/view_controller.js').ViewController;
|
const ViewController = require('../core/view_controller.js').ViewController;
|
||||||
const stringFormat = require('../core/string_format.js');
|
const stringFormat = require('../core/string_format.js');
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ exports.getModule = class UserListModule extends MenuModule {
|
||||||
},
|
},
|
||||||
function fetchUserList(callback) {
|
function fetchUserList(callback) {
|
||||||
// :TODO: Currently fetching all users - probably always OK, but this could be paged
|
// :TODO: Currently fetching all users - probably always OK, but this could be paged
|
||||||
getUserList(USER_LIST_OPTS, function got(err, ul) {
|
User.getUserList(USER_LIST_OPTS, function got(err, ul) {
|
||||||
userList = ul;
|
userList = ul;
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue