예제 #1
0
 public function actionAdmin()
 {
     $countNewsProduct = NewsProduct::getCountNoShow();
     if ($countNewsProduct > 0) {
         Yii::app()->user->setFlash('info', Yii::t('common', 'There are new product news') . ': ' . CHtml::link(Yii::t('common', '{n} news', $countNewsProduct), array('/news/backend/main/product')));
     }
     $this->rememberPage();
     $this->getMaxSorter();
     $this->getMinSorter();
     $model = new Apartment('search');
     $model->resetScope();
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET[$this->modelName])) {
         $model->attributes = $_GET[$this->modelName];
     }
     $model->setRememberScenario('ads_remember');
     $model = $model->with(array('user'));
     $this->params['paidServicesArray'] = array();
     if (issetModule('paidservices')) {
         $paidServices = PaidServices::model()->findAll('id != ' . PaidServices::ID_ADD_FUNDS);
         $this->params['paidServicesArray'] = CHtml::listData($paidServices, 'id', 'name');
     }
     $this->render('admin', array_merge(array('model' => $model), $this->params));
 }
예제 #2
0
 public function actionProduct()
 {
     //NewsProduct::getProductNews();
     Yii::app()->user->setState('menu_active', 'news.product');
     $model = NewsProduct::model();
     $result = $model->getAllWithPagination();
     $this->render('news_product', array('items' => $result['items'], 'pages' => $result['pages']));
 }
예제 #3
0
 public function actionAdmin()
 {
     $countNewsProduct = NewsProduct::getCountNoShow();
     if ($countNewsProduct > 0) {
         Yii::app()->user->setFlash('info', Yii::t('common', 'There are new product news') . ': ' . CHtml::link(Yii::t('common', '{n} news', $countNewsProduct), array('/news/backend/main/product')));
     }
     $this->rememberPage();
     $this->getMaxSorter();
     $model = new Apartment('search');
     $model = $model->with(array('user'));
     $this->render('admin', array_merge(array('model' => $model), $this->params));
 }
예제 #4
0
 public function actionLogin()
 {
     $this->layout = '//layouts/inner';
     $this->showSearchForm = false;
     $model = new LoginForm();
     if (Yii::app()->request->getQuery('soc_error_save')) {
         Yii::app()->user->setFlash('error', tt('Error saving data. Please try again later.', 'socialauth'));
     }
     if (Yii::app()->request->getQuery('deactivate')) {
         showMessage(tc('Login'), tt('Your account not active. Administrator deactivate your account.', 'socialauth'), null, true);
     }
     $service = Yii::app()->request->getQuery('service');
     if (isset($service)) {
         $authIdentity = Yii::app()->eauth->getIdentity($service);
         $authIdentity->redirectUrl = Yii::app()->user->returnUrl;
         $authIdentity->cancelUrl = $this->createAbsoluteUrl('site/login');
         if ($authIdentity->authenticate()) {
             $identity = new EAuthUserIdentity($authIdentity);
             // успешная авторизация
             if ($identity->authenticate()) {
                 //Yii::app()->user->login($identity);
                 $uid = $identity->id;
                 $firstName = $identity->firstName;
                 $email = $identity->email;
                 $service = $identity->serviceName;
                 $mobilePhone = $identity->mobilePhone;
                 $homePhone = $identity->homePhone;
                 $isNewUser = false;
                 $existId = User::getIdByUid($uid, $service);
                 if (!$existId) {
                     $isNewUser = true;
                     $email = !$email ? User::getRandomEmail() : $email;
                     $phone = '';
                     if ($mobilePhone) {
                         $phone = $mobilePhone;
                     } elseif ($homePhone) {
                         $phone = $homePhone;
                     }
                     $user = User::createUser(array('email' => $email, 'phone' => $phone, 'username' => $firstName), true);
                     if (!$user && isset($user['id'])) {
                         $authIdentity->redirect(Yii::app()->createAbsoluteUrl('/site/login') . '?soc_error_save=1');
                     }
                     $success = User::setSocialUid($user['id'], $uid, $service);
                     if (!$success) {
                         User::model()->findByPk($user['id'])->delete();
                         $authIdentity->redirect(Yii::app()->createAbsoluteUrl('/site/login') . '?soc_error_save=1');
                     }
                     $existId = User::getIdByUid($uid, $service);
                 }
                 if ($existId) {
                     $result = $model->loginSocial($existId);
                     User::updateUserSession();
                     User::updateLatestInfo(Yii::app()->user->id, Yii::app()->controller->currentUserIp);
                     if ($result) {
                         //						Yii::app()->user->clearState('id');
                         //						Yii::app()->user->clearState('first_name');
                         //						Yii::app()->user->clearState('nickname');
                         if ($result === 'deactivate') {
                             $authIdentity->redirect(Yii::app()->createAbsoluteUrl('/site/login') . '?deactivate=1');
                         }
                         if ($isNewUser) {
                             $authIdentity->redirect(Yii::app()->createAbsoluteUrl('/usercpanel/main/index') . '?soc_success=1');
                         } else {
                             $authIdentity->redirect(Yii::app()->createAbsoluteUrl('/usercpanel/main/index'));
                         }
                     }
                 }
                 // специальное перенаправления для корректного закрытия всплывающего окна
                 $authIdentity->redirect();
             } else {
                 // закрытие всплывающего окна и перенаправление на cancelUrl
                 $authIdentity->cancel();
             }
         }
         // авторизация не удалась, перенаправляем на страницу входа
         $this->redirect(array('site/login'));
     }
     if (Yii::app()->user->getState('attempts-login') >= LoginForm::ATTEMPTSLOGIN) {
         $model->scenario = 'withCaptcha';
     }
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         if ($model->validate() && $model->login()) {
             Yii::app()->user->setState('attempts-login', 0);
             User::updateUserSession();
             User::updateLatestInfo(Yii::app()->user->id, Yii::app()->controller->currentUserIp);
             if (Yii::app()->user->checkAccess('apartments_admin')) {
                 NewsProduct::getProductNews();
                 $this->redirect(array('/apartments/backend/main/admin'));
                 Yii::app()->end();
             }
             /*if (Yii::app()->user->isGuest) {
             			$this->redirect(Yii::app()->user->returnUrl);
             		} else {
             			if (!Yii::app()->user->getState('returnedUrl')) {
             				$this->redirect(array('/usercpanel/main/index'));
             			} else {
             				$this->redirect(Yii::app()->user->getState('returnedUrl'));
             			}
             		}*/
             if (!Yii::app()->user->returnUrl) {
                 $this->redirect(array('/usercpanel/main/index'));
             } else {
                 $this->redirect(Yii::app()->user->returnUrl);
             }
         } else {
             Yii::app()->user->setState('attempts-login', Yii::app()->user->getState('attempts-login', 0) + 1);
             if (Yii::app()->user->getState('attempts-login') >= LoginForm::ATTEMPTSLOGIN) {
                 $model->scenario = 'withCaptcha';
             }
         }
     }
     $this->render('login', array('model' => $model));
 }
예제 #5
0
 public function actionCreate()
 {
     if (!Yii::app()->user->isGuest) {
         if (Yii::app()->user->checkAccess('backend_access')) {
             $this->redirect(Yii::app()->createUrl('/apartments/backend/main/create'));
         } else {
             $this->redirect(Yii::app()->createUrl('/userads/main/create'));
         }
     }
     if (param('user_registrationMode') == 'without_confirm') {
         $user = new User('register_without_confirm');
     } else {
         $user = new User('register');
     }
     $login = new LoginForm();
     $model = new Apartment();
     $model->active = Apartment::STATUS_DRAFT;
     $model->period_activity = param('apartment_periodActivityDefault', 'always');
     $model->references = $model->getFullInformation($model->id, $model->type);
     $isAdmin = false;
     $activeTab = 'tab_register';
     $isUpdate = Yii::app()->request->getPost('is_update');
     if (!$isUpdate && isset($_POST['LoginForm']) && ($_POST['LoginForm']['username'] || $_POST['LoginForm']['password'])) {
         if (Yii::app()->user->getState('attempts-login') >= LoginForm::ATTEMPTSLOGIN) {
             $login->scenario = 'withCaptcha';
         }
         $activeTab = 'tab_login';
         $login->attributes = $_POST['LoginForm'];
         if ($login->validate() && $login->login()) {
             Yii::app()->user->setState('attempts-login', 0);
             User::updateUserSession();
             $isAdmin = Yii::app()->user->checkAccess('backend_access');
             $user = User::model()->findByPk(Yii::app()->user->id);
         } else {
             Yii::app()->user->setState('attempts-login', Yii::app()->user->getState('attempts-login', 0) + 1);
             if (Yii::app()->user->getState('attempts-login') >= LoginForm::ATTEMPTSLOGIN) {
                 $login->scenario = 'withCaptcha';
             }
         }
     }
     if (isset($_POST['Apartment'])) {
         $model->attributes = $_POST['Apartment'];
         if (!$isUpdate) {
             $adValid = $model->validate();
             $userValid = false;
             if ($activeTab == 'tab_register' && param('useUserRegistration')) {
                 $user->attributes = $_POST['User'];
                 $userValid = $user->validate();
                 if ($adValid && $userValid) {
                     $user->activatekey = User::generateActivateKey();
                     $userData = User::createUser($user->attributes);
                     if ($userData) {
                         $user = $userData['userModel'];
                         $user->password = $userData['password'];
                         $user->activatekey = $userData['activatekey'];
                         $user->activateLink = $userData['activateLink'];
                         $notifier = new Notifier();
                         $notifier->raiseEvent('onNewUser', $user, array('forceEmail' => $user->email));
                     }
                 }
             }
             if ($user->id && ($activeTab == 'tab_login' && $adValid || $activeTab == 'tab_register' && param('useUserRegistration') && $adValid && $userValid)) {
                 if (param('useUseradsModeration', 1)) {
                     $model->active = Apartment::STATUS_MODERATION;
                 } else {
                     $model->active = Apartment::STATUS_ACTIVE;
                 }
                 $model->owner_active = Apartment::STATUS_ACTIVE;
                 $model->owner_id = $user->id;
                 if ($model->save(false)) {
                     if (!$isAdmin && param('useUseradsModeration', 1)) {
                         Yii::app()->user->setFlash('success', tc('The listing is succesfullty added and is awaiting moderation'));
                     } else {
                         Yii::app()->user->setFlash('success', tc('The listing is succesfullty added'));
                     }
                     if ($activeTab == 'tab_register') {
                         if (param('user_registrationMode') == 'without_confirm') {
                             $login = new LoginForm();
                             $login->setAttributes(array('username' => $user['username'], 'password' => $user['password']));
                             if ($login->validate() && $login->login()) {
                                 User::updateUserSession();
                                 User::updateLatestInfo(Yii::app()->user->id, Yii::app()->controller->currentUserIp);
                                 $this->redirect(array('/usercpanel/main/index'));
                             } else {
                                 /*echo 'getErrors=<pre>';
                                 		print_r($login->getErrors());
                                 		echo '</pre>';
                                 		exit;*/
                                 showMessage(Yii::t('common', 'Registration'), Yii::t('common', 'You were successfully registered.'));
                             }
                         } else {
                             showMessage(Yii::t('common', 'Registration'), Yii::t('common', 'You were successfully registered. The letter for account activation has been sent on {useremail}', array('{useremail}' => $user['email'])));
                         }
                     } else {
                         if ($isAdmin) {
                             NewsProduct::getProductNews();
                             $this->redirect(array('/apartments/backend/main/update', 'id' => $model->id));
                             Yii::app()->end();
                         } else {
                             $this->redirect(array('/userads/main/update', 'id' => $model->id));
                         }
                     }
                 }
             }
         }
     } else {
         $objTypes = array_keys(Apartment::getObjTypesArray());
         $model->setDefaultType();
         $model->obj_type_id = reset($objTypes);
         $user->unsetAttributes(array('verifyCode'));
     }
     $this->render('create', array('model' => $model, 'user' => $user, 'login' => $login, 'activeTab' => $activeTab));
 }