forked from shoreless-ltd/tbg-oauth2-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Oauth2_gitlab.php
119 lines (99 loc) · 3.34 KB
/
Oauth2_gitlab.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace thebuggenie\modules\oauth2_gitlab;
use Omines\OAuth2\Client\Provider\GitlabResourceOwner;
use thebuggenie\core\entities\Module;
use thebuggenie\core\entities\tables\Users;
use thebuggenie\core\entities\User;
use thebuggenie\core\framework;
/**
* Autogenerated module Oauth2-GitLab
*
* @author
* @version 0.1
* @license http://opensource.org/licenses/MPL-2.0 Mozilla Public License 2.0 (MPL 2.0)
* @package oauth2-gitlab
* @subpackage core
*/
/**
* Autogenerated module Oauth2-gitlab
*
* @package oauth2-gitlab
* @subpackage core
*
* @Table(name="\thebuggenie\core\entities\tables\Modules")
*/
class Oauth2_gitlab extends Module
{
const VERSION = '1.0';
protected $_has_config_settings = true;
protected $_name = 'oauth2_gitlab';
protected $_longname = 'GitLab OAuth2 support';
protected $_description = 'Adds GitLab as an OAuth2 provider for user authentication and registration.';
protected $_module_config_title = 'GitLab OAuth2 settings';
protected $_module_config_description = 'Set up the Oauth2-gitlab module from this section';
/**
* Return an instance of this module
*
* @return Oauth2_gitlab
*/
public static function getModule()
{
return framework\Context::getModule('oauth2_gitlab');
}
protected function _initialize()
{
require THEBUGGENIE_MODULES_PATH . 'oauth2_gitlab' . DS . 'vendor' . DS . 'autoload.php';
}
protected function _addListeners()
{
framework\Event::listen('core', 'login_form_pane', array($this, 'listenLoginButtons'));
}
protected function _install($scope)
{
}
protected function _loadFixtures($scope)
{
}
protected function _uninstall()
{
}
public function getSettings()
{
return [
'domain' => $this->getSetting('domain'),
'client_id' => $this->getSetting('client_id'),
'client_secret' => $this->getSetting('client_secret'),
// 'btn_label' => $this->getSetting('btn_label'),
];
}
public function listenLoginButtons(framework\Event $event)
{
include_component('oauth2_gitlab/loginbutton');
}
public function getOrCreateUserByOwnerDetails(GitlabResourceOwner $ownerDetails)
{
$email = $ownerDetails->getEmail();
$user = Users::getTable()->getByEmail($email);
if (!$user instanceof User) {
$user = new User();
$user->setPassword(User::createPassword());
$user->setUsername($email);
$user->setRealname($ownerDetails->getName());
$user->setEmail($email);
$user->setOpenIdLocked();
$user->setActivated();
$user->setEnabled();
$user->setValidated();
$user->save();
}
return $user;
}
public function getFontAwesomeIcon()
{
return 'gitlab';
}
public function getFontAwesomeColor()
{
return '#555';
}
}