enigma-bbs/core/system_menu_method.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-04-21 05:24:15 +00:00
/* jslint node: true */
'use strict';
var theme = require('../core/theme.js');
2015-07-26 06:20:07 +00:00
//var Log = require('../core/logger.js').log;
2015-04-21 05:24:15 +00:00
var ansi = require('../core/ansi_term.js');
var async = require('async');
exports.login = login;
exports.logoff = logoff;
function login(callingMenu, formData, extraArgs) {
var client = callingMenu.client;
client.user.authenticate(formData.value.username, formData.value.password, function authenticated(err) {
if(err) {
2015-07-26 06:20:07 +00:00
client.log.info( { username : formData.value.username }, 'Failed login attempt %s', err);
2015-04-21 05:24:15 +00:00
client.gotoMenuModule( { name : callingMenu.menuConfig.fallback } );
} else {
// use client.user so we can get correct case
2015-07-26 06:20:07 +00:00
client.log.info( { username : callingMenu.client.user.username }, 'Successful login');
2015-04-21 05:24:15 +00:00
async.parallel(
[
function loadThemeConfig(callback) {
theme.loadTheme(client.user.properties.theme_id, function themeLoaded(err, theme) {
client.currentTheme = theme;
callback(null); // always non-fatal
2015-04-21 05:24:15 +00:00
});
2015-07-26 06:20:07 +00:00
},
function recordLogin(callback) {
client.user.persistProperty('last_login_timestamp', new Date().toISOString(), function persisted(err) {
callback(err);
});
2015-04-21 05:24:15 +00:00
}
],
function complete(err, results) {
2015-07-26 06:20:07 +00:00
if(err) {
client.log.error(err);
// :TODO: drop the connection?
}
2015-04-21 05:24:15 +00:00
client.gotoMenuModule( { name : callingMenu.menuConfig.next } );
}
);
}
});
}
function logoff(callingMenu, formData, extraArgs) {
var client = callingMenu.client;
// :TODO: record this.
setTimeout(function timeout() {
client.term.write(ansi.normal() + '\nATH0\n');
client.end();
}, 500);
}