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()); } }
/** * Registration user */ public function actionRegistration() { if(Y::module()->isRegistrationClose) $this->redirect('close'); $model = new RegistrationForm; $profile=new Profile; $profile->regMode = true; // ajax validator if(isset($_POST['ajax']) && $_POST['ajax']==='registration-form') Y::end(UActiveForm::validate(array($model,$profile))); if (Y::userId()) { $this->redirect(Y::module()->cabinetUrl); } else { if(isset($_POST['RegistrationForm'])) { $model->attributes=$_POST['RegistrationForm']; $profile->attributes= isset($_POST['Profile'])?$_POST['Profile']:array(); if($model->validate()&&$profile->validate()) { $soucePassword = $model->password; $model->activkey=UserModule::encrypting(microtime().$soucePassword); $model->password=UserModule::encrypting($soucePassword); $model->verifyPassword=UserModule::encrypting($model->verifyPassword); $model->createtime=time(); $model->lastvisit=((Y::module()->loginNotActiv||(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false))&&Y::module()->autoLogin)?time():0; $model->superuser=0; $model->status=((Y::module()->activeAfterRegister)?User::STATUS_ACTIVE:User::STATUS_NOACTIVE); if ($model->save()) { $profile->user_id=$model->id; $profile->save(); if (Y::module()->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation',array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email,Users::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),Users::t("Please activate you account go to {activation_url}",array('{activation_url}'=>$activation_url))); } if ((Y::module()->loginNotActiv||(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false))&&Y::module()->autoLogin) { $identity=new UserIdentity($model->username,$soucePassword); $identity->authenticate(); Y::user()->login($identity,0); $this->redirect(Y::module()->returnUrl); } else { if (!Y::module()->activeAfterRegister&&!Y::module()->sendActivationMail) { Y::flash('/user/registration',Users::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false) { Y::flash('/user/registration',Users::t("Thank you for your registration. Please {{login}}.",array('{{login}}'=>CHtml::link(Users::t('Login'),Y::module()->loginUrl)))); } elseif(Y::module()->loginNotActiv) { Y::flash('/user/registration',Users::t("Thank you for your registration. Please check your email or login.")); } else { Y::flash('/user/registration',Users::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } else $profile->validate(); } $this->render('/user/registration',array('model'=>$model,'profile'=>$profile,'lang'=>Yii::app()->language)); } }