Resolve TODO RE using EnigError for bad login attempts
This commit is contained in:
parent
ebc70907d4
commit
9fd819d608
|
@ -34,8 +34,9 @@ exports.Errors = {
|
||||||
ExternalProcess : (reason, reasonCode) => new EnigError('External process error', -32005, reason, reasonCode),
|
ExternalProcess : (reason, reasonCode) => new EnigError('External process error', -32005, reason, reasonCode),
|
||||||
MissingConfig : (reason, reasonCode) => new EnigError('Missing configuration', -32006, reason, reasonCode),
|
MissingConfig : (reason, reasonCode) => new EnigError('Missing configuration', -32006, reason, reasonCode),
|
||||||
UnexpectedState : (reason, reasonCode) => new EnigError('Unexpected state', -32007, 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),
|
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 = {
|
exports.ErrorReasons = {
|
||||||
|
@ -44,4 +45,5 @@ exports.ErrorReasons = {
|
||||||
NoPreviousMenu : 'NOPREV',
|
NoPreviousMenu : 'NOPREV',
|
||||||
NoConditionMatch : 'NOCONDMATCH',
|
NoConditionMatch : 'NOCONDMATCH',
|
||||||
NotEnabled : 'NOTENABLED',
|
NotEnabled : 'NOTENABLED',
|
||||||
|
AlreadyLoggedIn : 'ALREADYLOGGEDIN',
|
||||||
};
|
};
|
|
@ -10,6 +10,7 @@ const userLogin = require('../../user_login.js').userLogin;
|
||||||
const enigVersion = require('../../../package.json').version;
|
const enigVersion = require('../../../package.json').version;
|
||||||
const theme = require('../../theme.js');
|
const theme = require('../../theme.js');
|
||||||
const stringFormat = require('../../string_format.js');
|
const stringFormat = require('../../string_format.js');
|
||||||
|
const { ErrorReasons } = require('../../enig_error.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const ssh2 = require('ssh2');
|
const ssh2 = require('ssh2');
|
||||||
|
@ -70,7 +71,7 @@ function SSHClient(clientConn) {
|
||||||
|
|
||||||
userLogin(self, ctx.username, ctx.password, function authResult(err) {
|
userLogin(self, ctx.username, ctx.password, function authResult(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
if(err.existingConn) {
|
if(ErrorReasons.AlreadyLoggedIn === err.reasonCode) {
|
||||||
return alreadyLoggedIn(username);
|
return alreadyLoggedIn(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ function SSHClient(clientConn) {
|
||||||
|
|
||||||
userLogin(self, username, (answers[0] || ''), err => {
|
userLogin(self, username, (answers[0] || ''), err => {
|
||||||
if(err) {
|
if(err) {
|
||||||
if(err.existingConn) {
|
if(ErrorReasons.AlreadyLoggedIn === err.reasonCode) {
|
||||||
return alreadyLoggedIn(username);
|
return alreadyLoggedIn(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
const removeClient = require('./client_connections.js').removeClient;
|
const { removeClient } = require('./client_connections.js');
|
||||||
const ansiNormal = require('./ansi_term.js').normal;
|
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 messageArea = require('./message_area.js');
|
||||||
|
const { ErrorReasons } = require('./enig_error.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
@ -26,13 +27,15 @@ function login(callingMenu, formData, extraArgs, cb) {
|
||||||
userLogin(callingMenu.client, formData.value.username, formData.value.password, err => {
|
userLogin(callingMenu.client, formData.value.username, formData.value.password, err => {
|
||||||
if(err) {
|
if(err) {
|
||||||
// login failure
|
// 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);
|
return callingMenu.gotoMenu(callingMenu.menuConfig.config.tooNodeMenu, cb);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// Other error
|
// Other error
|
||||||
return callingMenu.prevMenu(cb);
|
return callingMenu.prevMenu(cb);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// success!
|
// success!
|
||||||
return callingMenu.nextMenu(cb);
|
return callingMenu.nextMenu(cb);
|
||||||
|
|
|
@ -45,9 +45,10 @@ module.exports = class User {
|
||||||
|
|
||||||
static get AccountStatus() {
|
static get AccountStatus() {
|
||||||
return {
|
return {
|
||||||
disabled : 0,
|
disabled : 0, // +op disabled
|
||||||
inactive : 1,
|
inactive : 1, // inactive, aka requires +op approval/activation
|
||||||
active : 2,
|
active : 2, // standard, active
|
||||||
|
locked : 3, // locked out (too many bad login attempts, etc.)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,10 @@ const StatLog = require('./stat_log.js');
|
||||||
const logger = require('./logger.js');
|
const logger = require('./logger.js');
|
||||||
const Events = require('./events.js');
|
const Events = require('./events.js');
|
||||||
const Config = require('./config.js').get;
|
const Config = require('./config.js').get;
|
||||||
|
const {
|
||||||
|
Errors,
|
||||||
|
ErrorReasons
|
||||||
|
} = require('./enig_error.js');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
|
@ -48,12 +52,10 @@ function userLogin(client, username, password, cb) {
|
||||||
'Already logged in'
|
'Already logged in'
|
||||||
);
|
);
|
||||||
|
|
||||||
const existingConnError = new Error('Already logged in as supplied user');
|
return cb(Errors.BadLogin(
|
||||||
existingConnError.existingConn = true;
|
`User ${user.username} already logged in.`,
|
||||||
|
ErrorReasons.AlreadyLoggedIn
|
||||||
// :TODO: We should use EnigError & pass existing connection as second param
|
));
|
||||||
|
|
||||||
return cb(existingConnError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update client logger with addition of username
|
// update client logger with addition of username
|
||||||
|
|
Loading…
Reference in New Issue