* clearScreen -> cls for nostalgia

* module cleanup: some simple modules moved to general_menu_method.js @methods
* More work on menu configuration & options
- Removed formatting of args for now. Too tied to MCI, not really needed with argName stuff
This commit is contained in:
Bryan Ashby 2015-04-20 22:50:58 -06:00
parent 8db72430d3
commit ec5f1836c5
16 changed files with 350 additions and 1233 deletions

View file

@ -1,29 +1,14 @@
/* jslint node: true */
'use strict';
var ansi = require('../core/ansi_term.js');
var art = require('../core/art.js');
var user = require('../core/user.js');
var theme = require('../core/theme.js');
var Log = require('../core/logger.js').log;
var MenuModule = require('../core/menu_module.js').MenuModule;
var ViewController = require('../core/view_controller.js').ViewController;
var async = require('async');
// :TODO: clean up requires
exports.login = login;
/*exports.moduleInfo = {
name : 'Login',
desc : 'Login Module',
author : 'NuSkooler',
};*/
//exports.getModule = LoginModule;
exports.attemptLogin = attemptLogin;
function attemptLogin(callingMenu, formData, extraArgs) {
function login(callingMenu, formData, extraArgs) {
var client = callingMenu.client;
client.user.authenticate(formData.value.username, formData.value.password, function authenticated(err) {
@ -36,99 +21,18 @@ function attemptLogin(callingMenu, formData, extraArgs) {
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 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 LoginModule(menuConfig) {
MenuModule.call(this, menuConfig);
var self = this;
// :TODO: Handle max login attempts before hangup
// :TODO: probably should persist failed login attempts to user DB
this.menuMethods.attemptLogin = function(args) {
self.client.user.authenticate(args.username, args.password, function onAuth(err) {
if(err) {
// :TODO: change to simple login/username prompts - no buttons.
Log.info( { username : args.username }, 'Failed login attempt %s', err);
// :TODO: localize:
// :TODO: create a blink label of sorts - simulate blink with ICE
self.viewController.getView(5).setText('Invalid username or password!');
self.clearForm();
self.viewController.switchFocus(1);
setTimeout(function onTimeout() {
// :TODO: should there be a block input type of pattern here? self.client.ignoreInput() ... self.client.acceptInput()
self.viewController.getView(5).clearText(); // :TODO: for some reason this doesn't clear the last character
self.viewController.switchFocus(1);
}, 2000);
} else {
Log.info( { username : self.client.user.username }, 'Successful login');
// :TODO: persist information about login to user
async.parallel(
[
function loadThemeConfig(callback) {
theme.getThemeInfo(self.client.user.properties.art_theme_id, function themeInfo(err, info) {
self.client.currentThemeInfo = info;
callback(null);
});
}
],
function complete(err, results) {
self.client.gotoMenuModule( { name : args.next.success } );
}
);
}
});
};
this.clearForm = function() {
[ 1, 2, ].forEach(function onId(id) {
self.viewController.getView(id).clearText();
});
};
}
require('util').inherits(LoginModule, MenuModule);
LoginModule.prototype.enter = function(client) {
LoginModule.super_.prototype.enter.call(this, client);
};
LoginModule.prototype.beforeArt = function() {
LoginModule.super_.prototype.beforeArt.call(this);
//this.client.term.write(ansi.resetScreen());
};
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 : mciData.menu, menuConfig : self.menuConfig }, function onViewReady(err) {
});
};
*/