Commit bea66c28604f1af78a962873898e8cbbbbda4207

Authored by Yarik
2 parents cdb04594 f1f35982

Merge remote-tracking branch 'origin/master'

frontend/assets/AppAsset.php
@@ -31,7 +31,7 @@ class AppAsset extends AssetBundle @@ -31,7 +31,7 @@ class AppAsset extends AssetBundle
31 ]; 31 ];
32 public $depends = [ 32 public $depends = [
33 'yii\web\YiiAsset', 33 'yii\web\YiiAsset',
34 - 'yii\bootstrap\BootstrapAsset', 34 + 'yii\bootstrap\BootstrapPluginAsset',
35 ]; 35 ];
36 public $jsOptions = array( 36 public $jsOptions = array(
37 'position' => \yii\web\View::POS_HEAD 37 'position' => \yii\web\View::POS_HEAD
frontend/controllers/SiteController.php
@@ -123,59 +123,7 @@ class SiteController extends Controller @@ -123,59 +123,7 @@ class SiteController extends Controller
123 public function actionLogin() 123 public function actionLogin()
124 { 124 {
125 125
126 - // creat new model table Social and new model User  
127 - $social = new Social();  
128 - $user = new User();  
129 -  
130 - $serviceName = Yii::$app->getRequest()->getQueryParam('service');  
131 -  
132 - if (isset($serviceName)) {  
133 - /** @var $eauth \nodge\eauth\ServiceBase */  
134 - $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);  
135 - $eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());  
136 - $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));  
137 -  
138 - try {  
139 - if ($eauth->authenticate()) {  
140 - $identity = User::findByEAuth($eauth);  
141 - Yii::$app->getUser()->login($identity);  
142 -  
143 - //Save date get social network in database  
144 - if (! $social::find()->where(['social_user_id' => $identity[profile][id], 'social_name' => $identity[profile][service]])->exists()) {  
145 - $name = explode(' ',$identity[profile][name]);  
146 - $user->firstname = $name[0];  
147 - $user->lastname = $name[1];  
148 - $user->id_system_date = date("d.m.y.H:i:s");  
149 - $user->save();  
150 - $social->social_name = $identity[profile][service];  
151 - $social->social_user_id = $identity[profile][id];  
152 - $social->user_id = $user->id;  
153 - $social->validate();  
154 - $social->errors;  
155 - $social->save();  
156 - }  
157 126
158 - // special redirect with closing popup window  
159 - $eauth->redirect();  
160 - }  
161 - else {  
162 - // close popup window and redirect to cancelUrl  
163 - $eauth->cancel();  
164 - }  
165 - }  
166 - catch (\nodge\eauth\ErrorException $e) {  
167 - // save error to show it later  
168 - Yii::$app->getSession()->setFlash('error', 'EAuthException: '.$e->getMessage());  
169 -  
170 - // close popup window and redirect to cancelUrl  
171 -// $eauth->cancel();  
172 - $eauth->redirect($eauth->getCancelUrl());  
173 - }  
174 - }  
175 -  
176 -  
177 -  
178 -  
179 if (!\Yii::$app->user->isGuest) { 127 if (!\Yii::$app->user->isGuest) {
180 return $this->goHome(); 128 return $this->goHome();
181 } 129 }
@@ -188,6 +136,72 @@ class SiteController extends Controller @@ -188,6 +136,72 @@ class SiteController extends Controller
188 'model' => $model, 136 'model' => $model,
189 ]); 137 ]);
190 } 138 }
  139 +
  140 +// // creat new model table Social and new model User
  141 +// $social = new Social();
  142 +// $user = new User();
  143 +//
  144 +// $serviceName = Yii::$app->getRequest()->getQueryParam('service');
  145 +//
  146 +// if (isset($serviceName)) {
  147 +// /** @var $eauth \nodge\eauth\ServiceBase */
  148 +// $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
  149 +// $eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
  150 +// $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
  151 +//
  152 +// try {
  153 +// if ($eauth->authenticate()) {
  154 +// $identity = User::findByEAuth($eauth);
  155 +// Yii::$app->getUser()->login($identity);
  156 +//
  157 +// //Save date get social network in database
  158 +// if (! $social::find()->where(['social_user_id' => $identity[profile][id], 'social_name' => $identity[profile][service]])->exists()) {
  159 +// $name = explode(' ',$identity[profile][name]);
  160 +// $user->firstname = $name[0];
  161 +// $user->lastname = $name[1];
  162 +// $user->id_system_date = date("d.m.y.H:i:s");
  163 +// $user->save();
  164 +// $social->social_name = $identity[profile][service];
  165 +// $social->social_user_id = $identity[profile][id];
  166 +// $social->user_id = $user->id;
  167 +// $social->validate();
  168 +// $social->errors;
  169 +// $social->save();
  170 +// }
  171 +//
  172 +// // special redirect with closing popup window
  173 +// $eauth->redirect();
  174 +// }
  175 +// else {
  176 +// // close popup window and redirect to cancelUrl
  177 +// $eauth->cancel();
  178 +// }
  179 +// }
  180 +// catch (\nodge\eauth\ErrorException $e) {
  181 +// // save error to show it later
  182 +// Yii::$app->getSession()->setFlash('error', 'EAuthException: '.$e->getMessage());
  183 +//
  184 +// // close popup window and redirect to cancelUrl
  185 +// // $eauth->cancel();
  186 +// $eauth->redirect($eauth->getCancelUrl());
  187 +// }
  188 +// }
  189 +//
  190 +//
  191 +//
  192 +//
  193 +// if (!\Yii::$app->user->isGuest) {
  194 +// return $this->goHome();
  195 +// }
  196 +//
  197 +// $model = new LoginForm();
  198 +// if ($model->load(Yii::$app->request->post()) && $model->login()) {
  199 +// return $this->goBack();
  200 +// } else {
  201 +// return $this->render('login', [
  202 +// 'model' => $model,
  203 +// ]);
  204 +// }
191 } 205 }
192 206
193 /** 207 /**
@@ -328,7 +342,7 @@ class SiteController extends Controller @@ -328,7 +342,7 @@ class SiteController extends Controller
328 } 342 }
329 } 343 }
330 } 344 }
331 - if(hasErrors) { 345 + if($hasErrors) {
332 $data['option_values'] = $option_values; 346 $data['option_values'] = $option_values;
333 return $this->render('options', ['options' => $data, 'post' => $post]); 347 return $this->render('options', ['options' => $data, 'post' => $post]);
334 } else { 348 } else {
frontend/views/layouts/main.php
@@ -48,9 +48,17 @@ AppAsset::register($this); @@ -48,9 +48,17 @@ AppAsset::register($this);
48 <li><span><img src="/images/ico-question.png" alt=""/></span><a href="#">Помощь</a></li> 48 <li><span><img src="/images/ico-question.png" alt=""/></span><a href="#">Помощь</a></li>
49 </ul> 49 </ul>
50 <div class="header-cabinet-wr"> 50 <div class="header-cabinet-wr">
51 - <div class="header-cabinet-foto"><img src="/images/ded-ico.png" alt=""/></div>  
52 - <div class="header-cabinet-profile">Профиль</div>  
53 - <a href="/site/login">Личный кабинет</a> 51 + <?php
  52 + if (Yii::$app->user->isGuest): ?>
  53 + <div class="header-cabinet-foto"><img src="/images/ded-ico.png" alt=""/></div>
  54 + <div class="header-cabinet-profile">Профиль</div>
  55 + <?= Html::a('Личный кабинет',['/site/signup']) ?>
  56 + <?php else : ?>
  57 + <div class="header-cabinet-foto"><img src="/images/ded-ico.png" alt=""/></div>
  58 + <div class="header-cabinet-profile">Профиль</div>
  59 + <?= Html::a(Yii::$app->user->identity->email,['/cabinet/index']) ?>
  60 + <?php endif; ?>
  61 +
54 </div> 62 </div>
55 </div> 63 </div>
56 </div> 64 </div>