Skip to content

Commit 443e124

Browse files
committed
Adds social network login
1 parent b24e883 commit 443e124

22 files changed

+1094
-110
lines changed

composer.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
"doctrine/doctrine-orm-module": "dev-master",
66
"zendframework/zendframework": "master",
77
"org_heigl/contact" : "dev-master",
8-
"org_heigl/mailproxy" : "dev-master",
9-
"org_heigl/deploy" : "master"
8+
"org_heigl/mailproxy" : "dev-master",
9+
"org_heigl/hybridauth" : "dev-feature/multipleProviders"
10+
},
11+
"require-dev" : {
12+
"mockery/mockery": "dev-master"
13+
},
14+
"autoload" : {
15+
"psr-0" : {
16+
"Phpug\\" : "src/module/Phpug/src",
17+
"PhpugTest\\" : "src/module/Phpug/tests"
18+
}
1019
}
1120
}

composer.phar

245 KB
Binary file not shown.

src/module/Phpug/Module.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232

3333
namespace Phpug;
3434

35-
use Zend\Module\Manager,
36-
Zend\EventManager\StaticEventManager,
37-
Zend\Module\Consumer\AutoloaderProvider,
38-
Zend\Mvc\ModuleRouteListener;
35+
use Zend\Module\Manager;
36+
use Zend\Module\Consumer\AutoloaderProvider;
37+
use Zend\Mvc\ModuleRouteListener;
38+
use Zend\View\HelperPluginManager;
39+
3940

4041
/**
4142
* The Module-Provider
@@ -64,7 +65,30 @@ public function getConfig()
6465
{
6566
return include __DIR__ . '/config/module.config.php';
6667
}
67-
68+
public function getViewHelperConfig()
69+
{
70+
return array(
71+
'factories' => array(
72+
// This will overwrite the native navigation helper
73+
'navigation' => function(HelperPluginManager $pm) {
74+
// Setup ACL:
75+
$acl = $pm->getServiceLocator()->get('acl');
76+
$role = $pm->getServiceLocator()->get('roleManager');
77+
$role->setUserToken($pm->getServiceLocator()->get('OrgHeiglHybridAuthToken'));
78+
79+
// Get an instance of the proxy helper
80+
$navigation = $pm->get('Zend\View\Helper\Navigation');
81+
82+
// Store ACL and role in the proxy helper:
83+
$navigation->setAcl($acl)
84+
->setRole((string) $role);
85+
86+
// Return the new navigation helper instance
87+
return $navigation;
88+
}
89+
)
90+
);
91+
}
6892
public function getAutoloaderConfig()
6993
{
7094
return array(

src/module/Phpug/config/module.config.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,24 @@
172172
),
173173
),
174174
'service_manager' => array(
175-
'factories' => array(
176-
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
177-
),
175+
'factories' => array(
176+
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
177+
'acl' => 'Phpug\Service\AclFactory',
178+
'roleManager' => 'Phpug\Service\RoleManagerFactory',
179+
),
180+
'invokables' => array(
181+
'usersGroupAssertion' => 'Phpug\Acl\UsersGroupAssertion',
182+
),
178183
),
179184
'translator' => array(
180-
'locale' => 'en_US',
181-
'translation_patterns' => array(
182-
array(
183-
'type' => 'gettext',
184-
'base_dir' => __DIR__ . '/../language',
185-
'pattern' => '%s.mo',
186-
),
187-
),
185+
'locale' => 'en_US',
186+
'translation_patterns' => array(
187+
array(
188+
'type' => 'gettext',
189+
'base_dir' => __DIR__ . '/../language',
190+
'pattern' => '%s.mo',
191+
),
192+
),
188193
),
189194
'controllers' => array(
190195
'invokables' => array(
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright (c)2013-2013 heiglandreas
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIBILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
* @category
24+
* @author Andreas Heigl<[email protected]>
25+
* @copyright ©2013-2013 Andreas Heigl
26+
* @license http://www.opesource.org/licenses/mit-license.php MIT-License
27+
* @version 0.0
28+
* @since 07.10.13
29+
* @link https://github.com/heiglandreas/
30+
*/
31+
namespace Phpug\Acl;
32+
33+
return array(
34+
'acl' => array(
35+
'roles' => array(
36+
'guest' => null,
37+
'member' => 'guest',
38+
'admin' => null,
39+
),
40+
'resources' => array(
41+
'allow' => array(
42+
'all' => array(
43+
'all' => 'admin',
44+
),
45+
'ug' => array(
46+
'promote' => 'member',
47+
'edit' => array(
48+
'role' => 'member',
49+
'assert' => 'usersGroupAssertion',
50+
),
51+
'validatepromote' => 'member',
52+
'validateedit' => array(
53+
'role' => 'member',
54+
'assert' => 'usersGroupAssertion',
55+
),
56+
),
57+
),
58+
),
59+
'admins' => array(
60+
'twitter' => array(
61+
'heiglandreas',
62+
)
63+
),
64+
),
65+
);

src/module/Phpug/phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<directory suffix=".php">tests</directory>
2020
</blacklist>
2121
</filter>
22+
<listeners>
23+
<listener class="\Mockery\Adapter\Phpunit\TestListener"></listener>
24+
</listeners>
2225
<logging>
2326
<!--
2427
Adapt these paths to your special needs

src/module/Phpug/phpunit.xml.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
<group>disable</group>
1010
</exclude>
1111
</groups>
12-
12+
<listeners>
13+
<listener class="\Mockery\Adapter\Phpunit\TestListener"></listener>
14+
</listeners>
1315
<logging>
1416
<!--
1517
Adapt these paths to your special needs
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?php
2+
/**
3+
* Copyright (c)2013-2013 heiglandreas
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIBILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*
23+
* @category
24+
* @author Andreas Heigl<[email protected]>
25+
* @copyright ©2013-2013 Andreas Heigl
26+
* @license http://www.opesource.org/licenses/mit-license.php MIT-License
27+
* @version 0.0
28+
* @since 30.10.13
29+
* @link https://github.com/heiglandreas/
30+
*/
31+
32+
namespace Phpug\Acl;
33+
34+
35+
class RoleManager
36+
{
37+
/**
38+
* @var \OrgHeiglHybridAuth\UserTokenInterface $user
39+
*/
40+
protected $user = null;
41+
42+
/**
43+
* @var array $admins
44+
*/
45+
protected $admins = array();
46+
47+
/**
48+
* The default role
49+
*
50+
* @var string $defaultRole
51+
*/
52+
protected $defaultRole = 'guest';
53+
54+
/**
55+
* The role to be used for logged in users
56+
*
57+
* @var string $loggedInRole
58+
*/
59+
protected $loggedInRole = 'member';
60+
61+
/**
62+
* The role for admin-users
63+
*
64+
* @var string $adminRole
65+
*/
66+
protected $adminRole = 'admin';
67+
68+
/**
69+
* Set the current user
70+
*
71+
* @param \OrgHeiglHybridAuth\UserTokenInterface $user
72+
*
73+
* @return RoleManager
74+
*/
75+
public function setUserToken(\OrgHeiglHybridAuth\UserTokenInterface $user)
76+
{
77+
$this->user = $user;
78+
79+
return $this;
80+
}
81+
82+
/**
83+
* Set the default role
84+
*
85+
* @param string $defaultRole
86+
*/
87+
public function setDefaultRole($defaultRole)
88+
{
89+
$this->defaultRole = $defaultRole;
90+
91+
return $this;
92+
}
93+
94+
/**
95+
* Set the role for logged in users
96+
*
97+
* @param string $role
98+
*
99+
* @return RoleManager
100+
*/
101+
public function setLoggedInRole($role)
102+
{
103+
$this->loggedInRole = $role;
104+
105+
return $this;
106+
}
107+
108+
/**
109+
* Set the rolename for admin users
110+
*
111+
* @param string $role
112+
*
113+
* @return RoleManager
114+
*/
115+
public function setAdminRole($role)
116+
{
117+
$this->adminRole = $role;
118+
119+
return $this;
120+
}
121+
122+
/**
123+
* Set the Admin-users
124+
* The given array has to contain the service-name as key and an array with
125+
* usernames for that service as value
126+
*
127+
* @param array $admins
128+
*
129+
* @return RoleManager
130+
*/
131+
public function setAdmins(array $array)
132+
{
133+
$this->admins = $array;
134+
135+
return $this;
136+
}
137+
138+
/**
139+
* Get the role of the currently set user
140+
*
141+
* @return string
142+
*/
143+
public function getRole()
144+
{
145+
if (! $this->user->isAuthenticated()) {
146+
return $this->defaultRole;
147+
}
148+
149+
if (! array_key_Exists($this->user->getService(), $this->admins)) {
150+
return $this->loggedInRole;
151+
}
152+
153+
if (! in_array($this->user->getDisplayName(), $this->admins[$this->user->getService()])) {
154+
return $this->loggedInRole;
155+
}
156+
157+
return $this->adminRole;
158+
}
159+
160+
/**
161+
* Magic method to return the role.
162+
*
163+
* @return string
164+
*/
165+
public function __toString()
166+
{
167+
return $this->getRole();
168+
}
169+
170+
}

0 commit comments

Comments
 (0)