-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathUser.php
95 lines (85 loc) · 1.78 KB
/
User.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
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
<?php
/**
* @package ImpressPages
*
*
*/
namespace Ip;
/**
* Logging in a user and checking login status
*
*/
class User
{
/**
* Alias of isLoggedIn
* @private
* @return bool true if user is logged in
*/
function loggedIn()
{
return $this->isLoggedIn();
}
/**
* @return bool true if user is logged in
*/
function isLoggedIn()
{
return isset($_SESSION['ipUserId']);
}
/**
* Logout current user
* @return void
*/
function logout()
{
if (isset($_SESSION['ipUserId'])) {
ipEvent('ipBeforeUserLogout', array('userId' => $this->userId()));
unset($_SESSION['ipUserId']);
ipEvent('ipUserLogout', array('userId' => $this->userId()));
}
}
/**
* Get current user ID
* @return int Logged in user ID or false, if user is not logged in
*/
function userId()
{
if (isset($_SESSION['ipUserId'])) {
return $_SESSION['ipUserId'];
} else {
return false;
}
}
/**
* Set user as logged in
* @param int $id User id
* @return void
*/
function login($id)
{
ipEvent('ipUserLogin', array('userId' => $id));
$_SESSION['ipUserId'] = $id;
}
/**
* Get all user info collected from all user specific plugins.
* @param int $userId
* @return array
*/
function data($userId = null)
{
if ($userId === null) {
$userId = $this->userId();
}
if (!$userId) {
return array();
}
$info = array(
'userId' => $userId
);
$data = array(
'id' => $userId
);
return ipFilter('ipUserData', $data, $info);
}
}