* New @systemMethod
This commit is contained in:
parent
ec5f1836c5
commit
5ab89f952f
|
@ -13,6 +13,7 @@ var ALL_ASSETS = [
|
|||
'art',
|
||||
'menu',
|
||||
'method',
|
||||
'systemMethod',
|
||||
'prompt',
|
||||
];
|
||||
|
||||
|
|
25
core/bbs.js
25
core/bbs.js
|
@ -209,25 +209,12 @@ function prepareClient(client, cb) {
|
|||
if('*' === conf.config.preLoginTheme) {
|
||||
var theme = require('./theme.js');
|
||||
|
||||
async.waterfall(
|
||||
[
|
||||
function getRandTheme(callback) {
|
||||
theme.getRandomTheme(function randTheme(err, themeId) {
|
||||
client.user.properties.theme_id = themeId || '';
|
||||
callback(null);
|
||||
});
|
||||
},
|
||||
function setCurrentThemeInfo(callback) {
|
||||
theme.getThemeInfo(client.user.properties.theme_id, function themeInfo(err, info) {
|
||||
client.currentThemeInfo = info;
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
cb(err);
|
||||
}
|
||||
);
|
||||
client.user.properties.theme_id = theme.getRandomTheme() || '';
|
||||
|
||||
theme.getThemeInfo(client.user.properties.theme_id, function themeInfo(err, info) {
|
||||
client.currentThemeInfo = info;
|
||||
cb(null);
|
||||
});
|
||||
} else {
|
||||
client.user.properties.theme_id = conf.config.preLoginTheme;
|
||||
cb(null);
|
||||
|
|
|
@ -168,28 +168,33 @@ function handleAction(client, formData, conf) {
|
|||
var actionAsset = asset.parseAsset(conf.action);
|
||||
assert(_.isObject(actionAsset));
|
||||
|
||||
function callModuleMenuMethod(path) {
|
||||
if('' === paths.extname(path)) {
|
||||
path += '.js';
|
||||
}
|
||||
|
||||
try {
|
||||
var methodMod = require(path);
|
||||
methodMod[actionAsset.asset](client.currentMenuModule, formData, conf.extraArgs);
|
||||
} catch(e) {
|
||||
Log.error( { error : e.toString(), methodName : actionAsset.asset }, 'Failed to execute asset method');
|
||||
}
|
||||
}
|
||||
|
||||
switch(actionAsset.type) {
|
||||
case 'method' :
|
||||
case 'systemMethod' :
|
||||
if(_.isString(actionAsset.location)) {
|
||||
try {
|
||||
// allow ".js" omission
|
||||
if(''=== paths.extname(actionAsset.location)) {
|
||||
actionAsset.location += '.js';
|
||||
}
|
||||
|
||||
var methodMod = require(paths.join(Config.paths.mods, actionAsset.location));
|
||||
|
||||
if(_.isFunction(methodMod[actionAsset.asset])) {
|
||||
methodMod[actionAsset.asset](client.currentMenuModule, formData, conf.extraArgs);
|
||||
}
|
||||
} catch(e) {
|
||||
Log.error( { error : e, methodName : actionAsset.asset }, 'Failed to execute asset method');
|
||||
}
|
||||
callModuleMenuMethod(paths.join(Config.paths.mods, actionAsset.location));
|
||||
} else {
|
||||
// local to current module
|
||||
var currentModule = client.currentMenuModule;
|
||||
if(_.isFunction(currentModule.menuMethods[actionAsset.asset])) {
|
||||
currentModule.menuMethods[actionAsset.asset](formData, conf.extraArgs);
|
||||
if('systemMethod' === actionAsset.type) {
|
||||
callModuleMenuMethod(paths.join(__dirname, 'system_menu_method.js'));
|
||||
} else {
|
||||
// local to current module
|
||||
var currentModule = client.currentMenuModule;
|
||||
if(_.isFunction(currentModule.menuMethods[actionAsset.asset])) {
|
||||
currentModule.menuMethods[actionAsset.asset](formData, conf.extraArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var theme = require('../core/theme.js');
|
||||
var Log = require('../core/logger.js').log;
|
||||
var ansi = require('../core/ansi_term.js');
|
||||
|
||||
var async = require('async');
|
||||
|
||||
exports.login = login;
|
||||
exports.logoff = logoff;
|
||||
|
||||
function login(callingMenu, formData, extraArgs) {
|
||||
var client = callingMenu.client;
|
||||
|
||||
client.user.authenticate(formData.value.username, formData.value.password, function authenticated(err) {
|
||||
if(err) {
|
||||
Log.info( { username : formData.value.username }, 'Failed login attempt %s', err);
|
||||
|
||||
client.gotoMenuModule( { name : callingMenu.menuConfig.fallback } );
|
||||
} else {
|
||||
// use client.user so we can get correct case
|
||||
Log.info( { username : callingMenu.client.user.username }, 'Successful login');
|
||||
|
||||
async.parallel(
|
||||
[
|
||||
function loadThemeConfig(callback) {
|
||||
theme.getThemeInfo(client.user.properties.theme_id, function themeInfo(err, info) {
|
||||
client.currentThemeInfo = info;
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
],
|
||||
function complete(err, results) {
|
||||
client.gotoMenuModule( { name : callingMenu.menuConfig.next } );
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function logoff(callingMenu, formData, extraArgs) {
|
||||
var client = callingMenu.client;
|
||||
|
||||
// :TODO: record this.
|
||||
|
||||
setTimeout(function timeout() {
|
||||
client.term.write(ansi.normal() + '\nATH0\n');
|
||||
client.end();
|
||||
}, 500);
|
||||
}
|
|
@ -94,6 +94,14 @@ function initAvailableThemes(cb) {
|
|||
);
|
||||
}
|
||||
|
||||
function getRandomTheme() {
|
||||
if(Object.getOwnPropertyNames(availableThemes).length > 0) {
|
||||
var themeIds = Object.keys(availableThemes);
|
||||
return themeIds[Math.floor(Math.random() * themeIds.length)];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
function getRandomTheme(cb) {
|
||||
if(Object.getOwnPropertyNames(availableThemes).length > 0) {
|
||||
var themeIds = Object.keys(availableThemes);
|
||||
|
@ -102,6 +110,7 @@ function getRandomTheme(cb) {
|
|||
cb(new Error('No themes available'));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
function getThemeArt(name, themeID, options, cb) {
|
||||
// allow options to be optional
|
||||
|
|
|
@ -87,13 +87,18 @@ function submitApplication(callingMenu, formData, extraArgs) {
|
|||
email_address : formData.value.email,
|
||||
web_address : formData.value.web,
|
||||
|
||||
theme_id : Config.defaults.theme, // :TODO: allow '*' = random
|
||||
account_status : Config.users.requireActivation ? user.User.AccountStatus.inactive : user.User.AccountStatus.active,
|
||||
|
||||
// :TODO: Other defaults
|
||||
// :TODO: should probably have a place to create defaults/etc.
|
||||
};
|
||||
|
||||
if('*' === Config.defaults.theme) {
|
||||
newUser.properties.theme_id = theme.getRandomTheme();
|
||||
} else {
|
||||
newUser.properties.theme_id = Config.defaults.theme;
|
||||
}
|
||||
|
||||
newUser.create( { password : formData.value.password }, function created(err) {
|
||||
if(err) {
|
||||
client.gotoMenuModule( { name : extraArgs.error } );
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
"prompt" : "userCredentials",
|
||||
"fallback" : "matrix",
|
||||
"next" : "newUserActive",
|
||||
"action" : "@method:general_menu_methods/login",
|
||||
"action" : "@systemMethod:login",
|
||||
|
||||
// :TODO: support alt submit method for prompts
|
||||
// if present, standard filters apply. No need for multiple submit ID's
|
||||
|
@ -90,7 +90,7 @@
|
|||
"logoff" : {
|
||||
"art" : "LOGOFF",
|
||||
//"module" : "logoff",
|
||||
"action" : "@method:general_menu_methods/logoff",
|
||||
"action" : "@systemMethod:logoff",
|
||||
"options" : { "cls" : true }
|
||||
},
|
||||
"apply" : {
|
||||
|
|
Loading…
Reference in New Issue