private function getModel() { if (!$this->isGuest && $this->_model === null) { $this->_model = CmsUser::model()->findByPk($this->id, array('select' => 'role')); } return $this->_model; }
public function authenticate() { // Производим стандартную аутентификацию, описанную в руководстве. $user = CmsUser::model()->find('LOWER(username)=?', array(strtolower($this->username))); if ($user->ban == 1) { die("Ваш пользователь забанен, для дополнительной инвормации обратитеть к администратору"); } if ($user === null || md5('lkjhgfd' . $this->password) !== $user->password) { if ($user === null || $this->password !== $user->password) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { $this->_id = $user->id; $this->username = $user->username; CmsUser::model()->updateByPk($this->_id, array('data_avtor' => time())); $this->errorCode = self::ERROR_NONE; } } else { $this->_id = $user->id; $this->username = $user->username; CmsUser::model()->updateByPk($this->_id, array('data_avtor' => time())); $this->errorCode = self::ERROR_NONE; } return !$this->errorCode; }
/** * Displays the login page */ public function actionLogin() { /** * Авторизация по токену для восстановления пароля */ if ($recoveryPasswordToken = Yii::app()->request->getParam('token')) { if ($user = CmsUser::getByRecoveryPasswordToken($recoveryPasswordToken)) { $log = new LoginForm(); $log->username = $user->username; $log->password = $user->password; $log->login(); $this->redirect($this->createAbsoluteUrl('UserPersonal/index', array('id' => $user->id))); } } $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 ServiceUserIdentity($authIdentity); // Успешный вход if ($identity->authenticate()) { Yii::app()->user->login($identity); // Специальный редирект с закрытием popup окна $authIdentity->redirect(); } else { // Закрываем popup окно и перенаправляем на cancelUrl $authIdentity->cancel(); } } $this->redirect(array('site/login')); } //авторизация с помошью соц сетей $model = new LoginForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid // $model1=CmsUser::model()->findByAttributes(array('username'=>$model->username)); $model_set = CmsSetting::model()->findByPk(1); if ($model_set->podtv_email == 1) { $user = CmsUser::model()->findByAttributes(array('username' => $model->username)); $user->sendRecoveryPasswordMessage(); $this->render('login', array('model' => $model, 'flag' => true)); Yii::app()->end(); } else { if ($model->validate() && $model->login()) { $this->redirect(array('UserPersonal/index', 'id' => Yii::app()->user->id)); } } } // display the login form $this->render('login', array('model' => $model)); }
public static function sendOtvet($id) { $model = self::model()->findAllByPk($id); if ($model->user_id != null) { $user = CmsUser::model()->findAllByPk($model->user_id); if ($user->podpis == 1) { $model = self::model()->findByAttributes(array('parent_id' => $id)); //naxodim kom po roditely Yii::app()->mailer->AddAddress($user->email); if ($model->user_id != null) { $user = CmsUser::model()->findAllByPk($model->user_id); } Yii::app()->mailer->Subject = 'Ответ на коментарий'; Yii::app()->mailer->Body = Yii::app()->controller->renderPartial('/email/otvet', array('model' => $model, 'user' => $user), true); Yii::app()->mailer->Send(); } } return true; }
public function actionChangeAvatar() { $model = CmsUser::model()->findByPk(Yii::app()->user->id); $model->scenario = 'ava'; $model->attributes = $_POST['CmsUser']; if ($model->validate()) { $model->SaveImage(); CmsUser::model()->updateByPk(Yii::app()->user->id, array('picture' => $model->picture)); return $this->sendResponse(self::STATUS_OK, CmsUser::model()->findByPk(Yii::app()->user->id)); } else { return $this->sendResponse(self::STATUS_BAD_REQUEST, ""); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return CmsUser the loaded model * @throws CHttpException */ public function loadModel($id) { $model = CmsUser::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionAxjaxQuery() { $model = CmsUser::model()->findByPk(Yii::app()->user->id); if ($model->podpis == 0) { return CmsUser::model()->updateByPk(Yii::app()->user->id, array('podpis' => '1')); } else { return CmsUser::model()->updateByPk(Yii::app()->user->id, array('podpis' => '0')); } }
} ?> </tr> </table> </div> </div> </div> <div class="row"> <div class="container-fluid "> <?php $model2 = CmsUser::model()->findAllByAttributes(array('prigl_id' => array($model->id))); ?> <div class="col-md-4" style="margin-top: 5%"> <?php echo CHtml::form('', 'POST', array('id' => 'FormSms', 'role' => 'form')); ?> <div class="form-group"> <label for="InputSms">Введите своё сообщение</label> <?php echo CHtml::hiddenField('id', $id, array('id' => 'IdUser')); echo CHtml::textArea('sms', '', array('id' => 'SmsId', 'class' => 'sizeKom form-control', 'rows' => '4')); ?> </div> <?php