mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-27 10:03:13 +00:00
test against ip matcher for notification on login if different from previous ip
This commit is contained in:
parent
de83df2703
commit
bf2ea4e7b3
2 changed files with 12 additions and 0 deletions
|
@ -11,6 +11,7 @@ UserHandler = require("../User/UserHandler")
|
||||||
UserSessionsManager = require("../User/UserSessionsManager")
|
UserSessionsManager = require("../User/UserSessionsManager")
|
||||||
Analytics = require "../Analytics/AnalyticsManager"
|
Analytics = require "../Analytics/AnalyticsManager"
|
||||||
passport = require 'passport'
|
passport = require 'passport'
|
||||||
|
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
|
||||||
|
|
||||||
module.exports = AuthenticationController =
|
module.exports = AuthenticationController =
|
||||||
|
|
||||||
|
@ -72,6 +73,7 @@ module.exports = AuthenticationController =
|
||||||
finishLogin: (user, req, res, next) ->
|
finishLogin: (user, req, res, next) ->
|
||||||
redir = AuthenticationController._getRedirectFromSession(req) || "/project"
|
redir = AuthenticationController._getRedirectFromSession(req) || "/project"
|
||||||
AuthenticationController._loginAsyncHandlers(req, user)
|
AuthenticationController._loginAsyncHandlers(req, user)
|
||||||
|
AuthenticationController.ipMatchCheck(req, user)
|
||||||
AuthenticationController.afterLoginSessionSetup req, user, (err) ->
|
AuthenticationController.afterLoginSessionSetup req, user, (err) ->
|
||||||
if err?
|
if err?
|
||||||
return next(err)
|
return next(err)
|
||||||
|
@ -119,6 +121,15 @@ module.exports = AuthenticationController =
|
||||||
# capture the request ip for use when creating the session
|
# capture the request ip for use when creating the session
|
||||||
user._login_req_ip = req.ip
|
user._login_req_ip = req.ip
|
||||||
|
|
||||||
|
ipMatchCheck: (req, user) ->
|
||||||
|
if req.ip != user.lastLoginIp
|
||||||
|
NotificationsBuilder.ipMatcherAffiliation(user._id, req.ip).create((err) ->
|
||||||
|
return err
|
||||||
|
)
|
||||||
|
UserUpdater.updateUser user._id.toString(), {
|
||||||
|
$set: { "lastLoginIp": req.ip }
|
||||||
|
}
|
||||||
|
|
||||||
setInSessionUser: (req, props) ->
|
setInSessionUser: (req, props) ->
|
||||||
for key, value of props
|
for key, value of props
|
||||||
if req?.session?.passport?.user?
|
if req?.session?.passport?.user?
|
||||||
|
|
|
@ -22,6 +22,7 @@ UserSchema = new Schema
|
||||||
confirmed : {type : Boolean, default : false}
|
confirmed : {type : Boolean, default : false}
|
||||||
signUpDate : {type : Date, default: () -> new Date() }
|
signUpDate : {type : Date, default: () -> new Date() }
|
||||||
lastLoggedIn : {type : Date}
|
lastLoggedIn : {type : Date}
|
||||||
|
lastLoginIp : {type : String, default : ''}
|
||||||
loginCount : {type : Number, default: 0}
|
loginCount : {type : Number, default: 0}
|
||||||
holdingAccount : {type : Boolean, default: false}
|
holdingAccount : {type : Boolean, default: false}
|
||||||
ace : {
|
ace : {
|
||||||
|
|
Loading…
Reference in a new issue