From bb8cf49cdf13934568d6385995fcf68a5b345446 Mon Sep 17 00:00:00 2001 From: Dmitryi Date: Tue, 8 Dec 2015 12:31:18 +0200 Subject: [PATCH] user auth авторизация пользователей --- db-migration/social.backup | Bin 0 -> 2251 bytes db-migration/user.backup | Bin 0 -> 3758 bytes frontend/controllers/SiteController.php | 25 ++++++++++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 db-migration/social.backup create mode 100644 db-migration/user.backup diff --git a/db-migration/social.backup b/db-migration/social.backup new file mode 100644 index 0000000..862a369 Binary files /dev/null and b/db-migration/social.backup differ diff --git a/db-migration/user.backup b/db-migration/user.backup new file mode 100644 index 0000000..03ba32a Binary files /dev/null and b/db-migration/user.backup differ diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 087b960..7b15822 100644 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -20,6 +20,8 @@ use common\models\User; use yii\helpers\VarDumper; use common\models\Page; use frontend\models\Option; +use common\models\Social; + /** * Site controller @@ -101,8 +103,13 @@ class SiteController extends Controller */ public function actionLogin() { + + // creat new model table Social and new model User + $social = new Social(); + $user = new User(); $serviceName = Yii::$app->getRequest()->getQueryParam('service'); + if (isset($serviceName)) { /** @var $eauth \nodge\eauth\ServiceBase */ $eauth = Yii::$app->get('eauth')->getIdentity($serviceName); @@ -111,11 +118,24 @@ class SiteController extends Controller try { if ($eauth->authenticate()) { -// var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes()); exit; - $identity = User::findByEAuth($eauth); Yii::$app->getUser()->login($identity); + //Save date get social network in database + if (! $social::find()->where(['social_user_id' => $identity[profile][id], 'social_name' => $identity[profile][service]])->exists()) { + $name = explode(' ',$identity[profile][name]); + $user->firstname = $name[0]; + $user->lastname = $name[1]; + $user->id_system_date = date("d.m.y.H:i:s"); + $user->save(); + $social->social_name = $identity[profile][service]; + $social->social_user_id = $identity[profile][id]; + $social->user_id = $user->id; + $social->validate(); + $social->errors; + $social->save(); + } + // special redirect with closing popup window $eauth->redirect(); } @@ -170,7 +190,6 @@ class SiteController extends Controller */ public function actionContact() { - //Yii::$app->user->logout(); $identity = Yii::$app->getUser()->getIdentity(); var_dump($identity[profile]); -- libgit2 0.21.4