You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.4 KiB
PHP

<?php
# Checks the uniqueId exists, if so create cookie and redirect
function userLogin(string $username, string $password){
require_once('./repository/userRepository.php');
// If correct credentials, add cookie and redirect
$uniqueId = isUserCorrect($conn, $username, $password);
if ($uniqueId === NULL or $uniqueId === ""){
$notification = [
"type" => "error",
"message" => "Something went wrong! The admin has been informed"
];
}elseif ($uniqueId === false){
$notification = [
"type" => "alert",
"message" => "Login details incorrect; Try again"
];
}else{
// 1 hour cookie to store userLogged username
setcookie("userLogged", $uniqueId, time()+3600);
// Needed as new cookies aren't checked until page reload
header("Location: ./profile.php");
die();
}
return $notification;
}
function userLogged(){
if (isset($_COOKIE['userLogged']) and $_COOKIE['userLogged']){
// User is loged in, redirect to profile
echo('test userLogged');
$url = "/profile.php";
header("Location: ".$url);
die();
}
}
# If the user account can access the page.
# username/uniqueId
# permissionRequired
function userPermissed(){
}
function logOut(){
if (isset($_COOKIE['userLogged'])) {
unset($_COOKIE['userLogged']);
setcookie('userLogged', null, -1, '/');
return true;
} else {
return false;
}
header("Location: /");
die();
}
?>