Game-Jaming/Backend/Controllers/Admin/AdminLogin.php

36 lines
940 B
PHP
Raw Normal View History

2021-03-09 09:45:05 +00:00
<?php
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();
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;
$_SESSION['admin'] = true;
2021-03-09 09:45:05 +00:00
$_SESSION['success'] = "You are now logged in";
2021-03-23 12:39:44 +00:00
http_response_code(200);
2021-03-09 09:45:05 +00:00
}else{
session_destroy();
2021-03-23 12:39:44 +00:00
http_response_code(401);
echo json_encode(["message" => "wrong password"]);
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-23 12:39:44 +00:00
http_response_code(401);
echo json_encode(["message" => "admin don't exist"]);
2021-03-09 09:45:05 +00:00
}
2021-03-17 08:43:09 +00:00
}else{
2021-03-23 12:39:44 +00:00
http_response_code(400);
2021-03-09 09:45:05 +00:00
}