@@ -44,6 +44,7 @@ component displayName="Admin login service" {
4444 _setCookieService ( arguments .cookieService );
4545 _setQrCodeGenerator ( arguments .qrCodeGenerator );
4646 _setRememberMeCookieKey ( " _presidecms-admin-persist" );
47+ _setTwoFactorAuthCookiePersistKey ( " _presidecms-admin-tfa-persist" );
4748
4849 return this ;
4950 }
@@ -481,11 +482,9 @@ component displayName="Admin login service" {
481482 * by the user and whether or not the user is already authenticated.
482483 *
483484 * @autodoc
484- * @ipAddress.hint The originating IP address of the request
485- * @userAgent.hint The originating user agent of the request
486485 */
487- public boolean function twoFactorAuthenticationRequired ( required string ipAddress , required string userAgent ) {
488- if ( isTwoFactorAuthenticated ( argumentCollection = arguments ) ) {
486+ public boolean function twoFactorAuthenticationRequired () {
487+ if ( isTwoFactorAuthenticated () ) {
489488 return false ;
490489 }
491490
@@ -506,10 +505,8 @@ component displayName="Admin login service" {
506505 * authentication.
507506 *
508507 * @autodoc
509- * @ipAddress.hint The originating IP address of the request
510- * @userAgent.hint The originating user agent of the request
511508 */
512- public boolean function isTwoFactorAuthenticated ( required string ipAddress , required string userAgent ) {
509+ public boolean function isTwoFactorAuthenticated () {
513510 var authenticated = _getSessionStorage ().getVar ( name = _getTwoFaSessionKey (), default = " " );
514511
515512 if ( IsBoolean ( authenticated ?: " " ) && authenticated ) {
@@ -525,9 +522,8 @@ component displayName="Admin login service" {
525522 selectFields = [ " logged_in_date" ]
526523 , filter = {
527524 security_user = getLoggedInUserId ()
528- , ip_address = arguments .ipAddress
529- , user_agent = arguments .userAgent
530- }
525+ , id = _getCookieService ().getVar ( name = _getTwoFactorAuthCookiePersistKey (), default = " " )
526+ }
531527 );
532528
533529 if ( ! tfaLoginRecord .recordCount ) {
@@ -654,11 +650,9 @@ component displayName="Admin login service" {
654650 *
655651 * @autodoc
656652 * @token.hint The user provided one time token (should have been generated by authenticator app)
657- * @ipAddress.hint The IP address of the incoming request
658- * @userAgent.hint The user agent ot the incoming request
659653 *
660654 */
661- public boolean function attemptTwoFactorAuthentication ( required string token , required string ipAddress , required string userAgent ) {
655+ public boolean function attemptTwoFactorAuthentication ( required string token ) {
662656 var userId = getLoggedInUserId ();
663657 var key = getTwoFactorAuthenticationKey ();
664658
@@ -677,21 +671,12 @@ component displayName="Admin login service" {
677671 two_step_auth_key_in_use = true
678672 } );
679673
680- var loginRecordDao = $getPresideObject ( " security_user_two_factor_login_record" );
681- var updated = loginRecordDao .updateData ( filter = {
682- security_user = userId
683- , ip_address = arguments .ipAddress
684- , user_agent = arguments .userAgent
685- }, data = { logged_in_date = Now () } );
686-
687- if ( ! updated ) {
688- loginRecordDao .insertData ({
689- security_user = userId
690- , ip_address = arguments .ipAddress
691- , user_agent = arguments .userAgent
692- , logged_in_date = Now ()
693- });
694- }
674+ var loginRecordId = $getPresideObject ( " security_user_two_factor_login_record" ).insertData ( {
675+ security_user = userId
676+ , logged_in_date = Now ()
677+ } );
678+
679+ _getCookieService ().setVar ( name = _getTwoFactorAuthCookiePersistKey (), value = loginRecordId );
695680
696681 $audit (
697682 userId = userId
@@ -1056,4 +1041,12 @@ component displayName="Admin login service" {
10561041 _rememberMeCookieKey = arguments .rememberMeCookieKey ;
10571042 }
10581043
1044+ private any function _getTwoFactorAuthCookiePersistKey (){
1045+ return variables ._twoFactorAuthCookieKey ;
1046+ }
1047+
1048+ private void function _setTwoFactorAuthCookiePersistKey ( required any twoFactorAuthCookieKey ){
1049+ variables ._twoFactorAuthCookieKey = arguments .twoFactorAuthCookieKey ;
1050+ }
1051+
10591052}
0 commit comments