@@ -38,10 +38,9 @@ router.post('/', async (req, res) => {
38
38
try {
39
39
let establishmentUser = givenEstablishmentUid === null ? await models . login . findOne ( {
40
40
where : {
41
- username : givenUsername ,
42
- isActive :true
41
+ username : givenUsername
43
42
} ,
44
- attributes : [ 'id' , 'username' , 'isActive' , 'invalidAttempt' , 'registrationId' , 'firstLogin' , 'Hash' , 'lastLogin' , 'tribalHash' , 'tribalSalt' , 'agreedUpdatedTerms' ] ,
43
+ attributes : [ 'id' , 'username' , 'isActive' , 'invalidAttempt' , 'registrationId' , 'firstLogin' , 'Hash' , 'lastLogin' , 'tribalHash' , 'tribalSalt' , 'agreedUpdatedTerms' , 'status' ] ,
45
44
include : [ {
46
45
model : models . user ,
47
46
attributes : [ 'id' , 'uid' , 'FullNameValue' , 'EmailValue' , 'isPrimary' , 'establishmentId' , "UserRoleValue" , 'tribalId' ] ,
@@ -61,10 +60,9 @@ router.post('/', async (req, res) => {
61
60
// before returning error, check to see if this is a superadmin user with a given establishment UID, to be assumed as their "logged in session" primary establishment
62
61
establishmentUser = await models . login . findOne ( {
63
62
where : {
64
- username : givenUsername ,
65
- isActive :true ,
63
+ username : givenUsername
66
64
} ,
67
- attributes : [ 'id' , 'username' , 'isActive' , 'invalidAttempt' , 'registrationId' , 'firstLogin' , 'Hash' , 'lastLogin' , 'tribalHash' , 'tribalSalt' , 'agreedUpdatedTerms' ] ,
65
+ attributes : [ 'id' , 'username' , 'isActive' , 'invalidAttempt' , 'registrationId' , 'firstLogin' , 'Hash' , 'lastLogin' , 'tribalHash' , 'tribalSalt' , 'agreedUpdatedTerms' , 'status' ] ,
68
66
include : [ {
69
67
model : models . user ,
70
68
attributes : [ 'id' , 'uid' , 'FullNameValue' , 'EmailValue' , 'isPrimary' , 'establishmentId' , "UserRoleValue" , 'tribalId' ] ,
@@ -109,6 +107,23 @@ router.post('/', async (req, res) => {
109
107
}
110
108
}
111
109
110
+ //check weather posted user is locked or pending
111
+ if ( establishmentUser ) {
112
+ if ( ! establishmentUser . isActive && establishmentUser . status === 'Locked' ) {
113
+ //check for locked status, if locked then return with 409 error
114
+ console . error ( `POST .../login failed: User status is locked` ) ;
115
+ return res . status ( 409 ) . send ( {
116
+ message : 'Authentication failed.' ,
117
+ } ) ;
118
+ } else if ( ! establishmentUser . isActive && establishmentUser . status === 'PENDING' ) {
119
+ //check for Pending status, if Pending then return with 403 error
120
+ console . error ( `POST .../login failed: User status is pending` ) ;
121
+ return res . status ( 405 ) . send ( {
122
+ message : 'Authentication failed.' ,
123
+ } ) ;
124
+ }
125
+ }
126
+
112
127
// if this found login account is a migrated tribal account, and there is no current hash, then
113
128
// we need to first validate password using tribal hashing
114
129
let tribalErr = null ;
@@ -218,7 +233,8 @@ router.post('/', async (req, res) => {
218
233
if ( establishmentUser . invalidAttempt === ( maxNumberOfFailedAttempts + 1 ) ) {
219
234
// lock the account
220
235
const loginUpdate = {
221
- isActive : false
236
+ isActive : false ,
237
+ status : 'Locked'
222
238
} ;
223
239
await establishmentUser . update ( loginUpdate , { transaction : t } ) ;
224
240
@@ -238,9 +254,11 @@ router.post('/', async (req, res) => {
238
254
239
255
const resetLink = `${ req . protocol } ://${ req . get ( 'host' ) } /api/registration/validateResetPassword?reset=${ requestUuid } ` ;
240
256
241
- // send email to recipient with the reset UUID
257
+ // send email to recipient with the reset UUID if user is not locked
242
258
try {
243
- await sendMail ( establishmentUser . user . EmailValue , establishmentUser . user . FullNameValue , requestUuid ) ;
259
+ if ( establishmentUser . isActive && establishmentUser . status !== 'Locked' ) {
260
+ await sendMail ( establishmentUser . user . EmailValue , establishmentUser . user . FullNameValue , requestUuid ) ;
261
+ }
244
262
} catch ( err ) {
245
263
console . error ( err ) ;
246
264
}
0 commit comments