enigma-bbs/core/system_menu_method.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-04-21 05:24:15 +00:00
/* jslint node: true */
'use strict';
var theme = require('./theme.js');
2016-01-02 19:10:54 +00:00
var removeClient = require('./client_connections.js').removeClient;
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.prevMenu = prevMenu;
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 && _.has(callingMenu, 'menuConfig.config.tooNodeMenu')) {
callingMenu.gotoMenu(callingMenu.menuConfig.config.tooNodeMenu);
} else {
// Other error
callingMenu.prevMenu();
}
} else {
// success!
callingMenu.nextMenu();
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) +
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);
}
function prevMenu(callingMenu, formData, extraArgs) {
callingMenu.prevMenu(function result(err) {
if(err) {
callingMenu.client.log.error( { error : err.toString() }, 'Error attempting to fallback!');
}
});
}