Resolve TODO RE using EnigError for bad login attempts

This commit is contained in:
Bryan Ashby 2018-11-21 19:43:50 -07:00
parent ebc70907d4
commit 9fd819d608
5 changed files with 27 additions and 18 deletions

View File

@ -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',
};

View File

@ -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);
}

View File

@ -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,13 +27,15 @@ 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);
}
}
// success!
return callingMenu.nextMenu(cb);

View File

@ -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.)
};
}

View File

@ -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