/** * render a user profile */ public function actionView() { // load the user profile according to the request if (isset($_GET['u'])) { // look for the right user criteria to use according to the viewer permissions if (Yii::app()->user->pbac(array('user.admin', 'admin.admin'))) { $criteria = array('id' => $_GET['u']); } else { $criteria = array('id' => $_GET['u'], 'status' => UserGroupsUser::ACTIVE); } // load the profile $model = UserGroupsUser::model()->findByAttributes($criteria); if ($model === null || $model->relUserGroupsGroup->level > Yii::app()->user->level && !UserGroupsConfiguration::findRule('public_profiles')) { throw new CHttpException(404, Yii::t('userGroupsModule.general', 'The requested page does not exist.')); } } else { $model = $this->loadModel(Yii::app()->user->id); } // load the profile extensions $profiles = array(); $profile_list = Yii::app()->controller->module->profile; foreach ($profile_list as $p) { // check if the profile data exist on the current user, otherwise // create an instance of the profile extension $relation = "rel{$p}"; if (!$model->{$relation} instanceof CActiveRecord) { $p_instance = new $p(); } else { $p_instance = $model->{$relation}; } // check if the profile extension is supporting profile views $views = $p_instance->profileViews(); if (isset($views[UserGroupsUser::VIEW])) { $profiles[] = array('view' => $views[UserGroupsUser::VIEW], 'model' => $p_instance); } } $service = Yii::app()->request->getQuery('service'); if (isset($service) && !Yii::app()->user->isGuest) { $authIdentity = Yii::app()->eauth->getIdentity($service); $authIdentity->redirectUrl = Yii::app()->user->returnUrl; $authIdentity->cancelUrl = $this->createAbsoluteUrl('/profile/update'); if ($authIdentity->authenticate()) { $identity = new ServiceUserIdentity($authIdentity); // успешная авторизация if ($identity->setAccountParams()) { //Yii::app()->user->login($identity); $serviceModel = UsergroupsSocialServices::model()->findByAttributes(array('service_name' => $identity->external_auth_id)); $isInAnoter = UsergroupsUserSocialAccounts::model()->findByAttributes(array('xml_id' => $identity->xml_id, 'external_auth_id' => $identity->external_auth_id), 'ug_id !=' . Yii::app()->user->id); if ($serviceModel && (!$isInAnoter || $isInAnoter && count($isInAnoter->user->social_accounts) <= 1)) { $userRes = array(); $oldUsers = UserGroupsUser::model()->findAllByAttributes(array('xml_id' => $identity->xml_id, 'external_auth_id' => $identity->external_auth_id), 'id !=' . Yii::app()->user->id); if ($isInAnoter) { $oldUsers[] = $isInAnoter->user; } if ($oldUsers) { $userRes = Yii::app()->user->userModel->eatUsers($oldUsers); } $account = UsergroupsUserSocialAccounts::model()->findByPk(array('ug_id' => Yii::app()->user->id, 'service_id' => $serviceModel->id)); if (!$account) { $account = new UsergroupsUserSocialAccounts(); $account->ug_id = Yii::app()->user->id; $account->service_id = $serviceModel->id; } $account->xml_id = $identity->xml_id; $account->external_auth_id = $identity->external_auth_id; if ($account->save()) { Yii::app()->user->setFlash('user', 'Аккаунт сервиса ' . $serviceModel->name . ' успешно добавлен!' . ($userRes ? '<br /> Поглощено пользователей: ' . $userRes['usersCnt'] . '<br /> Переназначено ям:' . $userRes['holesCnt'] . '<br /> Переназначено комментариев:' . $userRes['commentsCnt'] : '')); } } elseif ($isInAnoter) { Yii::app()->user->setFlash('user', '<span style="color:red;">Ошибка! Этот аккаунт уже ассоциирован с пользователем ' . CHtml::link($isInAnoter->user->Fullname, array('/profile/view', 'id' => $isInAnoter->user->id)) . '.</span>'); } // специальное перенаправления для корректного закрытия всплывающего окна $this->redirect(array('/profile/update/')); } else { // закрытие всплывающего окна и перенаправление на cancelUrl $authIdentity->cancel(); } } // авторизация не удалась, перенаправляем на страницу входа Yii::app()->user->setFlash('user', 'Ошибка! Невозможно авторизовать аккаунт.'); $this->redirect(array('/profile/update/')); } if (Yii::app()->request->isAjaxRequest || isset($_GET['_isAjax'])) { $this->renderPartial('view', array('model' => $model, 'profiles' => $profiles), false, true); } else { $this->render('view', array('model' => $model, 'profiles' => $profiles)); } }