-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPlugin.php
99 lines (81 loc) · 3.54 KB
/
Plugin.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
namespace Kanboard\Plugin\GoogleAuth;
use Kanboard\Core\Plugin\Base;
use Kanboard\Core\Security\AuthenticationManager;
use Kanboard\Core\Translator;
use Kanboard\Core\Security\Role;
use Kanboard\Event\AuthSuccessEvent;
use Kanboard\Plugin\GoogleAuth\Auth\GoogleAuthProvider;
use Kanboard\Plugin\GoogleAuth\User\Avatar\GoogleAvatarProvider;
class Plugin extends Base
{
public function initialize()
{
$this->dispatcher->addListener(AuthenticationManager::EVENT_SUCCESS, array($this, 'onLoginSuccess'));
$this->authenticationManager->register(new GoogleAuthProvider($this->container));
$this->applicationAccessMap->add('OAuthController', 'handler', Role::APP_PUBLIC);
$this->avatarManager->register(new GoogleAvatarProvider($this->container));
$this->route->addRoute('/oauth/google', 'OAuthController', 'handler', 'GoogleAuth');
$this->template->hook->attach('template:auth:login-form:after', 'GoogleAuth:auth/login');
$this->template->hook->attach('template:config:integrations', 'GoogleAuth:config/integration');
$this->template->hook->attach('template:user:external', 'GoogleAuth:user/external');
$this->template->hook->attach('template:user:integrations', 'GoogleAuth:user/integrations');
$this->template->hook->attach('template:user:authentication:form', 'GoogleAuth:user/authentication');
$this->template->hook->attach('template:user:create-remote:form', 'GoogleAuth:user/create_remote');
}
public function onStartup()
{
Translator::load($this->languageModel->getCurrentLanguage(), __DIR__.'/Locale');
}
public function onLoginSuccess(AuthSuccessEvent $event)
{
if ($event->getAuthType() === 'Google') {
/** @var GoogleAuthProvider */
$provider = $this->authenticationManager->getProvider($event->getAuthType());
$avatar_url = $provider->getUser()->getAvatarUrl();
$user_id = $this->userSession->getId();
if (! empty($avatar_url)) {
$options = array('google_avatar_url' => $avatar_url);
if (! $this->userMetadataModel->exists($user_id, 'google_show_avatar')) {
$options['google_show_avatar'] = 1;
}
$this->userMetadataModel->save($user_id, $options);
}
$signup_groups = $provider->getGoogleSignupGroups();
$user_groups = array_column($this->groupMemberModel->getGroups($user_id), 'id', 'id');
if (!empty($signup_groups) && !is_null($signup_groups)) {
$signup_groups = array_map('trim', explode(',', $signup_groups));
$groups = $this->groupModel->getQuery()->in('name', $signup_groups)->findAll();
foreach ($groups as $signup_group) {
if (!isset($user_groups[$signup_group['id']])) {
$this->groupMemberModel->addUser($signup_group['id'], $user_id);
}
}
}
}
}
public function getPluginName()
{
return 'Google Authentication';
}
public function getPluginDescription()
{
return t('Use Google as authentication provider');
}
public function getPluginAuthor()
{
return 'Frédéric Guillot';
}
public function getPluginVersion()
{
return '1.0.8';
}
public function getPluginHomepage()
{
return 'https://github.com/kanboard/plugin-google-auth';
}
public function getCompatibleVersion()
{
return '>=1.0.37';
}
}