-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSession.php
More file actions
101 lines (87 loc) · 2.16 KB
/
Session.php
File metadata and controls
101 lines (87 loc) · 2.16 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* Definition of Session.php
*
* @copyright 2015-today Justso GmbH
* @author j.schirrmacher@justso.de
*/
namespace justso\justauth;
use justso\justapi\SystemEnvironmentInterface;
/**
* Class Session
*/
class Session
{
/**
* @var SystemEnvironmentInterface
*/
private $env;
/**
* Current user
*
* @var UserInterface
*/
private $user = null;
/**
* Indicates that the current user has just registered and has not yet activated the account
* @var bool
*/
private $justRegistered = null;
/**
* Indicates that the user object comes from the session and is therefore a clone of the 'real' user.
*
* @var bool
*/
private $isCloned;
public function __construct(SystemEnvironmentInterface $env)
{
$this->env = $env;
/** @var \justso\justapi\Session $session */
$session = $this->env->getSession();
if ($session->isValueSet('user')) {
$this->user = $session->getValue('user');
$this->justRegistered = $session->getValue('justRegistered');
$this->isCloned = true;
}
}
public function loginUser(UserInterface $user, $justRegistered = false)
{
$this->user = $user;
$this->justRegistered = $justRegistered;
$session = $this->env->getSession();
$session->setValue('user', $user);
$session->setValue('justRegistered', $justRegistered);
$this->isCloned = false;
}
public function logoutCurrentUser()
{
$session = $this->env->getSession();
$session->unsetValue('user');
$session->unsetValue('justRegistered');
$this->justRegistered = null;
$this->user = null;
}
/**
* @return UserInterface
*/
public function getCurrentUser()
{
return $this->user;
}
/**
* Checks if a user is logged in
* @return bool
*/
public function isAuth()
{
return $this->user !== null;
}
public function hasJustRegistered()
{
return $this->justRegistered;
}
public function isCloned()
{
return $this->isCloned;
}
}