diff --git a/core/enig_error.js b/core/enig_error.js index 3f189dd7..01e62c40 100644 --- a/core/enig_error.js +++ b/core/enig_error.js @@ -34,8 +34,9 @@ exports.Errors = { ExternalProcess : (reason, reasonCode) => new EnigError('External process error', -32005, reason, reasonCode), MissingConfig : (reason, reasonCode) => new EnigError('Missing configuration', -32006, reason, reasonCode), UnexpectedState : (reason, reasonCode) => new EnigError('Unexpected state', -32007, reason, reasonCode), - MissingParam : (reason, reasonCode) => new EnigError('Missing paramater(s)', -32008, reason, reasonCode), + MissingParam : (reason, reasonCode) => new EnigError('Missing paramter(s)', -32008, reason, reasonCode), MissingMci : (reason, reasonCode) => new EnigError('Missing required MCI code(s)', -32009, reason, reasonCode), + BadLogin : (reason, reasonCode) => new EnigError('Bad login attempt', -32010, reason, reasonCode), }; exports.ErrorReasons = { @@ -44,4 +45,5 @@ exports.ErrorReasons = { NoPreviousMenu : 'NOPREV', NoConditionMatch : 'NOCONDMATCH', NotEnabled : 'NOTENABLED', + AlreadyLoggedIn : 'ALREADYLOGGEDIN', }; \ No newline at end of file diff --git a/core/servers/login/ssh.js b/core/servers/login/ssh.js index 72f91a2a..5f0ff05f 100644 --- a/core/servers/login/ssh.js +++ b/core/servers/login/ssh.js @@ -10,6 +10,7 @@ const userLogin = require('../../user_login.js').userLogin; const enigVersion = require('../../../package.json').version; const theme = require('../../theme.js'); const stringFormat = require('../../string_format.js'); +const { ErrorReasons } = require('../../enig_error.js'); // deps const ssh2 = require('ssh2'); @@ -70,7 +71,7 @@ function SSHClient(clientConn) { userLogin(self, ctx.username, ctx.password, function authResult(err) { if(err) { - if(err.existingConn) { + if(ErrorReasons.AlreadyLoggedIn === err.reasonCode) { return alreadyLoggedIn(username); } @@ -96,7 +97,7 @@ function SSHClient(clientConn) { userLogin(self, username, (answers[0] || ''), err => { if(err) { - if(err.existingConn) { + if(ErrorReasons.AlreadyLoggedIn === err.reasonCode) { return alreadyLoggedIn(username); } diff --git a/core/system_menu_method.js b/core/system_menu_method.js index 9218e34a..8485a90f 100644 --- a/core/system_menu_method.js +++ b/core/system_menu_method.js @@ -2,10 +2,11 @@ 'use strict'; // ENiGMA½ -const removeClient = require('./client_connections.js').removeClient; +const { removeClient } = require('./client_connections.js'); const ansiNormal = require('./ansi_term.js').normal; -const userLogin = require('./user_login.js').userLogin; +const { userLogin } = require('./user_login.js'); const messageArea = require('./message_area.js'); +const { ErrorReasons } = require('./enig_error.js'); // deps const _ = require('lodash'); @@ -26,12 +27,14 @@ function login(callingMenu, formData, extraArgs, cb) { userLogin(callingMenu.client, formData.value.username, formData.value.password, err => { if(err) { // login failure - if(err.existingConn && _.has(callingMenu, 'menuConfig.config.tooNodeMenu')) { + if(ErrorReasons.AlreadyLoggedIn === err.reasonCode && + _.has(callingMenu, 'menuConfig.config.tooNodeMenu')) + { return callingMenu.gotoMenu(callingMenu.menuConfig.config.tooNodeMenu, cb); - } else { - // Other error - return callingMenu.prevMenu(cb); } + + // Other error + return callingMenu.prevMenu(cb); } // success! diff --git a/core/user.js b/core/user.js index 6c2b964d..27f4775a 100644 --- a/core/user.js +++ b/core/user.js @@ -45,9 +45,10 @@ module.exports = class User { static get AccountStatus() { return { - disabled : 0, - inactive : 1, - active : 2, + disabled : 0, // +op disabled + inactive : 1, // inactive, aka requires +op approval/activation + active : 2, // standard, active + locked : 3, // locked out (too many bad login attempts, etc.) }; } diff --git a/core/user_login.js b/core/user_login.js index a3b2089b..c4f1bcf1 100644 --- a/core/user_login.js +++ b/core/user_login.js @@ -8,6 +8,10 @@ const StatLog = require('./stat_log.js'); const logger = require('./logger.js'); const Events = require('./events.js'); const Config = require('./config.js').get; +const { + Errors, + ErrorReasons +} = require('./enig_error.js'); // deps const async = require('async'); @@ -48,12 +52,10 @@ function userLogin(client, username, password, cb) { 'Already logged in' ); - const existingConnError = new Error('Already logged in as supplied user'); - existingConnError.existingConn = true; - - // :TODO: We should use EnigError & pass existing connection as second param - - return cb(existingConnError); + return cb(Errors.BadLogin( + `User ${user.username} already logged in.`, + ErrorReasons.AlreadyLoggedIn + )); } // update client logger with addition of username