2015-04-21 05:24:15 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2015-08-05 04:35:59 +00:00
|
|
|
var theme = require('./theme.js');
|
|
|
|
var clientConnections = require('./client_connections.js').clientConnections;
|
|
|
|
var ansi = require('./ansi_term.js');
|
|
|
|
var userDb = require('./database.js').dbs.user;
|
2015-10-18 02:03:51 +00:00
|
|
|
var sysProp = require('./system_property.js');
|
2015-10-19 23:21:47 +00:00
|
|
|
var userLogin = require('./user_login.js').userLogin;
|
2015-04-21 05:24:15 +00:00
|
|
|
|
2015-08-05 04:35:59 +00:00
|
|
|
var async = require('async');
|
2015-10-16 05:41:24 +00:00
|
|
|
var _ = require('lodash');
|
2015-11-01 20:55:59 +00:00
|
|
|
var iconv = require('iconv-lite');
|
2015-04-21 05:24:15 +00:00
|
|
|
|
2015-08-05 04:35:59 +00:00
|
|
|
exports.login = login;
|
|
|
|
exports.logoff = logoff;
|
2015-09-24 05:41:06 +00:00
|
|
|
exports.fallbackMenu = fallbackMenu;
|
2015-04-21 05:24:15 +00:00
|
|
|
|
|
|
|
function login(callingMenu, formData, extraArgs) {
|
|
|
|
var client = callingMenu.client;
|
|
|
|
|
2015-10-19 23:21:47 +00:00
|
|
|
userLogin(callingMenu.client, formData.value.username, formData.value.password, function authResult(err) {
|
2015-04-21 05:24:15 +00:00
|
|
|
if(err) {
|
2015-10-19 23:21:47 +00:00
|
|
|
// login failure
|
|
|
|
if(err.existingConn) {
|
2015-10-16 05:41:24 +00:00
|
|
|
client.term.rawWrite(ansi.resetScreen());
|
2015-08-05 04:38:28 +00:00
|
|
|
|
2015-10-16 05:41:24 +00:00
|
|
|
var artOpts = {
|
|
|
|
client : client,
|
2015-10-19 23:21:47 +00:00
|
|
|
font : _.has(callingMenu, 'menuConfig.config.tooNode.font') ? callingMenu.menuConfig.config.tooNode.font : null,
|
|
|
|
name : _.has(callingMenu, 'menuConfig.config.tooNode.art') ? callingMenu.menuConfig.config.tooNode.art : 'TOONODE',
|
2015-10-16 05:41:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
theme.displayThemeArt(artOpts, function artDisplayed(err) {
|
|
|
|
if(err) {
|
|
|
|
client.term.write('\nA user by that name is already logged in.\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(function timeout() {
|
|
|
|
client.fallbackMenuModule();
|
|
|
|
}, 2000);
|
|
|
|
});
|
2015-08-05 04:35:59 +00:00
|
|
|
|
|
|
|
return;
|
2015-10-19 23:21:47 +00:00
|
|
|
} else {
|
|
|
|
// Other error
|
|
|
|
client.fallbackMenuModule();
|
2015-08-05 04:35:59 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 23:21:47 +00:00
|
|
|
} else {
|
|
|
|
// success!
|
|
|
|
client.gotoMenuModule( { name : callingMenu.menuConfig.next } );
|
2015-04-21 05:24:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function logoff(callingMenu, formData, extraArgs) {
|
2015-08-05 04:35:59 +00:00
|
|
|
//
|
|
|
|
// Simple logoff. Note that recording of @ logoff properties/stats
|
|
|
|
// occurs elsewhere!
|
|
|
|
//
|
2015-04-21 05:24:15 +00:00
|
|
|
var client = callingMenu.client;
|
|
|
|
|
|
|
|
setTimeout(function timeout() {
|
2015-08-21 19:47:01 +00:00
|
|
|
//
|
|
|
|
// For giggles...
|
|
|
|
//
|
|
|
|
client.term.write(
|
|
|
|
ansi.normal() + '\n' +
|
2015-11-01 20:55:59 +00:00
|
|
|
iconv.decode(require('crypto').randomBytes(Math.floor(Math.random() * 65) + 20), client.term.outputEncoding) +
|
2015-08-21 19:47:01 +00:00
|
|
|
'NO CARRIER');
|
|
|
|
|
2015-04-21 05:24:15 +00:00
|
|
|
client.end();
|
|
|
|
}, 500);
|
2015-09-24 04:24:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fallbackMenu(callingMenu, formData, extraArgs) {
|
|
|
|
callingMenu.client.fallbackMenuModule( { extraArgs : extraArgs }, function result(err) {
|
|
|
|
if(err) {
|
2015-09-24 05:41:06 +00:00
|
|
|
callingMenu.client.log.error( { error : err }, 'Error attempting to fallback!');
|
2015-09-24 04:24:37 +00:00
|
|
|
}
|
|
|
|
});
|
2015-09-24 05:41:06 +00:00
|
|
|
}
|