Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
f06b5ab1
Commit
f06b5ab1
authored
Dec 20, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Widget "yii\authclient\widgets\Choice" fixed.
parent
722c93fc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
135 additions
and
52 deletions
+135
-52
ClientInterface.php
extensions/yii/authclient/ClientInterface.php
+6
-0
ClientTrait.php
extensions/yii/authclient/ClientTrait.php
+35
-1
GoogleOpenId.php
extensions/yii/authclient/clients/GoogleOpenId.php
+15
-0
YandexOpenId.php
extensions/yii/authclient/clients/YandexOpenId.php
+15
-0
Choice.php
extensions/yii/authclient/widgets/Choice.php
+39
-38
ClientTraitTest.php
tests/unit/extensions/authclient/ClientTraitTest.php
+25
-13
No files found.
extensions/yii/authclient/ClientInterface.php
View file @
f06b5ab1
...
@@ -49,4 +49,9 @@ interface ClientInterface
...
@@ -49,4 +49,9 @@ interface ClientInterface
* @return array list of user attributes
* @return array list of user attributes
*/
*/
public
function
getUserAttributes
();
public
function
getUserAttributes
();
/**
* @return array view options in format: optionName => optionValue
*/
public
function
getViewOptions
();
}
}
\ No newline at end of file
extensions/yii/authclient/ClientTrait.php
View file @
f06b5ab1
...
@@ -39,6 +39,10 @@ trait ClientTrait
...
@@ -39,6 +39,10 @@ trait ClientTrait
* @var array authenticated user attributes.
* @var array authenticated user attributes.
*/
*/
private
$_userAttributes
;
private
$_userAttributes
;
/**
* @var array view options in format: optionName => optionValue
*/
private
$_viewOptions
;
/**
/**
* @param string $id service id.
* @param string $id service id.
...
@@ -111,12 +115,31 @@ trait ClientTrait
...
@@ -111,12 +115,31 @@ trait ClientTrait
/**
/**
* @param array $userAttributes list of user attributes
* @param array $userAttributes list of user attributes
*/
*/
public
function
setUserAttributes
(
array
$userAttributes
)
public
function
setUserAttributes
(
$userAttributes
)
{
{
$this
->
_userAttributes
=
$userAttributes
;
$this
->
_userAttributes
=
$userAttributes
;
}
}
/**
/**
* @param array $viewOptions view options in format: optionName => optionValue
*/
public
function
setViewOptions
(
$viewOptions
)
{
$this
->
_viewOptions
=
$viewOptions
;
}
/**
* @return array view options in format: optionName => optionValue
*/
public
function
getViewOptions
()
{
if
(
$this
->
_viewOptions
===
null
)
{
$this
->
_viewOptions
=
$this
->
defaultViewOptions
();
}
return
$this
->
_viewOptions
;
}
/**
* Generates service name.
* Generates service name.
* @return string service name.
* @return string service name.
*/
*/
...
@@ -142,4 +165,14 @@ trait ClientTrait
...
@@ -142,4 +165,14 @@ trait ClientTrait
{
{
throw
new
NotSupportedException
(
'Method "'
.
get_class
(
$this
)
.
'::'
.
__FUNCTION__
.
'" not implemented.'
);
throw
new
NotSupportedException
(
'Method "'
.
get_class
(
$this
)
.
'::'
.
__FUNCTION__
.
'" not implemented.'
);
}
}
/**
* Returns the default [[viewOptions]] value.
* Particular client may override this method in order to provide specific default view options.
* @return array list of default [[viewOptions]]
*/
protected
function
defaultViewOptions
()
{
return
[];
}
}
}
\ No newline at end of file
extensions/yii/authclient/clients/GoogleOpenId.php
View file @
f06b5ab1
...
@@ -17,6 +17,9 @@ use yii\authclient\OpenId;
...
@@ -17,6 +17,9 @@ use yii\authclient\OpenId;
*/
*/
class
GoogleOpenId
extends
OpenId
class
GoogleOpenId
extends
OpenId
{
{
/**
* @inheritdoc
*/
public
function
init
()
public
function
init
()
{
{
parent
::
init
();
parent
::
init
();
...
@@ -28,4 +31,15 @@ class GoogleOpenId extends OpenId
...
@@ -28,4 +31,15 @@ class GoogleOpenId extends OpenId
'pref/language'
,
'pref/language'
,
];
];
}
}
/**
* @inheritdoc
*/
protected
function
defaultViewOptions
()
{
return
[
'popupWidth'
=>
880
,
'popupHeight'
=>
520
,
];
}
}
}
\ No newline at end of file
extensions/yii/authclient/clients/YandexOpenId.php
View file @
f06b5ab1
...
@@ -17,6 +17,9 @@ use yii\authclient\OpenId;
...
@@ -17,6 +17,9 @@ use yii\authclient\OpenId;
*/
*/
class
YandexOpenId
extends
OpenId
class
YandexOpenId
extends
OpenId
{
{
/**
* @inheritdoc
*/
public
function
init
()
public
function
init
()
{
{
parent
::
init
();
parent
::
init
();
...
@@ -26,4 +29,15 @@ class YandexOpenId extends OpenId
...
@@ -26,4 +29,15 @@ class YandexOpenId extends OpenId
'contact/email'
,
'contact/email'
,
];
];
}
}
/**
* @inheritdoc
*/
protected
function
defaultViewOptions
()
{
return
[
'popupWidth'
=>
900
,
'popupHeight'
=>
550
,
];
}
}
}
\ No newline at end of file
extensions/yii/authclient/widgets/Choice.php
View file @
f06b5ab1
...
@@ -10,12 +10,12 @@ namespace yii\authclient\widgets;
...
@@ -10,12 +10,12 @@ namespace yii\authclient\widgets;
use
yii\base\Widget
;
use
yii\base\Widget
;
use
Yii
;
use
Yii
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\authclient\
provider\Provider
Interface
;
use
yii\authclient\
Client
Interface
;
/**
/**
* Class Choice
* Class Choice
*
*
* @property
Provider
Interface[] $providers auth providers list.
* @property
Client
Interface[] $providers auth providers list.
* @property array $baseAuthUrl configuration for the external services base authentication URL.
* @property array $baseAuthUrl configuration for the external services base authentication URL.
*
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
...
@@ -24,28 +24,28 @@ use yii\authclient\provider\ProviderInterface;
...
@@ -24,28 +24,28 @@ use yii\authclient\provider\ProviderInterface;
class
Choice
extends
Widget
class
Choice
extends
Widget
{
{
/**
/**
* @var
Provider
Interface[] auth providers list.
* @var
Client
Interface[] auth providers list.
*/
*/
private
$_
provider
s
;
private
$_
client
s
;
/**
/**
* @var string name of the auth
provider
collection application component.
* @var string name of the auth
client
collection application component.
* This component will be used to fetch {@link services} value if it is not set.
* This component will be used to fetch {@link services} value if it is not set.
*/
*/
public
$
providerCollection
;
public
$
clientCollection
=
'auth'
;
/**
/**
* @var array configuration for the external
service
s base authentication URL.
* @var array configuration for the external
client
s base authentication URL.
*/
*/
private
$_baseAuthUrl
;
private
$_baseAuthUrl
;
/**
/**
* @var string name of the GET param , which should be used to passed auth
provider
id to URL
* @var string name of the GET param , which should be used to passed auth
client
id to URL
* defined by {@link baseAuthUrl}.
* defined by {@link baseAuthUrl}.
*/
*/
public
$
providerIdGetParamName
=
'provider
'
;
public
$
clientIdGetParamName
=
'client_id
'
;
/**
/**
* @var array the HTML attributes that should be rendered in the div HTML tag representing the container element.
* @var array the HTML attributes that should be rendered in the div HTML tag representing the container element.
*/
*/
public
$mainContainerHtmlOptions
=
[
public
$mainContainerHtmlOptions
=
[
'class'
=>
'
service
s'
'class'
=>
'
auth-client
s'
];
];
/**
/**
* @var boolean indicates if popup window should be used instead of direct links.
* @var boolean indicates if popup window should be used instead of direct links.
...
@@ -58,22 +58,22 @@ class Choice extends Widget
...
@@ -58,22 +58,22 @@ class Choice extends Widget
public
$autoRender
=
true
;
public
$autoRender
=
true
;
/**
/**
* @param
ProviderInterface[] $provider
s auth providers
* @param
ClientInterface[] $client
s auth providers
*/
*/
public
function
set
Providers
(
array
$provider
s
)
public
function
set
Clients
(
array
$client
s
)
{
{
$this
->
_
providers
=
$provider
s
;
$this
->
_
clients
=
$client
s
;
}
}
/**
/**
* @return
Provider
Interface[] auth providers
* @return
Client
Interface[] auth providers
*/
*/
public
function
get
Provider
s
()
public
function
get
Client
s
()
{
{
if
(
$this
->
_
provider
s
===
null
)
{
if
(
$this
->
_
client
s
===
null
)
{
$this
->
_
providers
=
$this
->
defaultProvider
s
();
$this
->
_
clients
=
$this
->
defaultClient
s
();
}
}
return
$this
->
_
provider
s
;
return
$this
->
_
client
s
;
}
}
/**
/**
...
@@ -96,14 +96,14 @@ class Choice extends Widget
...
@@ -96,14 +96,14 @@ class Choice extends Widget
}
}
/**
/**
* Returns default auth
provider
s list.
* Returns default auth
client
s list.
* @return
ProviderInterface[] auth provider
s list.
* @return
ClientInterface[] auth client
s list.
*/
*/
protected
function
default
Provider
s
()
protected
function
default
Client
s
()
{
{
/** @var $collection \yii\authclient\
provider\
Collection */
/** @var $collection \yii\authclient\Collection */
$collection
=
Yii
::
$app
->
getComponent
(
$this
->
provider
Collection
);
$collection
=
Yii
::
$app
->
getComponent
(
$this
->
client
Collection
);
return
$collection
->
get
Provider
s
();
return
$collection
->
get
Client
s
();
}
}
/**
/**
...
@@ -116,47 +116,48 @@ class Choice extends Widget
...
@@ -116,47 +116,48 @@ class Choice extends Widget
Yii
::
$app
->
controller
->
getRoute
()
Yii
::
$app
->
controller
->
getRoute
()
];
];
$params
=
$_GET
;
$params
=
$_GET
;
unset
(
$params
[
$this
->
provider
IdGetParamName
]);
unset
(
$params
[
$this
->
client
IdGetParamName
]);
$baseAuthUrl
=
array_merge
(
$baseAuthUrl
,
$params
);
$baseAuthUrl
=
array_merge
(
$baseAuthUrl
,
$params
);
return
$baseAuthUrl
;
return
$baseAuthUrl
;
}
}
/**
/**
* Outputs external service auth link.
* Outputs external service auth link.
* @param
ProviderInterface $service external auth service
instance.
* @param
ClientInterface $client external auth client
instance.
* @param string $text link text, if not set - default value will be generated.
* @param string $text link text, if not set - default value will be generated.
* @param array $htmlOptions link HTML options.
* @param array $htmlOptions link HTML options.
*/
*/
public
function
providerLink
(
$
service
,
$text
=
null
,
array
$htmlOptions
=
[])
public
function
providerLink
(
$
client
,
$text
=
null
,
array
$htmlOptions
=
[])
{
{
if
(
$text
===
null
)
{
if
(
$text
===
null
)
{
$text
=
Html
::
tag
(
'span'
,
[
'class'
=>
'auth-icon '
.
$service
->
getName
()],
''
);
$text
=
Html
::
tag
(
'span'
,
''
,
[
'class'
=>
'auth-icon '
.
$client
->
getName
()]
);
$text
.=
Html
::
tag
(
'span'
,
[
'class'
=>
'auth-title'
],
$service
->
getTitle
()
);
$text
.=
Html
::
tag
(
'span'
,
$client
->
getTitle
(),
[
'class'
=>
'auth-title'
]
);
}
}
if
(
!
array_key_exists
(
'class'
,
$htmlOptions
))
{
if
(
!
array_key_exists
(
'class'
,
$htmlOptions
))
{
$htmlOptions
[
'class'
]
=
'auth-link '
.
$
service
->
getName
();
$htmlOptions
[
'class'
]
=
'auth-link '
.
$
client
->
getName
();
}
}
if
(
$this
->
popupMode
)
{
if
(
$this
->
popupMode
)
{
if
(
isset
(
$service
->
popupWidth
))
{
$viewOptions
=
$client
->
getViewOptions
();
$htmlOptions
[
'data-popup-width'
]
=
$service
->
popupWidth
;
if
(
isset
(
$viewOptions
[
'popupWidth'
]))
{
$htmlOptions
[
'data-popup-width'
]
=
$viewOptions
[
'popupWidth'
];
}
}
if
(
isset
(
$
service
->
popupHeight
))
{
if
(
isset
(
$
viewOptions
[
'popupHeight'
]
))
{
$htmlOptions
[
'data-popup-height'
]
=
$
service
->
popupHeight
;
$htmlOptions
[
'data-popup-height'
]
=
$
viewOptions
[
'popupHeight'
]
;
}
}
}
}
echo
Html
::
a
(
$text
,
$this
->
createProviderUrl
(
$
service
),
$htmlOptions
);
echo
Html
::
a
(
$text
,
$this
->
createProviderUrl
(
$
client
),
$htmlOptions
);
}
}
/**
/**
* Composes external service auth URL.
* Composes external service auth URL.
* @param
Provider
Interface $provider external auth service instance.
* @param
Client
Interface $provider external auth service instance.
* @return string auth URL.
* @return string auth URL.
*/
*/
public
function
createProviderUrl
(
$provider
)
public
function
createProviderUrl
(
$provider
)
{
{
$this
->
autoRender
=
false
;
$this
->
autoRender
=
false
;
$url
=
$this
->
getBaseAuthUrl
();
$url
=
$this
->
getBaseAuthUrl
();
$url
[
$this
->
provider
IdGetParamName
]
=
$provider
->
getId
();
$url
[
$this
->
client
IdGetParamName
]
=
$provider
->
getId
();
return
Html
::
url
(
$url
);
return
Html
::
url
(
$url
);
}
}
...
@@ -166,7 +167,7 @@ class Choice extends Widget
...
@@ -166,7 +167,7 @@ class Choice extends Widget
protected
function
renderMainContent
()
protected
function
renderMainContent
()
{
{
echo
Html
::
beginTag
(
'ul'
,
[
'class'
=>
'auth-services clear'
]);
echo
Html
::
beginTag
(
'ul'
,
[
'class'
=>
'auth-services clear'
]);
foreach
(
$this
->
get
Provider
s
()
as
$externalService
)
{
foreach
(
$this
->
get
Client
s
()
as
$externalService
)
{
echo
Html
::
beginTag
(
'li'
,
[
'class'
=>
'auth-service'
]);
echo
Html
::
beginTag
(
'li'
,
[
'class'
=>
'auth-service'
]);
$this
->
providerLink
(
$externalService
);
$this
->
providerLink
(
$externalService
);
echo
Html
::
endTag
(
'li'
);
echo
Html
::
endTag
(
'li'
);
...
...
tests/unit/extensions/authclient/ClientTraitTest.php
View file @
f06b5ab1
...
@@ -26,33 +26,46 @@ class ClientTraitTest extends TestCase
...
@@ -26,33 +26,46 @@ class ClientTraitTest extends TestCase
public
function
testSetGet
()
public
function
testSetGet
()
{
{
$
provider
=
new
Client
();
$
client
=
new
Client
();
$id
=
'test_id'
;
$id
=
'test_id'
;
$
provider
->
setId
(
$id
);
$
client
->
setId
(
$id
);
$this
->
assertEquals
(
$id
,
$
provider
->
getId
(),
'Unable to setup id!'
);
$this
->
assertEquals
(
$id
,
$
client
->
getId
(),
'Unable to setup id!'
);
$name
=
'test_name'
;
$name
=
'test_name'
;
$
provider
->
setName
(
$name
);
$
client
->
setName
(
$name
);
$this
->
assertEquals
(
$name
,
$
provider
->
getName
(),
'Unable to setup name!'
);
$this
->
assertEquals
(
$name
,
$
client
->
getName
(),
'Unable to setup name!'
);
$title
=
'test_title'
;
$title
=
'test_title'
;
$provider
->
setTitle
(
$title
);
$client
->
setTitle
(
$title
);
$this
->
assertEquals
(
$title
,
$provider
->
getTitle
(),
'Unable to setup title!'
);
$this
->
assertEquals
(
$title
,
$client
->
getTitle
(),
'Unable to setup title!'
);
$userAttributes
=
[
'attribute1'
=>
'value1'
,
'attribute2'
=>
'value2'
,
];
$client
->
setUserAttributes
(
$userAttributes
);
$this
->
assertEquals
(
$userAttributes
,
$client
->
getUserAttributes
(),
'Unable to setup user attributes!'
);
$viewOptions
=
[
'option1'
=>
'value1'
,
'option2'
=>
'value2'
,
];
$client
->
setViewOptions
(
$viewOptions
);
$this
->
assertEquals
(
$viewOptions
,
$client
->
getViewOptions
(),
'Unable to setup view options!'
);
}
}
public
function
testGetDe
scriptiveData
()
public
function
testGetDe
faults
()
{
{
$provider
=
new
Client
();
$provider
=
new
Client
();
$this
->
assertNotEmpty
(
$provider
->
getName
(),
'Unable to get name!'
);
$this
->
assertNotEmpty
(
$provider
->
getName
(),
'Unable to get default name!'
);
$this
->
assertNotEmpty
(
$provider
->
getTitle
(),
'Unable to get title!'
);
$this
->
assertNotEmpty
(
$provider
->
getTitle
(),
'Unable to get default title!'
);
$this
->
assertNotNull
(
$provider
->
getViewOptions
(),
'Unable to get default view options!'
);
}
}
}
}
class
Client
extends
Object
implements
ClientInterface
class
Client
extends
Object
implements
ClientInterface
{
{
use
ClientTrait
;
use
ClientTrait
;
public
function
authenticate
()
{}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment