Skip to content

Commit db2f9f3

Browse files
Update handlers.php
1 parent 2b49dbb commit db2f9f3

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

controllers/handlers.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,29 @@ final class LoginHandler extends Base
798798
*/
799799

800800
use validLogin, validPassword;
801+
802+
/**
803+
* @param array $post is users input
804+
*
805+
* @return void
806+
*/
807+
public function __construct( $post, $id )
808+
{
809+
parent::__construct( $post );
810+
811+
/**
812+
* @var object
813+
*/
814+
$this->user = R::findOne( 'users', 'login = ?', array( $this->login ) );
815+
816+
if ( !$this->user )
817+
{
818+
$this->user = R::findOne( 'users', 'email = ?', array( $this->login ) );
819+
} else
820+
{
821+
$this->errors[] = array( 'User not found!' );
822+
}
823+
}
801824

802825
/**
803826
* Checking login for valid and commit errors, if any.
@@ -814,28 +837,11 @@ public function isValid()
814837
$this->errors[] = self::isLogin( $this->login );
815838
}
816839

817-
$user = R::findOne( 'users', 'login = ?', array( $this->login ) );
818-
if ( !$user )
819-
{
820-
$user = R::findOne( 'users', 'email = ?', array( $this->login ) );
821-
}
822-
823840
if ( self::isPassword( $this->password ) )
824841
{
825842
$this->errors[] = self::isPassword( $this->password );
826843
}
827844

828-
if ( $user )
829-
{
830-
if ( !password_verify( $this->password, $user->password ) )
831-
{
832-
$this->errors[] = array( 'Password is incorrect!' );
833-
}
834-
} else
835-
{
836-
$this->errors[] = array( 'User not found!' );
837-
}
838-
839845
return $this->errors;
840846
}
841847

@@ -846,7 +852,7 @@ public function isValid()
846852
*/
847853
protected function showSuccess( $template )
848854
{
849-
$_SESSION['user'] = $user;
855+
$_SESSION['user'] = $this->user;
850856

851857
load_template( $template, array(
852858
'message_color' => 'green',

0 commit comments

Comments
 (0)