adapt patch to authenticate func to allow ldap login
This commit is contained in:
parent
b9f430631b
commit
19cf2f3981
|
@ -31,51 +31,25 @@ const AuthenticationManager = {
|
||||||
// gets serialized into the session and there may be subtle differences
|
// gets serialized into the session and there may be subtle differences
|
||||||
// between the user returned by Mongoose vs mongodb (such as default values)
|
// between the user returned by Mongoose vs mongodb (such as default values)
|
||||||
User.findOne(query, (error, user) => {
|
User.findOne(query, (error, user) => {
|
||||||
if (error) {
|
//console.log("Begining:" + JSON.stringify(query))
|
||||||
return callback(error)
|
AuthenticationManager.authUserObj(error, user, query, password, callback)
|
||||||
}
|
|
||||||
if (!user || !user.hashedPassword) {
|
|
||||||
return callback(null, null)
|
|
||||||
}
|
|
||||||
bcrypt.compare(password, user.hashedPassword, function (error, match) {
|
|
||||||
if (error) {
|
|
||||||
return callback(error)
|
|
||||||
}
|
|
||||||
const update = { $inc: { loginEpoch: 1 } }
|
|
||||||
if (!match) {
|
|
||||||
update.$set = { lastFailedLogin: new Date() }
|
|
||||||
}
|
|
||||||
User.updateOne(
|
|
||||||
{ _id: user._id, loginEpoch: user.loginEpoch },
|
|
||||||
update,
|
|
||||||
{},
|
|
||||||
(err, result) => {
|
|
||||||
if (err) {
|
|
||||||
return callback(err)
|
|
||||||
}
|
|
||||||
if (result.nModified !== 1) {
|
|
||||||
return callback(new ParallelLoginError())
|
|
||||||
}
|
|
||||||
if (!match) {
|
|
||||||
return callback(null, null)
|
|
||||||
}
|
|
||||||
AuthenticationManager.checkRounds(
|
|
||||||
user,
|
|
||||||
user.hashedPassword,
|
|
||||||
password,
|
|
||||||
function (err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err)
|
|
||||||
}
|
|
||||||
callback(null, user)
|
|
||||||
HaveIBeenPwned.checkPasswordForReuseInBackground(password)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
//login with any password
|
||||||
|
login(user, password, callback) {
|
||||||
|
AuthenticationManager.checkRounds(
|
||||||
|
user,
|
||||||
|
user.hashedPassword,
|
||||||
|
password,
|
||||||
|
function (err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err)
|
||||||
|
}
|
||||||
|
callback(null, user)
|
||||||
|
HaveIBeenPwned.checkPasswordForReuseInBackground(password)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
//oauth2
|
//oauth2
|
||||||
createUserIfNotExist(oauth_user, callback) {
|
createUserIfNotExist(oauth_user, callback) {
|
||||||
|
|
Loading…
Reference in New Issue