Commit bb8cf49cdf13934568d6385995fcf68a5b345446
1 parent
a3a5d51c
user auth
авторизация пользователей
Showing
3 changed files
with
22 additions
and
3 deletions
Show diff stats
No preview for this file type
No preview for this file type
frontend/controllers/SiteController.php
... | ... | @@ -20,6 +20,8 @@ use common\models\User; |
20 | 20 | use yii\helpers\VarDumper; |
21 | 21 | use common\models\Page; |
22 | 22 | use frontend\models\Option; |
23 | +use common\models\Social; | |
24 | + | |
23 | 25 | |
24 | 26 | /** |
25 | 27 | * Site controller |
... | ... | @@ -101,8 +103,13 @@ class SiteController extends Controller |
101 | 103 | */ |
102 | 104 | public function actionLogin() |
103 | 105 | { |
106 | + | |
107 | + // creat new model table Social and new model User | |
108 | + $social = new Social(); | |
109 | + $user = new User(); | |
104 | 110 | |
105 | 111 | $serviceName = Yii::$app->getRequest()->getQueryParam('service'); |
112 | + | |
106 | 113 | if (isset($serviceName)) { |
107 | 114 | /** @var $eauth \nodge\eauth\ServiceBase */ |
108 | 115 | $eauth = Yii::$app->get('eauth')->getIdentity($serviceName); |
... | ... | @@ -111,11 +118,24 @@ class SiteController extends Controller |
111 | 118 | |
112 | 119 | try { |
113 | 120 | if ($eauth->authenticate()) { |
114 | -// var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes()); exit; | |
115 | - | |
116 | 121 | $identity = User::findByEAuth($eauth); |
117 | 122 | Yii::$app->getUser()->login($identity); |
118 | 123 | |
124 | + //Save date get social network in database | |
125 | + if (! $social::find()->where(['social_user_id' => $identity[profile][id], 'social_name' => $identity[profile][service]])->exists()) { | |
126 | + $name = explode(' ',$identity[profile][name]); | |
127 | + $user->firstname = $name[0]; | |
128 | + $user->lastname = $name[1]; | |
129 | + $user->id_system_date = date("d.m.y.H:i:s"); | |
130 | + $user->save(); | |
131 | + $social->social_name = $identity[profile][service]; | |
132 | + $social->social_user_id = $identity[profile][id]; | |
133 | + $social->user_id = $user->id; | |
134 | + $social->validate(); | |
135 | + $social->errors; | |
136 | + $social->save(); | |
137 | + } | |
138 | + | |
119 | 139 | // special redirect with closing popup window |
120 | 140 | $eauth->redirect(); |
121 | 141 | } |
... | ... | @@ -170,7 +190,6 @@ class SiteController extends Controller |
170 | 190 | */ |
171 | 191 | public function actionContact() |
172 | 192 | { |
173 | - | |
174 | 193 | //Yii::$app->user->logout(); |
175 | 194 | $identity = Yii::$app->getUser()->getIdentity(); |
176 | 195 | var_dump($identity[profile]); | ... | ... |