public function init() { if(Y::isGuest()) $this->redirect(Admin::url('login')); if(!Y::checkAccess('moderator')) Y::end($this->render('accessDenied')); parent::init(); $folder = Y::asset('admin.assets'); Y::clientScript() ->registerCoreScript('jquery') ->registerCoreScript('jquery.ui'); Y::clientScript()->ajaxExclude(array( 'jquery.js', 'jquery-ui.min.js', 'jquery-ui.css', //treeview 'jquery.treeview.js', 'jquery.cookie.js', 'jquery.treeview.edit.js', 'jquery.treeview.async.js', )); }
public function rules() { return array( array('verifyCode', 'activeCaptcha', 'allowEmpty'=>!Y::isGuest() || !CCaptcha::checkRequirements()), // Во время AJAX запроса не забудьте установить сценарий для модели //to captcha ajax validation /*array('verifyCode','captcha', // авторизованным пользователям код можно не вводить , 'captchaAction' => 'site/captcha' ),*/ ); }
public function init() { // Иерархию ролей расположим в файле auth.php в директории config приложения if($this->authFile===null){ $this->authFile=Yii::getPathOfAlias('application.config.auth').'.php'; } parent::init(); // Для гостей у нас и так роль по умолчанию guest. if(!Y::isGuest()){ // Связываем роль, заданную в БД с идентификатором пользователя, // возвращаемым UserIdentity.getId(). $this->assign(Y::user()->role, Y::userId()); } }
public function renderContent() { if (Y::isAjaxRequest()) { $this->$_GET['do']; Y::end(); } $route = isset($_GET['users']) ? urldecode($_GET['users']) : ''; if (Y::isGuest()) { Yii::app()->runController('users/'.$route); } else { //cabinet $model = $this->module->user(); $this->render('user-info',array( 'model'=>$model, 'profile'=>$model->profile, )); } }
/** * Displays the login page */ public function actionLogin() { if (!Y::isGuest()) $this->_redirect(); $model = new UserLogin; $this->performAjaxValidation($model); // collect user input data if (isset($_POST['UserLogin'])){ $model->attributes = $_POST['UserLogin']; // validate user input and redirect to previous page if valid if ($model->validate()){ $this->lastVisit(); $this->_redirect(); } } // display the login form $this->render('/user/login', array('model' => $model)); }
<?php $this->pageTitle=Yii::app()->name . ' - '.Users::t("Change Password"); $this->breadcrumbs=array( Users::t("Profile") => Users::url('profile/cabinet'), Users::t("Change password"), ); ?> <h2><?php echo Users::t("Change password"); ?></h2> <?php if(Y::isGuest()) {$this->widget('GuestMenu');} else {$this->widget('UserMenu');} ?> <div class="form"> <?php $form=$this->beginWidget('UActiveForm', array( 'id'=>'changepassword-form', 'enableAjaxValidation'=>true, )); ?> <p class="note"><?php echo Users::t('Fields with <span class="required">*</span> are required.'); ?></p> <?php echo CHtml::errorSummary($model); ?> <div class="row"> <?php echo $form->labelEx($model,'password'); ?> <?php echo $form->passwordField($model,'password'); ?> <?php echo $form->error($model,'password'); ?> <p class="hint"> <?php echo Users::t("Minimal password length 4 symbols."); ?> </p> </div> <div class="row">
/** * Return safe user data. * @param user id not required * @return user object or false */ public static function user($id=0) { if ($id) return User::model()->active()->findbyPk($id); else { if(Y::isGuest()) { return false; } else { if (!self::$_user) self::$_user = User::model()->active()->findbyPk(Yii::app()->user->id); return self::$_user; } } }