/
AuthHelper.php
42 lines (33 loc) · 945 Bytes
/
AuthHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace App\Helper;
use \App\Database\StudentDataGateway;
class AuthHelper {
private $dataGateway;
public function __construct(StudentDataGateway $dataGateway) {
$this->dataGateway = $dataGateway;
}
public function getAuthorizedStudent() {
if(isset($_COOKIE['auth'])) {
$student = $this->dataGateway->selectStudent($_COOKIE['auth']);
if($student->id != null) {
return $student;
}
}
return false;
}
public function isAuthorized() {
if(isset($_COOKIE['auth'])) {
return true;
}
return false;
}
public function authorizeStudent() {
$generator = new TokenGenerator();
$token = $generator->generateToken(45);
setcookie("auth", $token, time()+36000000);
return $token;
}
public function logOut() {
setcookie('auth', null, -1);
}
}