mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-08-05 09:21:30 +02:00
* ButtonView is now MCI BT. BN is pre-defined "Board Name"
* Client current theme info loaded & used for e.g. passwordChar * Code cleanup
This commit is contained in:
parent
5eee568586
commit
586f3d60b3
16 changed files with 169 additions and 114 deletions
25
core/bbs.js
25
core/bbs.js
|
@ -12,6 +12,7 @@ var iconv = require('iconv-lite');
|
|||
var paths = require('path');
|
||||
var async = require('async');
|
||||
var util = require('util');
|
||||
var async = require('async');
|
||||
|
||||
exports.bbsMain = bbsMain;
|
||||
|
||||
|
@ -194,10 +195,26 @@ function prepareClient(client, cb) {
|
|||
// :TODO: it feels like this should go somewhere else... and be a bit more elegant.
|
||||
if('*' === conf.config.preLoginTheme) {
|
||||
var theme = require('./theme.js');
|
||||
theme.getRandomTheme(function onRandTheme(err, themeId) {
|
||||
client.user.properties.art_theme_id = themeId || '';
|
||||
cb(null);
|
||||
});
|
||||
|
||||
async.waterfall(
|
||||
[
|
||||
function getRandTheme(callback) {
|
||||
theme.getRandomTheme(function randTheme(err, themeId) {
|
||||
client.user.properties.art_theme_id = themeId || '';
|
||||
callback(null);
|
||||
});
|
||||
},
|
||||
function setCurrentThemeInfo(callback) {
|
||||
theme.getThemeInfo(client.user.properties.art_theme_id, function themeInfo(err, info) {
|
||||
client.currentThemeInfo = info;
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
cb(err);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
client.user.properties.art_theme_id = conf.config.preLoginTheme;
|
||||
cb(null);
|
||||
|
|
|
@ -224,6 +224,10 @@ Client.prototype.gotoMenuModule = function(options, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Client.prototype.fallbackMenuModule = function(cb) {
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Default error handlers
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -31,6 +31,8 @@ module.exports = {
|
|||
usernameMin : 2,
|
||||
usernameMax : 22,
|
||||
passwordMin : 6,
|
||||
requireActivation : true, // require SysOp activation?
|
||||
defaultTheme : 'NU-MAYA',
|
||||
},
|
||||
|
||||
paths : {
|
||||
|
|
|
@ -86,7 +86,6 @@ function connectEntry(client) {
|
|||
term.write(ansi.clearScreen());
|
||||
|
||||
client.gotoMenuModule({ name : Config.entryMod } );
|
||||
//moduleUtil.goto(Config.entryMod, client);
|
||||
}, timeout);
|
||||
});
|
||||
}, 500);
|
||||
|
|
|
@ -7,7 +7,11 @@ var ButtonView = require('./button_view.js').ButtonView;
|
|||
var VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView;
|
||||
var Config = require('./config.js').config;
|
||||
var packageJson = require('../package.json');
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var os = require('os');
|
||||
var _ = require('lodash');
|
||||
|
||||
exports.MCIViewFactory = MCIViewFactory;
|
||||
|
||||
|
@ -15,12 +19,30 @@ function MCIViewFactory(client) {
|
|||
this.client = client;
|
||||
}
|
||||
|
||||
MCIViewFactory.prototype.getPredefinedViewLabel = function(name) {
|
||||
MCIViewFactory.prototype.getPredefinedViewLabel = function(code) {
|
||||
var label;
|
||||
switch(name) {
|
||||
switch(code) {
|
||||
// :TODO: Fix conflict with ButtonView (BN); chagne to BT
|
||||
case 'BN' : label = Config.bbsName; break;
|
||||
case 'VL' : label = 'ENiGMA½ v' + packageJson.version; break;
|
||||
case 'VN' : label = packageJson.version; break;
|
||||
|
||||
case 'UN' : label = this.client.user.username; break;
|
||||
case 'UR' : label = this.client.user.properties.real_name; break;
|
||||
case 'LO' : label = this.client.user.properties.location; break;
|
||||
|
||||
case 'OS' :
|
||||
switch(os.platform()) {
|
||||
case 'linux' : label = 'Linux'; break;
|
||||
case 'darwin' : label = 'OS X'; break;
|
||||
case 'win32' : label = 'Windows'; break;
|
||||
case 'sunos' : label = 'SunOS'; break;
|
||||
default : label = os.type(); break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'OA' : label = os.arch(); break;
|
||||
case 'SC' : label = os.cpus()[0].model; break;
|
||||
}
|
||||
|
||||
return label;
|
||||
|
@ -56,6 +78,7 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
|||
}
|
||||
|
||||
switch(mci.code) {
|
||||
// Text Label (Text View)
|
||||
case 'TL' :
|
||||
setOption(0, 'textStyle');
|
||||
setOption(1, 'justify');
|
||||
|
@ -67,6 +90,7 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
|||
view = new TextView(options);
|
||||
break;
|
||||
|
||||
// Edit Text
|
||||
case 'ET' :
|
||||
if(setOption(0, 'maxLength')) {
|
||||
options.maxLength = parseInt(options.maxLength, 10);
|
||||
|
@ -75,11 +99,29 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
|||
|
||||
setOption(1, 'textStyle');
|
||||
|
||||
if(options.textStyle === 'P') {
|
||||
// Supply from theme, if available
|
||||
// :TODO: Move this logic elsewhere
|
||||
if(this.client.currentThemeInfo && this.client.currentThemeInfo.config) {
|
||||
var themePwChar = this.client.currentThemeInfo.config.passwordChar;
|
||||
if(_.isString(themePwChar)) {
|
||||
options.textMaskChar = themePwChar.substr(0, 1);
|
||||
} else if(_.isNumber(themePwChar)) {
|
||||
options.textMaskChar = String.fromCharCode(themePwChar);
|
||||
} else {
|
||||
options.textMaskChar = '*';
|
||||
}
|
||||
} else {
|
||||
options.textMaskChar = '*';
|
||||
}
|
||||
}
|
||||
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
|
||||
view = new EditTextView(options);
|
||||
break;
|
||||
|
||||
// Pre-defined Label (Text View)
|
||||
case 'PL' :
|
||||
if(mci.args.length > 0) {
|
||||
options.text = this.getPredefinedViewLabel(mci.args[0]);
|
||||
|
@ -97,7 +139,8 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
|||
}
|
||||
break;
|
||||
|
||||
case 'BN' :
|
||||
// Button
|
||||
case 'BT' :
|
||||
if(mci.args.length > 0) {
|
||||
options.dimens = { width : parseInt(mci.args[0], 10) };
|
||||
}
|
||||
|
@ -110,6 +153,7 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
|||
view = new ButtonView(options);
|
||||
break;
|
||||
|
||||
// Vertial Menu
|
||||
case 'VM' :
|
||||
setOption(0, 'itemSpacing');
|
||||
setOption(1, 'justify');
|
||||
|
@ -119,6 +163,13 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
|||
|
||||
view = new VerticalMenuView(options);
|
||||
break;
|
||||
|
||||
default :
|
||||
options.text = this.getPredefinedViewLabel(mci.code);
|
||||
if(options.text) {
|
||||
view = new TextView(options);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return view;
|
||||
|
|
|
@ -27,7 +27,7 @@ function MenuModule(options) {
|
|||
self.beforeArt();
|
||||
callback(null);
|
||||
},
|
||||
function displayArt(callback) {
|
||||
function displayArt(callback) {
|
||||
theme.displayThemeArt(self.menuConfig.art, self.client, function onArt(err, mciMap) {
|
||||
// :TODO: If the art simply is not found, or failed to load... we need to continue
|
||||
if(err) {
|
||||
|
|
|
@ -60,7 +60,7 @@ function TextView(options) {
|
|||
this.setText(options.text || '');
|
||||
|
||||
if(this.isPasswordTextStyle) {
|
||||
this.textMaskChar = miscUtil.valueWithDefault(this.textMaskChar, '*').substr(0, 1);
|
||||
this.textMaskChar = miscUtil.valueWithDefault(options.textMaskChar, '*').substr(0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,11 @@ var Config = require('./config.js').config;
|
|||
var art = require('./art.js');
|
||||
var miscUtil = require('./misc_util.js');
|
||||
var Log = require('./logger.js').log;
|
||||
|
||||
var fs = require('fs');
|
||||
var paths = require('path');
|
||||
var async = require('async');
|
||||
var _ = require('lodash');
|
||||
|
||||
exports.getThemeInfo = getThemeInfo;
|
||||
exports.getThemeArt = getThemeArt;
|
||||
|
@ -23,6 +25,7 @@ function getThemeInfo(themeID, cb) {
|
|||
cb(err);
|
||||
} else {
|
||||
try {
|
||||
// :TODO: strip comments/etc. ala menu.json
|
||||
var info = JSON.parse(data);
|
||||
cb(null, info);
|
||||
} catch(e) {
|
||||
|
@ -85,7 +88,7 @@ function getRandomTheme(cb) {
|
|||
|
||||
function getThemeArt(name, themeID, options, cb) {
|
||||
// allow options to be optional
|
||||
if(typeof cb === 'undefined') {
|
||||
if(_.isUndefined(cb)) {
|
||||
cb = options;
|
||||
options = {};
|
||||
}
|
||||
|
|
17
core/user.js
17
core/user.js
|
@ -2,6 +2,8 @@
|
|||
'use strict';
|
||||
|
||||
var userDb = require('./database.js').dbs.user;
|
||||
var Config = require('./config.js').config;
|
||||
|
||||
var crypto = require('crypto');
|
||||
var assert = require('assert');
|
||||
var async = require('async');
|
||||
|
@ -55,6 +57,12 @@ User.StandardPropertyGroups = {
|
|||
password : [ 'pw_pbkdf2_salt', 'pw_pbkdf2_dk' ],
|
||||
};
|
||||
|
||||
User.AccountStatus = {
|
||||
disabled : -1,
|
||||
inactive : 0,
|
||||
active : 1,
|
||||
};
|
||||
|
||||
User.prototype.authenticate = function(username, password, cb) {
|
||||
var self = this;
|
||||
|
||||
|
@ -154,6 +162,9 @@ User.prototype.create = function(options, cb) {
|
|||
|
||||
var self = this;
|
||||
|
||||
// :TODO: set various defaults, e.g. default activation status, etc.
|
||||
self.properties.account_status = Config.users.requireActivation ? User.AccountStatus.inactive : User.AccountStatus.active;
|
||||
|
||||
async.series(
|
||||
[
|
||||
function beginTransaction(callback) {
|
||||
|
@ -171,6 +182,12 @@ User.prototype.create = function(options, cb) {
|
|||
callback(err);
|
||||
} else {
|
||||
self.userId = this.lastID;
|
||||
|
||||
// Do not SGRValuesre activation for userId 1 (root/admin)
|
||||
if(1 === self.userId) {
|
||||
self.properties.account_status = User.AccountStatus.active;
|
||||
}
|
||||
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue