enigma-bbs/core/system_menu_method.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-04-21 05:24:15 +00:00
/* jslint node: true */
'use strict';
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;
var sysProp = require('./system_property.js');
var userLogin = require('./user_login.js').userLogin;
2015-04-21 05:24:15 +00:00
var async = require('async');
var _ = require('lodash');
var iconv = require('iconv-lite');
2015-04-21 05:24:15 +00:00
exports.login = login;
exports.logoff = logoff;
exports.fallbackMenu = fallbackMenu;
2015-04-21 05:24:15 +00:00
function login(callingMenu, formData, extraArgs) {
var client = callingMenu.client;
userLogin(callingMenu.client, formData.value.username, formData.value.password, function authResult(err) {
2015-04-21 05:24:15 +00:00
if(err) {
// login failure
if(err.existingConn) {
client.term.rawWrite(ansi.resetScreen());
var artOpts = {
client : client,
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',
};
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);
});
return;
} else {
// Other error
client.fallbackMenuModule();
}
} else {
// success!
client.gotoMenuModule( { name : callingMenu.menuConfig.next } );
2015-04-21 05:24:15 +00:00
}
});
}
function logoff(callingMenu, formData, extraArgs) {
//
// 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' +
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);
}
function fallbackMenu(callingMenu, formData, extraArgs) {
callingMenu.client.fallbackMenuModule( { extraArgs : extraArgs }, function result(err) {
if(err) {
callingMenu.client.log.error( { error : err }, 'Error attempting to fallback!');
}
});
}