* Tons of work with menu/prompts refactoring -- more to come soon
* More work with menu/prompt accets
This commit is contained in:
@@ -92,6 +92,12 @@ function ApplyModule(menuConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
var re = new RegExp(Config.users.usernamePattern);
|
||||
if(!re.test(args.username)) {
|
||||
cb('Handle contains invalid characters!', [ 1 ] );
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.pw.length < Config.users.passwordMin) {
|
||||
cb('Password too short!', [ 9, 10 ]);
|
||||
return;
|
||||
@@ -123,13 +129,13 @@ ApplyModule.prototype.beforeArt = function() {
|
||||
ApplyModule.super_.prototype.beforeArt.call(this);
|
||||
};
|
||||
|
||||
ApplyModule.prototype.mciReady = function(mciMap) {
|
||||
ApplyModule.super_.prototype.mciReady.call(this, mciMap);
|
||||
ApplyModule.prototype.mciReady = function(mciMaps) {
|
||||
ApplyModule.super_.prototype.mciReady.call(this, mciMaps);
|
||||
|
||||
var self = this;
|
||||
|
||||
self.viewController = self.addViewController(new ViewController({ client : self.client } ));
|
||||
self.viewController.loadFromMCIMapAndConfig( { mciMap : mciMap, menuConfig : self.menuConfig }, function onViewReady(err) {
|
||||
self.viewController.loadFromMCIMapAndConfig( { mciMap : mciMaps.menu, menuConfig : self.menuConfig }, function onViewReady(err) {
|
||||
|
||||
});
|
||||
};
|
||||
@@ -21,6 +21,37 @@ exports.moduleInfo = {
|
||||
|
||||
exports.getModule = LoginModule;
|
||||
|
||||
exports.attemptLogin = attemptLogin;
|
||||
|
||||
function attemptLogin(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.art_theme_id, function themeInfo(err, info) {
|
||||
client.currentThemeInfo = info;
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
],
|
||||
function complete(err, results) {
|
||||
client.gotoMenuModule( { name : callingMenu.menuConfig.next } );
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function LoginModule(menuConfig) {
|
||||
MenuModule.call(this, menuConfig);
|
||||
@@ -91,12 +122,12 @@ LoginModule.prototype.beforeArt = function() {
|
||||
//this.client.term.write(ansi.resetScreen());
|
||||
};
|
||||
|
||||
LoginModule.prototype.mciReady = function(mciMap) {
|
||||
LoginModule.super_.prototype.mciReady.call(this, mciMap);
|
||||
LoginModule.prototype.mciReady = function(mciData) {
|
||||
LoginModule.super_.prototype.mciReady.call(this, mciData);
|
||||
|
||||
var self = this;
|
||||
|
||||
self.viewController = self.addViewController(new ViewController( { client : self.client } ));
|
||||
self.viewController.loadFromMCIMapAndConfig( { mciMap : mciMap, menuConfig : self.menuConfig }, function onViewReady(err) {
|
||||
self.viewController.loadFromMCIMapAndConfig( { mciMap : mciData.menu, menuConfig : self.menuConfig }, function onViewReady(err) {
|
||||
});
|
||||
};
|
||||
@@ -28,8 +28,8 @@ LogOffModule.prototype.beforeArt = function() {
|
||||
this.client.term.write(ansi.resetScreen());
|
||||
};
|
||||
|
||||
LogOffModule.prototype.mciReady = function(mciMap) {
|
||||
LogOffModule.super_.prototype.mciReady.call(this, mciMap);
|
||||
LogOffModule.prototype.mciReady = function(mciData) {
|
||||
LogOffModule.super_.prototype.mciReady.call(this, mciData);
|
||||
};
|
||||
|
||||
LogOffModule.prototype.finishedLoading = function() {
|
||||
|
||||
@@ -38,8 +38,6 @@ MatrixModule.prototype.enter = function(client) {
|
||||
|
||||
MatrixModule.prototype.beforeArt = function() {
|
||||
MatrixModule.super_.prototype.beforeArt.call(this);
|
||||
|
||||
this.client.term.write(ansi.resetScreen());
|
||||
};
|
||||
|
||||
MatrixModule.prototype.mciReady = function(mciMap) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
// @method:scriptName[.js]/methodName (foreign .js)
|
||||
// @art:artName
|
||||
// @method:/methodName (local to module.js)
|
||||
// ... pass isFocused/etc. into draw method
|
||||
"draw" : {
|
||||
"normal" : ...,
|
||||
"focus" : ...
|
||||
@@ -20,10 +21,18 @@
|
||||
}
|
||||
}
|
||||
*/
|
||||
"connected" : {
|
||||
"art" : "connect",
|
||||
"next" : "matrix",
|
||||
"options" : {
|
||||
"clearScreen" : true,
|
||||
"nextTimeout" : 1500
|
||||
}
|
||||
},
|
||||
"matrix" : {
|
||||
"art" : "matrix",
|
||||
"form" : {
|
||||
"0" : {
|
||||
"0" : { // :TODO: Make form "0" the default if missing (e.g. optional)
|
||||
"VM1" : {
|
||||
"mci" : {
|
||||
"VM1" : {
|
||||
@@ -57,12 +66,18 @@
|
||||
}
|
||||
},
|
||||
"login" : {
|
||||
"art" : "login", // TODO: rename to login_form
|
||||
"module" : "login",
|
||||
//"art" : "login", // TODO: rename to login_form
|
||||
"prompt" : "userCredentials",
|
||||
"fallback" : "matrix",
|
||||
"next" : "newUserActive",
|
||||
//"module" : "login",
|
||||
/*
|
||||
"form" : {
|
||||
"0" : {
|
||||
"BT3BT4ET1ET2TL5" :{
|
||||
"mci" :{
|
||||
// :TODO: LIke prompts, assign "argName" values here, e.g.:
|
||||
// "argName" : "username", ...
|
||||
"ET1" : {
|
||||
"focus" : true
|
||||
},
|
||||
@@ -80,25 +95,30 @@
|
||||
{
|
||||
"value" : { "3" : null },
|
||||
"action" : "@method:attemptLogin",
|
||||
// :TODO: see above about argName;
|
||||
// any other args should be "extraArgs"
|
||||
"args" : {
|
||||
"next" : {
|
||||
// :TODO: just use menu.next
|
||||
"success" : "newUserActive"
|
||||
},
|
||||
"username" : "{1}",
|
||||
"password" : "{2}"
|
||||
} // :TODO: rename to actionArgs ?
|
||||
}
|
||||
}
|
||||
],
|
||||
"4" : [ // Cancel
|
||||
{
|
||||
"value" : { "4" : null },
|
||||
"action" : "@menu:matrix"
|
||||
// :TODO: Just use menu.fallback, e.g. @fallback
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
*/
|
||||
"options" : {
|
||||
"clearScreen" : true
|
||||
}
|
||||
@@ -165,19 +185,10 @@
|
||||
}
|
||||
},
|
||||
"newUserActive" : {
|
||||
"art" : "NEWACT",
|
||||
"art" : "STATS",
|
||||
"options" : {
|
||||
// :TODO: implement MCI codes for this
|
||||
"clearScreen" : true
|
||||
},
|
||||
"form" : {
|
||||
"0" : {
|
||||
"UN1UR2" : {
|
||||
"mci" : {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,19 +29,61 @@ StandardMenuModule.prototype.beforeArt = function() {
|
||||
StandardMenuModule.super_.prototype.beforeArt.call(this);
|
||||
};
|
||||
|
||||
StandardMenuModule.prototype.mciReady = function(mciMap) {
|
||||
StandardMenuModule.super_.prototype.mciReady.call(this, mciMap);
|
||||
StandardMenuModule.prototype.mciReady = function(mciData) {
|
||||
StandardMenuModule.super_.prototype.mciReady.call(this, mciData);
|
||||
|
||||
var self = this;
|
||||
|
||||
//
|
||||
// A quick rundown:
|
||||
// * We may have mciData.menu, mciData.prompt, or both.
|
||||
// * Prompt form is favored over menu form if both are present.
|
||||
// * Standard/prefdefined MCI entries must load both (e.g. %BN is expected to resolve)
|
||||
//
|
||||
self.viewControllers = {};
|
||||
|
||||
var vcOpts = { client : self.client };
|
||||
|
||||
if(mciData.menu) {
|
||||
self.viewControllers.menu = new ViewController(vcOpts);
|
||||
}
|
||||
|
||||
if(mciData.prompt) {
|
||||
self.viewControllers.prompt = new ViewController(vcOpts);
|
||||
}
|
||||
|
||||
var viewsReady = function(err) {
|
||||
// :TODO: Hrm.....
|
||||
};
|
||||
|
||||
|
||||
if(self.viewControllers.menu) {
|
||||
var menuLoadOpts = {
|
||||
mciMap : mciData.menu,
|
||||
menuConfig : self.menuConfig,
|
||||
withForm : !mciData.prompt,
|
||||
};
|
||||
|
||||
self.viewControllers.menu.loadFromMCIMapAndConfig(menuLoadOpts, viewsReady);
|
||||
}
|
||||
|
||||
if(self.viewControllers.prompt) {
|
||||
var promptLoadOpts = {
|
||||
callingMenu : self,
|
||||
mciMap : mciData.prompt,
|
||||
//promptConfig : self.menuConfig.promptConfig,
|
||||
};
|
||||
|
||||
self.viewControllers.prompt.loadFromPrompt(promptLoadOpts, viewsReady);
|
||||
}
|
||||
|
||||
/*
|
||||
var vc = self.addViewController(new ViewController({ client : self.client } ));
|
||||
vc.loadFromMCIMapAndConfig( { mciMap : mciMap, menuConfig : self.menuConfig }, function onViewReady(err) {
|
||||
vc.loadFromMCIMapAndConfig( { mciMap : mciData.menu, menuConfig : self.menuConfig }, function onViewReady(err) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
/* vc.on('submit', function onFormSubmit(formData) {
|
||||
console.log(formData);
|
||||
});*/
|
||||
}
|
||||
});
|
||||
*/
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user