<commit_before>/* 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;

var async				= require('async');
var _					= require('lodash');
var iconv				= require('iconv-lite');

exports.login			= login;
exports.logoff			= logoff;
exports.prevMenu		= prevMenu;

function login(callingMenu, formData, extraArgs) {
	var client = callingMenu.client;

	userLogin(callingMenu.client, formData.value.username, formData.value.password, function authResult(err) {
		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() {
						callingMenu.prevMenu();
					}, 2000);
				});

				return;
			} else {
				//	Other error
				callingMenu.prevMenu();
			}

		} else {
			//	success!
			callingMenu.nextMenu();
		}
	});
}

function logoff(callingMenu, formData, extraArgs) {
	//
	//	Simple logoff. Note that recording of @ logoff properties/stats
	//	occurs elsewhere!<commit_msg>* Better handling of TOONODE (existing user already logged in)<commit_after>/* 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;

var async				= require('async');
var _					= require('lodash');
var iconv				= require('iconv-lite');

exports.login			= login;
exports.logoff			= logoff;
exports.prevMenu		= prevMenu;

function login(callingMenu, formData, extraArgs) {
	var client = callingMenu.client;

	userLogin(callingMenu.client, formData.value.username, formData.value.password, function authResult(err) {
		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();
		}
	});
}

function logoff(callingMenu, formData, extraArgs) {
	//
	//	Simple logoff. Note that recording of @ logoff properties/stats
	//	occurs elsewhere!
{'fraction_non_alphanumeric': 0.1462756993596225, 'fraction_numerical': 0.0013481631277384564, 'mean_word_length': 3.573189522342065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4480994', 'n_tokens_mistral': 1141, 'n_tokens_neox': 985, 'n_words': 194}