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

36 lines
931 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-12 10:10:14 +00:00
header('location: ../../../Frontend/index.php?login=success');
2021-03-09 09:45:05 +00:00
}else{
session_destroy();
2021-03-12 10:10:14 +00:00
header('location: ../../../Frontend/index.php?login=failed?reason=password');
2021-03-09 09:45:05 +00:00
}
}
else{
session_destroy();
2021-03-12 10:10:14 +00:00
header('location: ../../../Frontend/index.php?login=failed?reason=username');
2021-03-09 09:45:05 +00:00
}
}