/**
  * This page is only accessable by admins.
  * 
  * @access public
  */
 public function preDispatch()
 {
     parent::preDispatch();
     // See if we have a logged in user.
     if (!$this->user->isAdmin()) {
         $this->_redirect('/');
     }
 }
 /**
  * This page is only accessable by admins.
  * 
  * @access public
  */
 public function preDispatch()
 {
     parent::preDispatch();
     // See if we have a logged in user.
     if (isset($this->user) && $this->user instanceof Application_Model_User && !$this->user->isAdmin()) {
         $this->_redirect('/');
     }
 }
 /**
  * Initializer.
  *
  * @return void
  */
 public function __construct()
 {
     // Apply the admin auth filter
     $this->middleware('admin');
     parent::__construct();
 }
 /**
  * Constructor.
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     $this->users = Sentinel::getUserRepository();
     $this->roles = Sentinel::getRoleRepository();
 }
示例#5
0
 public function saveUserInfo($model, $modelProfile, $postUser, $postProfile, $role, $checkRole = true)
 {
     $password = $model->password;
     $model->attributes = $postUser;
     if ($checkRole) {
         //check valid roles
         $roleArray = array('Manager', 'Administrator', 'Super User');
         if (!in_array($role, $roleArray)) {
             throw new CHttpException(451, Yii::t('user', 'Roles is not a valid value.'));
         }
     }
     if ($model->validate()) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             //Does user enter a new password? Yes: encrypt, No: nothing change
             if (!empty($model->password)) {
                 $model->salt = Yii::app()->extraFunctions->randomString(32);
                 $model->password = Yii::app()->extraFunctions->encryptUserPassword($model->salt, $postUser['password']);
             } else {
                 $model->password = $password;
             }
             $avatarArray = explode('/', $postUser['avatar']);
             $model->avatar = $avatarArray[count($avatarArray) - 1];
             //user want to create new profile must enter several info
             if (empty($modelProfile->userid)) {
                 if (Yii::app()->extraFunctions->checkEmptyField($postProfile, 'sex')) {
                     $modelProfile->userid = $model->id;
                     $modelProfile->attributes = $postProfile;
                     $modelProfile->save();
                 }
             } else {
                 //user update his profile
                 $modelProfile->attributes = $postProfile;
                 $modelProfile->save();
             }
             if ($model->update()) {
                 //save role
                 if ($checkRole) {
                     Yii::import('application.modules.backend.controllers.AuthorizedController');
                     $t = new AuthorizedController($model->id);
                     if ($t->SaveRole($model->id, $role)) {
                         $transaction->commit();
                         return TRUE;
                     } else {
                         $transaction->rollback();
                     }
                 } else {
                     //nếu ko có thêm role thì commit luôn
                     $transaction->commit();
                     return TRUE;
                 }
             }
         } catch (Exception $ex) {
             $transaction->rollback();
         }
     }
     return FALSE;
 }
 /**
  * Constructor.
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     $this->roles = Sentinel::getRoleRepository()->createModel();
 }