diff --git a/core/acs_parser.js b/core/acs_parser.js index 8671f52b..874033db 100644 --- a/core/acs_parser.js +++ b/core/acs_parser.js @@ -792,6 +792,7 @@ module.exports = (function() { var user = options.client.user; var _ = require('lodash'); + var assert = require('assert'); function checkAccess(acsCode, value) { try { @@ -802,6 +803,18 @@ module.exports = (function() { AG : function ageGreaterOrEqualThan() { return !isNaN(value) && user.getAge() >= value; }, + AS : function accountStatus() { + + if(_.isNumber(value)) { + value = [ value ]; + } + + assert(_.isArray(value)); + + return _.findIndex(value, function cmp(accStatus) { + return parseInt(accStatus, 10) === parseInt(user.properties.account_status, 10); + }) > -1; + }, EC : function isEncoding() { switch(value) { case 0 : return 'cp437' === client.term.outputEncoding.toLowerCase(); @@ -814,13 +827,9 @@ module.exports = (function() { return false; } - value.forEach(function grpEntry(groupName) { - if(user.isGroupMember(groupName)) { - return true; - } - }); - - return false; + return _.findIndex(value, function cmp(groupName) { + return user.isGroupMember(groupName); + }) > - 1; }, NN : function isNode() { return client.node === value; diff --git a/core/acs_util.js b/core/acs_util.js index d3e82a50..effa64fa 100644 --- a/core/acs_util.js +++ b/core/acs_util.js @@ -14,11 +14,11 @@ function getConditionalValue(client, condArray, memberName) { assert(_.isArray(condArray)); assert(_.isString(memberName)); - console.log(condArray) - - condArray.forEach(function cond(c) { - if(acsParser.parse(c.acs, { client : client })) { - return c[memberName]; - } + var matchCond = _.find(condArray, function cmp(cond) { + return acsParser.parse(cond.acs, { client : client } ); }); + + if(matchCond) { + return matchCond[memberName]; + } } \ No newline at end of file diff --git a/core/menu_module.js b/core/menu_module.js index 2f3dcab9..0ea0d73a 100644 --- a/core/menu_module.js +++ b/core/menu_module.js @@ -146,7 +146,7 @@ function MenuModule(options) { this.autoNextMenu = function() { function goNext() { - if(_.isString(self.menuConfig.next)) { + if(_.isString(self.menuConfig.next) || _.isArray(self.menuConfig.next)) { menuUtil.handleNext(self.client, self.menuConfig.next); } else { self.prevMenu(); @@ -179,6 +179,10 @@ function MenuModule(options) { } } }; + + this.haveNext = function() { + return (_.isString(this.menuConfig.next) || _.isArray(this.menuConfig.next)); + }; } require('util').inherits(MenuModule, PluginModule); @@ -215,6 +219,14 @@ MenuModule.prototype.restoreSavedState = function(savedState) { }; MenuModule.prototype.nextMenu = function(cb) { + // + // If we don't actually have |next|, we'll go previous + // + if(!this.haveNext()) { + this.prevMenu(cb); + return; + } + // :TODO: this, prevMenu(), and gotoMenu() need a default |cb| handler if none is supplied. // ...if the error is that we do not meet ACS requirements and did not get a match, then what? if(!cb) { diff --git a/core/menu_stack.js b/core/menu_stack.js index d980b82d..dbf3c8d6 100644 --- a/core/menu_stack.js +++ b/core/menu_stack.js @@ -46,24 +46,10 @@ MenuStack.prototype.next = function(cb) { assert(currentModuleInfo, 'Empty menu stack!'); var menuConfig = currentModuleInfo.instance.menuConfig; - - /* - :TODO: next should allow for conditionals based on ACS - - next: [ - { acs: "GM[sysops]|U1", next: theNextMenu }, - ... - ] - - acsUtil.getAcsConditionMatch(cond, memberName) -> value | undefined - (memberName = "next") - */ - var next; if(_.isArray(menuConfig.next)) { next = acsUtil.getConditionalValue(this.client, menuConfig.next, 'next'); - console.log('conditional next: ' + next); if(!next) { cb(new Error('No matching condition for \'next\'!')); return; @@ -75,12 +61,12 @@ MenuStack.prototype.next = function(cb) { return; } - if(menuConfig.next === currentModuleInfo.name) { + if(next === currentModuleInfo.name) { cb(new Error('Menu config \'next\' specifies current menu!')); return; } - this.goto(menuConfig.next, { }, cb); + this.goto(next, { }, cb); }; MenuStack.prototype.prev = function(cb) { diff --git a/core/menu_util.js b/core/menu_util.js index 02a91841..58bbb24f 100644 --- a/core/menu_util.js +++ b/core/menu_util.js @@ -10,6 +10,7 @@ var asset = require('./asset.js'); var theme = require('./theme.js'); var configCache = require('./config_cache.js'); var MCIViewFactory = require('./mci_view_factory.js').MCIViewFactory; +var acsUtil = require('./acs_util.js'); var fs = require('fs'); var paths = require('path'); @@ -220,8 +221,12 @@ function handleAction(client, formData, conf) { } function handleNext(client, nextSpec, conf) { - assert(_.isString(nextSpec)); - + assert(_.isString(nextSpec) || _.isArray(nextSpec)); + + if(_.isArray(nextSpec)) { + nextSpec = acsUtil.getConditionalValue(client, nextSpec, 'next'); + } + var nextAsset = asset.getAssetWithShorthand(nextSpec, 'menu'); conf = conf || {}; diff --git a/core/user.js b/core/user.js index ea5246c8..73d3927e 100644 --- a/core/user.js +++ b/core/user.js @@ -85,9 +85,9 @@ User.StandardPropertyGroups = { }; User.AccountStatus = { - disabled : -1, - inactive : 0, - active : 1, + disabled : 0, + inactive : 1, + active : 2, }; User.prototype.load = function(userId, cb) { diff --git a/misc/acs_parser.pegjs b/misc/acs_parser.pegjs index f7451162..c97973d1 100644 --- a/misc/acs_parser.pegjs +++ b/misc/acs_parser.pegjs @@ -4,6 +4,7 @@ var user = options.client.user; var _ = require('lodash'); + var assert = require('assert'); function checkAccess(acsCode, value) { try { @@ -14,6 +15,18 @@ AG : function ageGreaterOrEqualThan() { return !isNaN(value) && user.getAge() >= value; }, + AS : function accountStatus() { + + if(_.isNumber(value)) { + value = [ value ]; + } + + assert(_.isArray(value)); + + return _.findIndex(value, function cmp(accStatus) { + return parseInt(accStatus, 10) === parseInt(user.properties.account_status, 10); + }) > -1; + }, EC : function isEncoding() { switch(value) { case 0 : return 'cp437' === client.term.outputEncoding.toLowerCase(); @@ -26,13 +39,9 @@ return false; } - value.forEach(function grpEntry(groupName) { - if(user.isGroupMember(groupName)) { - return true; - } - }); - - return false; + return _.findIndex(value, function cmp(groupName) { + return user.isGroupMember(groupName); + }) > - 1; }, NN : function isNode() { return client.node === value; diff --git a/mods/menu.hjson b/mods/menu.hjson index 8bb35190..689b9515 100644 --- a/mods/menu.hjson +++ b/mods/menu.hjson @@ -119,8 +119,6 @@ next: @systemMethod:logoff } /* - nua -> send sysop mail -> { active } -> matrix - -> you must active -> matrix TODO: display PRINT before this (Obv/2) or NEWUSER1 (Mystic) */ newUserApplication: { @@ -305,9 +303,16 @@ newUserFeedbackToSysOp: { status: Feedback to SysOp module: msg_area_post_fse - // :TODO: If the user is auto-approved, login seq. else, DONE.ANS -> Logoff - // :TODO: client.nextOrFallback(): go next or fallback. Use in MenuModule base also - fallback: fullLoginSequenceLoginArt + next: [ + { + acs: AS2 + next: fullLoginSequenceLoginArt + } + { + acs: !AS2 + next: newUserInactiveDone + } + ] config: { art: { header: MSGEHDR @@ -413,6 +418,13 @@ } } + newUserInactiveDone: { + desc: Finished with NUA + art: DONE + options: { pause: true } + next: @menu:logoff + } + fullLoginSequenceLoginArt: { desc: Logging In art: WELCOME @@ -448,12 +460,8 @@ prompt: menuCommand submit: [ { - "value" : { "command" : "G" }, - "action" : "@menu:logoff" - }, - { - "value" : { "command" : "O" }, - "action" : "@menu:doorPimpWars" + value: { command: "G" } + action: @menu:logoff } { value: { command: "D" } @@ -464,21 +472,17 @@ action: @menu:mainMenuUserList } { - value: { command: "E" } - action: @menu:doorTestExample + value: { command: "L" } + action: @menu:mainMenuLastCallers } { - "value" : { "command" : "L" }, - "action" : "@menu:mainMenuLastCallers" - }, + value: { command: "Y" } + action: @menu:mainMenuUserStats + } { - "value" : { "command" : "Y" }, - "action" : "@menu:mainMenuUserStats" - }, - { - "value" : { "command" : "M" }, - "action" : "@menu:messageArea" - }, + value: { command: "M" } + action: @menu:messageArea + } { value: { command: "C" } action: @menu:mainMenuUserConfig @@ -488,8 +492,8 @@ action: @menu:mainMenuSystemStats } { - "value" : 1, - "action" : "@menu:mainMenu" + value: 1 + action: @menu:mainMenu } ] } diff --git a/mods/msg_area_post_fse.js b/mods/msg_area_post_fse.js index 817dbbbd..d6034e51 100644 --- a/mods/msg_area_post_fse.js +++ b/mods/msg_area_post_fse.js @@ -48,7 +48,7 @@ function AreaPostFSEModule(options) { console.log(msg); } - self.prevMenu(); + self.nextMenu(); } ); };