1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Social Login |
5
|
|
|
* @author Iurii Makukh |
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\social_login; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Module; |
13
|
|
|
use gplcart\core\models\Language as LanguageModel; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Main class for Social Login module |
17
|
|
|
*/ |
18
|
|
|
class SocialLogin extends Module |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Language model instance |
23
|
|
|
* @var \gplcart\core\models\Language $language |
24
|
|
|
*/ |
25
|
|
|
protected $language; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param LanguageModel $language |
29
|
|
|
*/ |
30
|
|
|
public function __construct(LanguageModel $language) |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
|
34
|
|
|
$this->language = $language; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Implements hook "module.install.before" |
39
|
|
|
*/ |
40
|
|
|
public function hookModuleInstallBefore(&$result) |
41
|
|
|
{ |
42
|
|
|
if (!function_exists('curl_init')) { |
43
|
|
|
$result = 'CURL library is not enabled'; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Implements hook "route.list" |
49
|
|
|
* @param array $routes |
50
|
|
|
*/ |
51
|
|
|
public function hookRouteList(array &$routes) |
52
|
|
|
{ |
53
|
|
|
$routes['admin/module/settings/social_login'] = array( |
54
|
|
|
'access' => 'module_edit', |
55
|
|
|
'handlers' => array( |
56
|
|
|
'controller' => array('gplcart\\modules\\social_login\\controllers\\Settings', 'editSettings') |
57
|
|
|
) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Implements hook "oauth.providers" |
63
|
|
|
* @param array $providers |
64
|
|
|
*/ |
65
|
|
|
public function hookOauthProviders(array &$providers) |
66
|
|
|
{ |
67
|
|
|
$settings = $this->config->module('social_login'); |
68
|
|
|
|
69
|
|
|
$providers['facebook'] = array( |
70
|
|
|
'name' => $this->language->text('Facebook'), |
71
|
|
|
'status' => !empty($settings['status']['facebook']), |
72
|
|
|
'type' => 'login', |
73
|
|
|
'scope' => 'email', |
74
|
|
|
'url' => array( |
75
|
|
|
'auth' => 'https://www.facebook.com/v2.8/dialog/oauth', |
76
|
|
|
'token' => 'https://graph.facebook.com/v2.8/oauth/access_token' |
77
|
|
|
), |
78
|
|
|
'settings' => array( |
79
|
|
|
'register' => $settings['register'], |
80
|
|
|
'register_login' => $settings['register_login'], |
81
|
|
|
'register_status' => $settings['register_status'], |
82
|
|
|
'client_id' => isset($settings['client_id']['facebook']) ? $settings['client_id']['facebook'] : '', |
83
|
|
|
'client_secret' => isset($settings['client_secret']['facebook']) ? $settings['client_secret']['facebook'] : '', |
84
|
|
|
), |
85
|
|
|
'template' => array('button' => 'social_login|buttons/facebook'), |
86
|
|
|
'handlers' => array( |
87
|
|
|
'process' => array('gplcart\\modules\\social_login\\handlers\\Facebook', 'process'), |
88
|
|
|
) |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$providers['google'] = array( |
92
|
|
|
'name' => $this->language->text('Google+'), |
93
|
|
|
'type' => 'login', |
94
|
|
|
'scope' => 'email', |
95
|
|
|
'status' => !empty($settings['status']['google']), |
96
|
|
|
'url' => array( |
97
|
|
|
'auth' => 'https://accounts.google.com/o/oauth2/auth', |
98
|
|
|
'token' => 'https://accounts.google.com/o/oauth2/token' |
99
|
|
|
), |
100
|
|
|
'settings' => array( |
101
|
|
|
'register' => $settings['register'], |
102
|
|
|
'register_login' => $settings['register_login'], |
103
|
|
|
'register_status' => $settings['register_status'], |
104
|
|
|
'client_id' => isset($settings['client_id']['google']) ? $settings['client_id']['google'] : '', |
105
|
|
|
'client_secret' => isset($settings['client_secret']['google']) ? $settings['client_secret']['google'] : '', |
106
|
|
|
), |
107
|
|
|
'template' => array('button' => 'social_login|buttons/google'), |
108
|
|
|
'handlers' => array( |
109
|
|
|
'process' => array('gplcart\\modules\\social_login\\handlers\\Google', 'process'), |
110
|
|
|
) |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|