2021-03-09 09:45:05 +00:00
|
|
|
<?php
|
2021-03-11 08:28:30 +00:00
|
|
|
require_once "../../../bootstrap.php";
|
|
|
|
require_once "Admin.php";
|
2021-03-09 09:45:05 +00:00
|
|
|
|
|
|
|
use Backend\Models\AdminUser;
|
|
|
|
|
|
|
|
//Start the php session
|
|
|
|
session_start();
|
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
if(isset($_POST['aLogin'])){
|
2021-03-09 09:45:05 +00:00
|
|
|
|
|
|
|
$userName = $_POST["userName"];
|
|
|
|
$password = $_POST["password"];
|
|
|
|
|
|
|
|
$user = AdminUser::firstWhere('user_name', $userName );
|
|
|
|
if($user){
|
|
|
|
$hashedPassword = $user->password;
|
|
|
|
if(password_verify($password, $hashedPassword )){
|
|
|
|
$_SESSION['userName'] = $userName;
|
2021-03-11 08:28:30 +00:00
|
|
|
$_SESSION['admin'] = true;
|
2021-03-09 09:45:05 +00:00
|
|
|
$_SESSION['success'] = "You are now logged in";
|
2021-03-22 08:43:33 +00:00
|
|
|
echo http_response_code(200);
|
2021-03-09 09:45:05 +00:00
|
|
|
}else{
|
|
|
|
session_destroy();
|
2021-03-19 12:25:27 +00:00
|
|
|
echo "Fail to verify password";
|
2021-03-22 08:43:33 +00:00
|
|
|
echo http_response_code(401);
|
2021-03-09 09:45:05 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 08:43:09 +00:00
|
|
|
}else{
|
2021-03-09 09:45:05 +00:00
|
|
|
session_destroy();
|
2021-03-19 12:25:27 +00:00
|
|
|
echo "No user";
|
2021-03-22 08:43:33 +00:00
|
|
|
echo http_response_code(401);
|
2021-03-09 09:45:05 +00:00
|
|
|
}
|
2021-03-17 08:43:09 +00:00
|
|
|
}else{
|
2021-03-22 08:43:33 +00:00
|
|
|
echo http_response_code(400);
|
2021-03-09 09:45:05 +00:00
|
|
|
}
|