2021-03-09 12:29:49 +00:00
|
|
|
<?php
|
2021-03-12 10:10:14 +00:00
|
|
|
require_once (realpath(dirname(__FILE__) ."/../../../bootstrap.php"));
|
2021-03-09 12:29:49 +00:00
|
|
|
|
|
|
|
use Backend\Models\Group;
|
|
|
|
use Backend\Models\Password;
|
2021-03-11 12:21:16 +00:00
|
|
|
session_start();
|
2021-03-09 12:29:49 +00:00
|
|
|
|
2021-03-25 09:28:56 +00:00
|
|
|
|
2021-03-09 12:29:49 +00:00
|
|
|
/**
|
|
|
|
* @param string $token
|
2021-03-11 08:28:30 +00:00
|
|
|
* @return Group|null ;
|
2021-03-09 12:29:49 +00:00
|
|
|
*/
|
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
function groupViaToken(string $token): ?Group
|
|
|
|
{
|
2021-03-09 12:29:49 +00:00
|
|
|
|
2021-03-09 13:43:39 +00:00
|
|
|
if($password = Password::firstWhere('remember_token', $token)){
|
|
|
|
return Group::find($password->group_id);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-03-11 08:28:30 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-03-12 10:10:14 +00:00
|
|
|
function isLogin(): bool
|
|
|
|
{
|
2021-03-09 13:43:39 +00:00
|
|
|
return isset($_SESSION["token"]);
|
2021-03-11 08:28:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $password1
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-03-12 10:10:14 +00:00
|
|
|
function passwordValidate(string $password1): bool
|
|
|
|
{
|
2021-03-11 08:28:30 +00:00
|
|
|
$uppercase = preg_match('@[A-Z]@', $password1);
|
|
|
|
$lowercase = preg_match('@[a-z]@', $password1);
|
|
|
|
$number = preg_match('@[0-9]@', $password1);
|
|
|
|
$specialChars = preg_match('@[^\w]@', $password1);
|
|
|
|
|
2021-03-12 10:10:14 +00:00
|
|
|
if(!$uppercase || !$lowercase || !$number || !$specialChars || (strlen($password1) >= 8 && strlen($password1) <= 255) ) {
|
2021-03-11 08:28:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-03-12 10:10:14 +00:00
|
|
|
else return false;
|
2021-03-25 08:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function makeLogin(string $groupName, int $groupId)
|
|
|
|
{
|
2021-03-25 09:28:56 +00:00
|
|
|
$cookieCon = array(
|
|
|
|
'expires' => 0,
|
|
|
|
'samesite' => 'Strict',
|
|
|
|
'path' => '/'
|
|
|
|
);
|
|
|
|
setcookie("groupName", $groupName, $cookieCon);
|
|
|
|
setcookie("groupId", $groupId, $cookieCon);
|
2021-03-09 12:29:49 +00:00
|
|
|
}
|