Beispiel #1
0
 public function actionSettings()
 {
     $user = User::thisUser();
     $changePasswordModel = new ChangePasswordForm();
     if ($changePasswordModel->load(Yii::$app->request->post()) && $changePasswordModel->validate() && $changePasswordModel->changePassword()) {
         Yii::$app->session->setFlash('success', Lang::t('page/accountProfile', 'changePasswordSuccess'));
         return $this->redirect(['account/settings']);
     }
     $ulogins = Ulogin::findAll(['user_id' => $user->id]);
     return $this->render('settings', ['user' => $user, 'changePasswordModel' => $changePasswordModel, 'ulogins' => $ulogins]);
 }
Beispiel #2
0
 public function actionUlogin()
 {
     $loginUlogin = Yii::$app->request->post('login_ulogin');
     if (!empty($loginUlogin)) {
         $ulogin = new Ulogin();
         if ($ulogin->loadAuthData($loginUlogin)) {
             $modelInBase = Ulogin::findUlogin($ulogin->identity, $ulogin->network);
             if (!empty($modelInBase)) {
                 // войти под пользователем $modelInBase
                 $user = \common\models\User::findOne($modelInBase->user_id);
                 if (!empty($user)) {
                     if (Yii::$app->getUser()->login($user)) {
                         return $this->goHome();
                     }
                 }
             } else {
                 if ($user = \common\models\User::findOne(['email' => $ulogin->email])) {
                     // Прикрепляем к существующему
                     if (empty($user->firstname) || empty($user->lastname)) {
                         $user->firstname = empty($user->firstname) ? $user->firstname : $ulogin->firstname;
                         $user->lastname = empty($user->lastname) ? $user->lastname : $ulogin->lastname;
                         $user->save();
                     }
                 } elseif ($user = \common\models\User::findOne(['username' => $ulogin->network . '_' . md5($ulogin->identity)])) {
                 } else {
                     // зарегистрировать нового пользователя
                     $signupForm = new SignupForm();
                     $signupForm->username = $ulogin->network . '_' . md5($ulogin->identity);
                     $signupForm->displayName = $ulogin->nickname;
                     $signupForm->password = $ulogin->randomPassword();
                     $signupForm->email = $ulogin->email;
                     $user = $signupForm->signup();
                     if (!empty($user)) {
                         $user->firstname = $ulogin->firstname;
                         $user->lastname = $ulogin->lastname;
                         $user->save();
                     }
                 }
                 if (!empty($user)) {
                     $ulogin->user_id = $user->id;
                     $ulogin->user_start_id = $user->id;
                     $ulogin->save();
                     if (Yii::$app->getUser()->login($user)) {
                         return $this->goHome();
                     }
                 }
             }
         }
     }
 }
Beispiel #3
0
 /**
  * @param string $identity
  * @param string $network
  * @param bool   $loadNull
  *
  * @return Ulogin
  */
 public static function findUlogin($identity, $network, $loadNull = false)
 {
     $query = Ulogin::find()->andWhere('identity = :identity AND network = :network', [':identity' => $identity, ':network' => $network]);
     if (!$loadNull) {
         $query->andWhere('user_id <> 0 AND user_id is not null');
     }
     return $query->one();
 }