/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. */ public function actionUpdate() { $model = $this->loadModel(); $profile = $model->profile; $this->performAjaxValidation(array($model, $profile)); /* Get current user role. Added by Phihx. date 14/02/2014*/ $assignedItems = Rights::getAuthorizer()->getAuthItems(null, $model->id); $userCurrenRole = array_keys($assignedItems); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $profile->attributes = $_POST['Profile']; if ($model->validate() && $profile->validate()) { /*$old_password = User::model()->notsafe()->findByPk($model->id); if ($old_password->password!=$model->password) { $model->password=Yii::app()->controller->module->encrypting($model->password); $model->activkey=Yii::app()->controller->module->encrypting(microtime().$model->password); }*/ if (!empty($_POST['newPassword'])) { $model->password = Yii::app()->controller->module->encrypting($_POST['newPassword']); $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $_POST['newPassword']); } $model->save(); $profile->save(); /*remove role for user. added by phihx. date 14/02/2014*/ if (!empty($userCurrenRole)) { foreach ($userCurrenRole as $role) { Rights::revoke($role, $model->id); } } /*Add role for user. added by phihx. date 14/02/2014*/ if (!empty($_POST['user_role'])) { //foreach($_POST['user_role'] as $role){ Rights::assign($_POST['user_role'], $model->id); //} } Yii::app()->user->setFlash('success', translate('Chỉnh sửa người dùng thành công.')); $this->redirect(PIUrl::createUrl('/user')); } else { $profile->validate(); } } /* Get All role. Added by Phihx. date 14/02/2014*/ $allRoles = $this->getAllRoleUser(); //$allClass = Classes::model()->findAll(); $arrClass[''] = '---Chọn lớp---'; Yii::app()->theme = 'flatlab'; $this->render('update', array('model' => $model, 'profile' => $profile, 'allRoles' => $allRoles, 'userCurrenRole' => $userCurrenRole)); }
public function setRoles($roles) { // $authorizer = Yii::app()->getModule("rights")->getAuthorizer(); if (!is_array($roles)) { return false; } foreach ($this->roles as $role) { Rights::revoke($role, $this->id); } foreach ($roles as $role) { Rights::assign($role, $this->id); } return true; }