forked from parse-community/parse-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseSession.php
More file actions
90 lines (81 loc) · 2.12 KB
/
Copy pathParseSession.php
File metadata and controls
90 lines (81 loc) · 2.12 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
<?php
namespace Parse;
/**
* ParseSession - Representation of an expiring user session.
*
* @author Fosco Marotto <fjm@fb.com>
*/
class ParseSession extends ParseObject
{
public static $parseClassName = '_Session';
private $_sessionToken = null;
/**
* Returns the session token string.
*
* @return string
*/
public function getSessionToken()
{
return $this->_sessionToken;
}
/**
* Retrieves the Session object for the currently logged in user.
*
* @param bool $useMasterKey If the Master Key should be used to override security.
*
* @return ParseSession
*/
public static function getCurrentSession($useMasterKey = false)
{
$token = ParseUser::getCurrentUser()->getSessionToken();
$response = ParseClient::_request(
'GET',
'sessions/me',
$token,
null,
$useMasterKey
);
$session = new self();
$session->_mergeAfterFetch($response);
$session->handleSaveResult();
return $session;
}
/**
* Determines whether the current session token is revocable.
* This method is useful for migrating an existing app to use
* revocable sessions.
*
* @return bool
*/
public static function isCurrentSessionRevocable()
{
$user = ParseUser::getCurrentUser();
if ($user) {
return self::_isRevocable($user->getSessionToken());
}
}
/**
* Determines whether a session token is revocable.
*
* @param string $token The session token to check
*
* @return bool
*/
public static function _isRevocable($token)
{
return strpos($token, 'r:') === 0;
}
/**
* After a save, perform Session object specific logic.
*
* @return null
*/
private function handleSaveResult()
{
if (isset($this->serverData['sessionToken'])) {
$this->_sessionToken = $this->serverData['sessionToken'];
unset($this->serverData['sessionToken']);
}
$this->rebuildEstimatedData();
}
}