-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.driver.php
99 lines (88 loc) · 2.7 KB
/
extension.driver.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
96
97
98
99
<?php
/**
* Copyright: Symphony Community 2018
* License: MIT, see the LICENSE file
*/
if (!defined("__IN_SYMPHONY__")) die("<h2>Error</h2><p>You cannot directly access this file</p>");
class extension_members_login_oauth2 extends Extension
{
/**
* Name of the extension
* @var string
*/
const EXT_NAME = 'Members: oAuth 2 Login';
/* ********* INSTALL/UPDATE/UNISTALL ******* */
protected function checkDependency($depname)
{
$status = ExtensionManager::fetchStatus(array('handle' => $depname));
$status = current($status);
if ($status != EXTENSION_ENABLED) {
Administration::instance()->Page->pageAlert("Could not load `$depname` extension.", Alert::ERROR);
return false;
}
return true;
}
protected function checkDependencyVersion($depname, $version)
{
$installedVersion = ExtensionManager::fetchInstalledVersion($depname);
if (version_compare($installedVersion, $version) == -1) {
Administration::instance()->Page->pageAlert("Extension `$depname` must have version $version or newer.", Alert::ERROR);
return false;
}
return true;
}
/**
* Creates the table needed for the settings of the field
*/
public function install()
{
// depends on "members"
if (!$this->checkDependencyVersion('members', '1.9.0')) {
return false;
}
return true;
}
/**
* Creates the table needed for the settings of the field
*/
public function update($previousVersion = false)
{
$ret = true;
return $ret;
}
/**
*
* Drops the table needed for the settings of the field
*/
public function uninstall()
{
return true;
}
/*------------------------------------------------------------------------------------------------*/
/* Delegates */
/*------------------------------------------------------------------------------------------------*/
public function getSubscribedDelegates()
{
return array(
array(
'page' => '/frontend/',
'delegate' => 'MembersLogin',
'callback' => 'membersLogin'
),
);
}
public function membersLogin(array $context)
{
if ($context['is-logged-in']) {
return;
}
if ($_SESSION['OAUTH_SERVICE'] !== 'oauth2') {
return;
}
if (empty($_SESSION['OAUTH_MEMBER_ID'])) {
return;
}
$context['is-logged-in'] = $_SESSION['OAUTH_TIMESTAMP'] + TWO_WEEKS > time();
$context['member_id'] = $_SESSION['OAUTH_MEMBER_ID'];
}
}