Commit bb8cf49cdf13934568d6385995fcf68a5b345446

Authored by Dmitryi
1 parent a3a5d51c

user auth

авторизация пользователей
db-migration/social.backup 0 → 100644
No preview for this file type
db-migration/user.backup 0 → 100644
No preview for this file type
frontend/controllers/SiteController.php
@@ -20,6 +20,8 @@ use common\models\User; @@ -20,6 +20,8 @@ use common\models\User;
20 use yii\helpers\VarDumper; 20 use yii\helpers\VarDumper;
21 use common\models\Page; 21 use common\models\Page;
22 use frontend\models\Option; 22 use frontend\models\Option;
  23 +use common\models\Social;
  24 +
23 25
24 /** 26 /**
25 * Site controller 27 * Site controller
@@ -101,8 +103,13 @@ class SiteController extends Controller @@ -101,8 +103,13 @@ class SiteController extends Controller
101 */ 103 */
102 public function actionLogin() 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 $serviceName = Yii::$app->getRequest()->getQueryParam('service'); 111 $serviceName = Yii::$app->getRequest()->getQueryParam('service');
  112 +
106 if (isset($serviceName)) { 113 if (isset($serviceName)) {
107 /** @var $eauth \nodge\eauth\ServiceBase */ 114 /** @var $eauth \nodge\eauth\ServiceBase */
108 $eauth = Yii::$app->get('eauth')->getIdentity($serviceName); 115 $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
@@ -111,11 +118,24 @@ class SiteController extends Controller @@ -111,11 +118,24 @@ class SiteController extends Controller
111 118
112 try { 119 try {
113 if ($eauth->authenticate()) { 120 if ($eauth->authenticate()) {
114 -// var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes()); exit;  
115 -  
116 $identity = User::findByEAuth($eauth); 121 $identity = User::findByEAuth($eauth);
117 Yii::$app->getUser()->login($identity); 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 // special redirect with closing popup window 139 // special redirect with closing popup window
120 $eauth->redirect(); 140 $eauth->redirect();
121 } 141 }
@@ -170,7 +190,6 @@ class SiteController extends Controller @@ -170,7 +190,6 @@ class SiteController extends Controller
170 */ 190 */
171 public function actionContact() 191 public function actionContact()
172 { 192 {
173 -  
174 //Yii::$app->user->logout(); 193 //Yii::$app->user->logout();
175 $identity = Yii::$app->getUser()->getIdentity(); 194 $identity = Yii::$app->getUser()->getIdentity();
176 var_dump($identity[profile]); 195 var_dump($identity[profile]);