Last active
May 15, 2020 07:04
-
-
Save harryWonder/021e34c23dedac23fa148aaa22272423 to your computer and use it in GitHub Desktop.
This file loads in the LoginModel Controller and it also extends the base controller.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once(__dir__ . '/Controller.php'); | |
require_once('./Model/LoginModel.php'); | |
class Login extends Controller { | |
public $active = 'login'; //for highlighting the active link... | |
private $loginModel; | |
/** | |
* @param null|void | |
* @return null|void | |
* @desc Checks if the user session is set and creates a new instance of the LoginModel... | |
**/ | |
public function __construct() | |
{ | |
if (isset($_SESSION['auth_status'])) header("Location: dashboard.php"); | |
$this->loginModel = new LoginModel(); | |
} | |
/** | |
* @param array | |
* @return array|boolean | |
* @desc Verifies and redirects a user by calling the login method on the LoginModel... | |
**/ | |
public function login(array $data) | |
{ | |
$email = stripcslashes(strip_tags($data['email'])); | |
$password = stripcslashes(strip_tags($data['password'])); | |
$EmailRecords = $this->loginModel->fetchEmail($email); | |
if (!$EmailRecords['status']) { | |
if (password_verify($password, $EmailRecords['data']['password'])) { | |
//check if the remember_me was selected... | |
$Response = array( | |
'status' => true | |
); | |
$_SESSION['data'] = $EmailRecords['data']; | |
$_SESSION['auth_status'] = true; | |
header("Location: dashboard.php"); | |
} | |
$Response = array( | |
'status' => false, | |
); | |
return $Response; | |
} | |
$Response = array( | |
'status' => false, | |
); | |
return $Response; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment