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');
|
2016-01-02 19:10:54 +00:00
|
|
|
var removeClient = require('./client_connections.js').removeClient;
|
2015-08-05 04:35:59 +00:00
|
|
|
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-11-04 06:15:49 +00:00
|
|
|
exports.prevMenu = prevMenu;
|
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
|
2015-12-07 03:54:23 +00:00
|
|
|
if(err.existingConn && _.has(callingMenu, 'menuConfig.config.tooNodeMenu')) {
|
|
|
|
callingMenu.gotoMenu(callingMenu.menuConfig.config.tooNodeMenu);
|
2015-10-19 23:21:47 +00:00
|
|
|
} else {
|
|
|
|
// Other error
|
2015-11-04 06:25:35 +00:00
|
|
|
callingMenu.prevMenu();
|
2015-08-05 04:35:59 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 23:21:47 +00:00
|
|
|
} else {
|
|
|
|
// success!
|
2015-11-04 06:15:49 +00:00
|
|
|
callingMenu.nextMenu();
|
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) +
|
2016-01-02 19:10:54 +00:00
|
|
|
'NO CARRIER', null, function written() {
|
2015-08-21 19:47:01 +00:00
|
|
|
|
2016-01-02 19:10:54 +00:00
|
|
|
// after data is written, disconnect & remove the client
|
|
|
|
removeClient(client);
|
|
|
|
});
|
2015-04-21 05:24:15 +00:00
|
|
|
}, 500);
|
2015-09-24 04:24:37 +00:00
|
|
|
}
|
|
|
|
|
2015-11-04 06:15:49 +00:00
|
|
|
function prevMenu(callingMenu, formData, extraArgs) {
|
|
|
|
callingMenu.prevMenu(function result(err) {
|
2015-09-24 04:24:37 +00:00
|
|
|
if(err) {
|
2015-11-04 06:15:49 +00:00
|
|
|
callingMenu.client.log.error( { error : err.toString() }, 'Error attempting to fallback!');
|
2015-09-24 04:24:37 +00:00
|
|
|
}
|
|
|
|
});
|
2015-09-24 05:41:06 +00:00
|
|
|
}
|