@@ -158,18 +158,16 @@ public function logoutAction()
158
158
$ notifier ->callback ('CALLBACK_CORE_USER_LOGOUT ' );
159
159
$ this ->userSession ->Dao = null ;
160
160
Zend_Session::ForgetMe ();
161
+
162
+ /** @var Zend_Controller_Request_Http $request */
161
163
$ request = $ this ->getRequest ();
164
+
162
165
$ date = new DateTime ();
163
166
$ interval = new DateInterval ('P1M ' );
164
- setcookie (
165
- MIDAS_USER_COOKIE_NAME ,
166
- null ,
167
- $ date ->sub ($ interval )->getTimestamp (),
168
- '/ ' ,
169
- $ request ->getHttpHost (),
170
- (int ) Zend_Registry::get ('configGlobal ' )->get ('cookie_secure ' , 1 ) === 1 ,
171
- true
172
- );
167
+ $ expires = $ date ->sub ($ interval );
168
+
169
+ UtilityComponent::setCookie ($ request , MIDAS_USER_COOKIE_NAME , false , $ expires );
170
+
173
171
$ noRedirect = $ this ->getParam ('noRedirect ' );
174
172
if (isset ($ noRedirect )) {
175
173
$ this ->disableView ();
@@ -499,18 +497,17 @@ public function ajaxloginAction()
499
497
if ($ userDao ->getSalt () == '' ) {
500
498
$ passwordHash = $ this ->User ->convertLegacyPasswordHash ($ userDao , $ form ->getValue ('password ' ));
501
499
}
500
+
501
+ /** @var Zend_Controller_Request_Http $request */
502
502
$ request = $ this ->getRequest ();
503
503
$ date = new DateTime ();
504
504
$ interval = new DateInterval ('P1M ' );
505
- setcookie (
506
- MIDAS_USER_COOKIE_NAME ,
507
- $ userDao ->getKey ().'- ' .$ passwordHash ,
508
- $ date ->add ($ interval )->getTimestamp (),
509
- '/ ' ,
510
- $ request ->getHttpHost (),
511
- (int ) Zend_Registry::get ('configGlobal ' )->get ('cookie_secure ' , 1 ) === 1 ,
512
- true
513
- );
505
+ $ expires = $ date ->add ($ interval );
506
+
507
+ $ value = $ userDao ->getKey ().'- ' .$ passwordHash ;
508
+
509
+ UtilityComponent::setCookie ($ request , MIDAS_USER_COOKIE_NAME , $ value , $ expires );
510
+
514
511
Zend_Session::start ();
515
512
$ user = new Zend_Session_Namespace ('Auth_User ' );
516
513
$ user ->setExpirationSeconds (60 * (int ) Zend_Registry::get ('configGlobal ' )->get ('session_lifetime ' , 20 ));
@@ -526,17 +523,20 @@ public function ajaxloginAction()
526
523
/** Login action */
527
524
public function loginAction ()
528
525
{
526
+ /** @var Zend_Controller_Request_Http $request */
529
527
$ request = $ this ->getRequest ();
530
528
$ this ->Form ->User ->uri = $ request ->getRequestUri ();
529
+
530
+ /** @var Zend_Form $form */
531
531
$ form = $ this ->Form ->User ->createLoginForm ();
532
532
$ this ->view ->form = $ this ->getFormAsArray ($ form );
533
533
$ this ->disableLayout ();
534
534
if ($ this ->_request ->isPost ()) {
535
535
$ this ->disableView ();
536
536
$ previousUri = $ this ->getParam ('previousuri ' );
537
537
if ($ form ->isValid ($ request ->getPost ())) {
538
+ $ notifications = array ();
538
539
try {
539
- $ notifications = array (); // initialize first in case of exception
540
540
$ notifications = Zend_Registry::get ('notifier ' )->callback (
541
541
'CALLBACK_CORE_AUTHENTICATION ' ,
542
542
array ('email ' => $ form ->getValue ('email ' ), 'password ' => $ form ->getValue ('password ' ))
@@ -545,6 +545,7 @@ public function loginAction()
545
545
$ this ->getLogger ()->crit ($ exc ->getMessage ());
546
546
}
547
547
$ authModule = false ;
548
+ $ userDao = false ;
548
549
foreach ($ notifications as $ user ) {
549
550
if ($ user ) {
550
551
$ userDao = $ user ;
@@ -585,6 +586,9 @@ public function loginAction()
585
586
} elseif (!$ authModule ) {
586
587
$ passwordHash = md5 ($ instanceSalt .$ form ->getValue ('password ' ));
587
588
$ coreAuth = $ this ->User ->legacyAuthenticate ($ userDao , $ instanceSalt , $ form ->getValue ('password ' ));
589
+ } else {
590
+ $ passwordHash = false ;
591
+ $ coreAuth = false ;
588
592
}
589
593
590
594
if ($ authModule || $ coreAuth ) {
@@ -603,30 +607,19 @@ public function loginAction()
603
607
) {
604
608
$ passwordHash = $ this ->User ->convertLegacyPasswordHash ($ userDao , $ form ->getValue ('password ' ));
605
609
}
606
- $ remember = $ form ->getValue ('remerberMe ' );
610
+
611
+ $ remember = (int ) $ form ->getValue ('remerberMe ' );
607
612
if (!$ this ->isTestingEnv ()) {
608
613
$ date = new DateTime ();
609
614
$ interval = new DateInterval ('P1M ' );
610
- if (!$ authModule && isset ($ remember ) && $ remember == 1 ) {
611
- setcookie (
612
- MIDAS_USER_COOKIE_NAME ,
613
- $ userDao ->getKey ().'- ' .$ passwordHash ,
614
- $ date ->add ($ interval )->getTimestamp (),
615
- '/ ' ,
616
- $ request ->getHttpHost (),
617
- (int ) Zend_Registry::get ('configGlobal ' )->get ('cookie_secure ' , 1 ) === 1 ,
618
- true
619
- );
615
+
616
+ if (!$ authModule && $ remember === 1 ) {
617
+ $ expires = $ date ->add ($ interval );
618
+ $ value = $ userDao ->getKey ().'- ' .$ passwordHash ;
619
+ UtilityComponent::setCookie ($ request , MIDAS_USER_COOKIE_NAME , $ value , $ expires );
620
620
} else {
621
- setcookie (
622
- MIDAS_USER_COOKIE_NAME ,
623
- null ,
624
- $ date ->sub ($ interval )->getTimestamp (),
625
- '/ ' ,
626
- $ request ->getHttpHost (),
627
- (int ) Zend_Registry::get ('configGlobal ' )->get ('cookie_secure ' , 1 ) === 1 ,
628
- true
629
- );
621
+ $ expires = $ date ->sub ($ interval );
622
+ UtilityComponent::setCookie ($ request , MIDAS_USER_COOKIE_NAME , false , $ expires );
630
623
Zend_Session::start ();
631
624
$ user = new Zend_Session_Namespace ('Auth_User ' );
632
625
$ user ->setExpirationSeconds (60 * (int ) Zend_Registry::get ('configGlobal ' )->get ('session_lifetime ' , 20 ));
@@ -1330,18 +1323,15 @@ public function deleteAction()
1330
1323
session_start ();
1331
1324
$ this ->userSession ->Dao = null ;
1332
1325
Zend_Session::ForgetMe ();
1326
+
1327
+ /** @var Zend_Controller_Request_Http $request */
1333
1328
$ request = $ this ->getRequest ();
1329
+
1334
1330
$ date = new DateTime ();
1335
1331
$ interval = new DateInterval ('P1M ' );
1336
- setcookie (
1337
- MIDAS_USER_COOKIE_NAME ,
1338
- null ,
1339
- $ date ->sub ($ interval )->getTimestamp (),
1340
- '/ ' ,
1341
- $ request ->getHttpHost (),
1342
- (int ) Zend_Registry::get ('configGlobal ' )->get ('cookie_secure ' , 1 ) === 1 ,
1343
- true
1344
- );
1332
+ $ expires = $ date ->sub ($ interval );
1333
+
1334
+ UtilityComponent::setCookie ($ request , MIDAS_USER_COOKIE_NAME , false , $ expires );
1345
1335
}
1346
1336
}
1347
1337
$ this ->_helper ->viewRenderer ->setNoRender ();
0 commit comments