2015-03-30 03:47:48 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var theme = require('../core/theme.js');
|
2015-04-06 06:18:08 +00:00
|
|
|
var Log = require('../core/logger.js').log;
|
2015-03-30 03:47:48 +00:00
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
var async = require('async');
|
2015-03-30 03:47:48 +00:00
|
|
|
|
2015-04-21 04:50:58 +00:00
|
|
|
exports.login = login;
|
2015-03-30 03:47:48 +00:00
|
|
|
|
2015-04-21 04:50:58 +00:00
|
|
|
function login(callingMenu, formData, extraArgs) {
|
2015-04-19 08:13:13 +00:00
|
|
|
var client = callingMenu.client;
|
|
|
|
|
|
|
|
client.user.authenticate(formData.value.username, formData.value.password, function authenticated(err) {
|
|
|
|
if(err) {
|
|
|
|
Log.info( { username : formData.value.username }, 'Failed login attempt %s', err);
|
|
|
|
|
|
|
|
client.gotoMenuModule( { name : callingMenu.menuConfig.fallback } );
|
|
|
|
} else {
|
|
|
|
// use client.user so we can get correct case
|
|
|
|
Log.info( { username : callingMenu.client.user.username }, 'Successful login');
|
|
|
|
|
|
|
|
async.parallel(
|
2015-04-21 04:50:58 +00:00
|
|
|
[
|
|
|
|
function loadThemeConfig(callback) {
|
|
|
|
theme.getThemeInfo(client.user.properties.theme_id, function themeInfo(err, info) {
|
2015-05-13 05:04:22 +00:00
|
|
|
client.currentTheme = info;
|
2015-04-21 04:50:58 +00:00
|
|
|
callback(null);
|
|
|
|
});
|
2015-04-19 08:13:13 +00:00
|
|
|
}
|
2015-04-21 04:50:58 +00:00
|
|
|
],
|
|
|
|
function complete(err, results) {
|
|
|
|
client.gotoMenuModule( { name : callingMenu.menuConfig.next } );
|
|
|
|
}
|
|
|
|
);
|
2015-04-19 08:13:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|