Skip to content

Commit cef91fb

Browse files
Init project
0 parents  commit cef91fb

12 files changed

Lines changed: 487 additions & 0 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CHANGELOG
2+
==============
3+
4+
1.0.0-alpha
5+
-----------------
6+
* Can be used

CmsAuthClientCollection.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* @author Semenov Alexander <[email protected]>
4+
* @link http://skeeks.com/
5+
* @copyright 2010 SkeekS (СкикС)
6+
* @date 15.04.2016
7+
*/
8+
namespace skeeks\cms\authclient;
9+
use yii\helpers\ArrayHelper;
10+
/**
11+
* Class CmsAuthClientCollection
12+
* @package skeeks\cms\authclient
13+
*/
14+
class CmsAuthClientCollection extends \yii\authclient\Collection
15+
{
16+
public function init()
17+
{
18+
parent::init();
19+
20+
if (\Yii::$app->authClientSettings && \Yii::$app->authClientSettings->enabled === false)
21+
{
22+
return;
23+
}
24+
25+
$this->clients = \Yii::$app->authClientSettings->clients;
26+
}
27+
}

CmsAuthClientModule.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* @author Semenov Alexander <[email protected]>
4+
* @link http://skeeks.com/
5+
* @copyright 2010 SkeekS (СкикС)
6+
* @date 15.04.2016
7+
*/
8+
namespace skeeks\cms\authclient;
9+
/**
10+
* Class CmsAuthClientModule
11+
* @package skeeks\cms\authclient
12+
*/
13+
class CmsAuthClientModule extends \skeeks\cms\base\Module
14+
{
15+
public $controllerNamespace = 'skeeks\cms\authclient\controllers';
16+
}

CmsAuthClientSettings.php

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
<?php
2+
/**
3+
* @author Semenov Alexander <[email protected]>
4+
* @link http://skeeks.com/
5+
* @copyright 2010 SkeekS (СкикС)
6+
* @date 31.07.2015
7+
*/
8+
namespace skeeks\cms\authclient;
9+
10+
use skeeks\cms\components\Cms;
11+
use yii\helpers\ArrayHelper;
12+
use yii\widgets\ActiveForm;
13+
14+
/**
15+
* @property array $clients
16+
* Class AuthClientSettings
17+
* @package skeeks\cms\authclient
18+
*/
19+
class CmsAuthClientSettings extends \skeeks\cms\base\Component
20+
{
21+
22+
public $enabled = false;
23+
24+
//Настройки для гитхаба
25+
public $githubEnabled = true;
26+
public $githubClientId = '';
27+
public $githubClientSecret = '';
28+
public $githubClass = '';
29+
30+
//Настройки для vk
31+
public $vkEnabled = true;
32+
public $vkClientId = '';
33+
public $vkClientSecret = '';
34+
public $vkClass = '';
35+
36+
//Настройки для facebook
37+
public $facebookEnabled = true;
38+
public $facebookClientId = '';
39+
public $facebookClientSecret = '';
40+
public $facebookClass = '';
41+
42+
/**
43+
* Можно задать название и описание компонента
44+
* @return array
45+
*/
46+
static public function descriptorConfig()
47+
{
48+
return array_merge(parent::descriptorConfig(), [
49+
'name' => \Yii::t('skeeks/authclient', 'Authorization through social networks'),
50+
]);
51+
}
52+
53+
public function renderConfigForm(ActiveForm $form)
54+
{
55+
echo \Yii::$app->view->renderFile(__DIR__ . '/_settingsFrom.php', [
56+
'form' => $form,
57+
'model' => $this
58+
], $this);
59+
}
60+
61+
62+
public function rules()
63+
{
64+
return ArrayHelper::merge(parent::rules(), [
65+
[['enabled'], 'boolean'],
66+
67+
[['githubEnabled'], 'boolean'],
68+
[['githubClientId'], 'string'],
69+
[['githubClientSecret'], 'string'],
70+
[['githubClass'], 'string'],
71+
72+
[['vkEnabled'], 'boolean'],
73+
[['vkClientId'], 'integer'],
74+
[['vkClientSecret'], 'string'],
75+
[['vkClass'], 'string'],
76+
77+
[['facebookEnabled'], 'boolean'],
78+
[['facebookClientId'], 'integer'],
79+
[['facebookClientSecret'], 'string'],
80+
[['facebookClass'], 'string'],
81+
]);
82+
}
83+
84+
/**
85+
* @return array
86+
*/
87+
public function attributeLabels()
88+
{
89+
return ArrayHelper::merge(parent::attributeLabels(), [
90+
'enabled' => \Yii::t('app','Enable'),
91+
92+
'githubEnabled' => \Yii::t('app','Enable authorization through {github}',['github' => 'GitHub']),
93+
'githubClientId' => 'clientId',
94+
'githubClientSecret' => 'clientSecret',
95+
'githubClass' => \Yii::t('app','Handler'),
96+
97+
'vkEnabled' => 'Включить авторизацию через vk',
98+
'vkClientId' => 'clientId',
99+
'vkClientSecret' => 'clientSecret',
100+
'vkClass' => 'Обработчик',
101+
102+
'facebookEnabled' => 'Включить авторизацию через facebook',
103+
'facebookClientId' => 'clientId',
104+
'facebookClientSecret' => 'clientSecret',
105+
'facebookClass' => 'Обработчик',
106+
]);
107+
}
108+
109+
110+
/**
111+
*
112+
* Инициализация гитхаб провайдера
113+
*
114+
* @param array $data
115+
* @return $this
116+
*/
117+
protected function _initGitHubData(&$data = [])
118+
{
119+
if ($this->githubEnabled && $this->githubClientId && $this->githubClientSecret)
120+
{
121+
$data['github'] = [
122+
'class' => $this->githubClass ? $this->githubClass : 'yii\authclient\clients\GitHub',
123+
'clientId' => $this->githubClientId,
124+
'clientSecret' => $this->githubClientSecret,
125+
];
126+
}
127+
128+
return $this;
129+
}
130+
131+
132+
/**
133+
*
134+
* Инициализация гитхаб провайдера
135+
*
136+
* @param array $data
137+
* @return $this
138+
*/
139+
protected function _initVkData(&$data = [])
140+
{
141+
if ($this->vkEnabled && $this->vkClientId && $this->vkClientSecret)
142+
{
143+
$data['vkontakte'] = [
144+
'class' => $this->vkClass ? $this->vkClass : 'yii\authclient\clients\VKontakte',
145+
'clientId' => $this->vkClientId,
146+
'clientSecret' => $this->vkClientSecret,
147+
];
148+
}
149+
150+
return $this;
151+
}
152+
/**
153+
*
154+
* Инициализация гитхаб провайдера
155+
*
156+
* @param array $data
157+
* @return $this
158+
*/
159+
protected function _initFacebookData(&$data = [])
160+
{
161+
if ($this->vkEnabled && $this->vkClientId && $this->vkClientSecret)
162+
{
163+
$data['facebook'] = [
164+
'class' => $this->facebookClass ? $this->facebookClass : 'yii\authclient\clients\Facebook',
165+
'clientId' => $this->facebookClientId,
166+
'clientSecret' => $this->facebookClientSecret,
167+
];
168+
}
169+
170+
return $this;
171+
}
172+
173+
/**
174+
* @return array
175+
*/
176+
public function getClients()
177+
{
178+
$result = [];
179+
180+
$this->_initGitHubData($result);
181+
$this->_initVkData($result);
182+
$this->_initFacebookData($result);
183+
184+
return $result;
185+
}
186+
}

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Authorization by social networks for SkeekS CMS
2+
===================================
3+
4+
Installation
5+
------------
6+
7+
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
8+
9+
Either run
10+
11+
```
12+
php composer.phar require --prefer-dist skeeks/cms-authclient "*"
13+
```
14+
15+
or add
16+
17+
```
18+
"skeeks/cms-authclient": "*"
19+
```
20+
21+
Configuration app
22+
----------
23+
24+
```php
25+
26+
```
27+
28+
___
29+
30+
> [![skeeks!](https://gravatar.com/userimage/74431132/13d04d83218593564422770b616e5622.jpg)](http://skeeks.com)
31+
<i>SkeekS CMS (Yii2) — quickly, easily and effectively!</i>
32+
[skeeks.com](http://skeeks.com) | [en.cms.skeeks.com](http://en.cms.skeeks.com) | [cms.skeeks.com](http://cms.skeeks.com) | [marketplace.cms.skeeks.com](http://marketplace.cms.skeeks.com)
33+
34+

_ide/YiiApplication.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
*
4+
* The pseudo-only IDE tips
5+
*
6+
* @author Semenov Alexander <[email protected]>
7+
* @link http://skeeks.com/
8+
* @copyright 2010 SkeekS (СкикС)
9+
* @date 10.09.2015
10+
*/
11+
namespace yii\web;
12+
use skeeks\cms\authclient\CmsAuthClientCollection;
13+
use skeeks\cms\authclient\CmsAuthClientSettings;
14+
15+
/**
16+
* @property CmsAuthClientCollection $authClientCollection
17+
* @property CmsAuthClientSettings $authClientSettings
18+
19+
* Class Application
20+
* @package yii\web
21+
*/
22+
class Application
23+
{}

_settingsFrom.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* @author Semenov Alexander <[email protected]>
4+
* @link http://skeeks.com/
5+
* @copyright 2010 SkeekS (СкикС)
6+
* @date 27.03.2015
7+
*/
8+
use yii\helpers\Html;
9+
/* @var $this yii\web\View */
10+
/* @var $model \skeeks\cms\models\WidgetConfig */
11+
12+
?>
13+
<?= $form->fieldSet(\Yii::t('app','Are common')); ?>
14+
<?= $form->field($model, 'enabled')->radioList(\Yii::$app->formatter->booleanFormat); ?>
15+
<?= $form->fieldSetEnd(); ?>
16+
17+
<?= $form->fieldSet('GitHub'); ?>
18+
19+
<p><?=\Yii::t('app','Create application at page')?>: <?= Html::a('https://github.com/settings/applications', 'https://github.com/settings/applications', [
20+
'target' => '_blank'
21+
]); ?><?=\Yii::t('app',', and get its settings.')?></p>
22+
<hr />
23+
24+
<?= $form->field($model, 'githubEnabled')->radioList(\Yii::$app->formatter->booleanFormat); ?>
25+
26+
<?= $form->field($model, 'githubClientId')->textInput(['placeholder' => 'c692de6c3c3247e39cf4']); ?>
27+
<?= $form->field($model, 'githubClientSecret')->textInput(['placeholder' => 'f01f7bc7d41f38e4049d15786c0f1b93a5e96e90']); ?>
28+
<?= $form->field($model, 'githubClass')->textInput(['placeholder' => 'yii\authclient\clients\GitHub'])->hint(\Yii::t('app','Optional parameter, if not filled will be used {yii}',['yii' => 'yii\authclient\clients\GitHub'])); ?>
29+
30+
<?= $form->fieldSetEnd(); ?>
31+
32+
<?= $form->fieldSet('Vk'); ?>
33+
34+
<p><?=\Yii::t('app','Create application at page')?>: <?= Html::a('http://vk.com/editapp?act=create', 'http://vk.com/editapp?act=create', [
35+
'target' => '_blank'
36+
]); ?><?=\Yii::t('app',', and get its settings.')?></p>
37+
<hr />
38+
39+
<?= $form->field($model, 'vkEnabled')->radioList(\Yii::$app->formatter->booleanFormat); ?>
40+
41+
<?= $form->field($model, 'vkClientId')->textInput(['placeholder' => '5040380']); ?>
42+
<?= $form->field($model, 'vkClientSecret')->textInput(['placeholder' => 'sxAWws6ATNj5vDabPysA']); ?>
43+
<?= $form->field($model, 'vkClass')->textInput(['placeholder' => 'yii\authclient\clients\VKontakte'])->hint(\Yii::t('app','Optional parameter, if not filled will be used {yii}',['yii' => 'yii\authclient\clients\VKontakte'])); ?>
44+
45+
<?= $form->fieldSetEnd(); ?>
46+
47+
48+
<?= $form->fieldSet('Facebook'); ?>
49+
50+
<p><?=\Yii::t('app','Create application at page')?>: <?= Html::a('https://developers.facebook.com/apps', 'https://developers.facebook.com/apps', [
51+
'target' => '_blank'
52+
]); ?><?=\Yii::t('app',', and get its settings.')?></p>
53+
<hr />
54+
55+
<?= $form->field($model, 'facebookEnabled')->radioList(\Yii::$app->formatter->booleanFormat); ?>
56+
57+
<?= $form->field($model, 'facebookClientId')->textInput(['placeholder' => '5040380']); ?>
58+
<?= $form->field($model, 'facebookClientSecret')->textInput(['placeholder' => 'sxAWws6ATNj5vDabPysA']); ?>
59+
<?= $form->field($model, 'facebookClass')->textInput(['placeholder' => 'yii\authclient\clients\Facebook'])->hint(\Yii::t('app','Optional parameter, if not filled will be used {yii}',['yii' => 'yii\authclient\clients\VKontakte'])); ?>
60+
61+
<?= $form->fieldSetEnd(); ?>
62+
63+
64+

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "skeeks/cms-authclient",
3+
"description": "Authorization by social networks for SkeekS CMS",
4+
"keywords": ["yii", "skeeks", "framework", "component", "authclient"],
5+
"homepage": "http://cms.skeeks.com/",
6+
"type": "yii2-extension",
7+
"license": "BSD-3-Clause",
8+
"support": {
9+
"issues": "http://skeeks.com/",
10+
"wiki": "http://en.cms.skeeks.com/docs/",
11+
"source": "https://github.com/skeeks-cms/cms-authclient"
12+
},
13+
"authors": [
14+
{
15+
"name": "Semenov Alexander",
16+
"email": "[email protected]"
17+
}
18+
],
19+
"require": {
20+
"skeeks/cms": "*",
21+
"yiisoft/yii2-authclient": "*"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"skeeks\\cms\\authclient\\": ""
26+
}
27+
}
28+
}

config/main-console.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
return [];

0 commit comments

Comments
 (0)