Beispiel #1
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->company_id = $this->company_id;
         $user->first_name = $this->first_name;
         $user->last_name = $this->last_name;
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $permissionList = $_POST['SignupForm']['permissions'];
             foreach ($permissionList as $value) {
                 $newPermissions = new AuthAssignment();
                 $newPermissions->user_id = $user->id;
                 $newPermissions->item_name = $value;
                 $newPermissions->save();
                 $newPermissions->getErrors();
             }
             return $user;
         }
     }
     return null;
 }
Beispiel #2
0
 public function actionAddData()
 {
     $model = new UserBackend();
     $auth = new AuthAssignment();
     if ($model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         $user = new User();
         $user->username = $_POST['UserBackend']['username'];
         $user->email = $_POST['UserBackend']['email'];
         $user->setPassword('123456');
         $user->generateAuthKey();
         $user->status = 10;
         if ($user) {
             $auth = new AuthAssignment();
             $auth->item_name = $_POST['AuthAssignment']['item_name'];
             $auth->user_id = 17;
             $auth->created_at = 1428931496;
             if ($auth->save()) {
                 $res = array('message' => 'Data Berhasil Di Simpan.', 'alert' => 'success', 'proses' => 'save', 'success' => true);
             } else {
                 $res = array('message' => 'Data Gagal Di Simpan.', 'alert' => 'error', 'proses' => 'save', 'success' => false);
             }
         } else {
             $res = array('message' => 'Data Gagal Di Simpan.', 'alert' => 'error', 'proses' => 'save', 'success' => false);
         }
         return $res;
         \Yii::$app->end();
     } else {
         return $this->renderAjax('create', ['model' => $model, 'auth' => $auth]);
     }
 }
 public static function reassign()
 {
     $auth = \Yii::$app->authManager;
     $auth->removeAllAssignments();
     // all assignment
     $query = AuthAssignment::find();
     $model = $query->all();
     foreach ($model as $list) {
         $auth->assign($auth->getRole($list->itemname), 'u:' . $list->userid);
     }
 }
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if (!$this->validate()) {
         return null;
     }
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     return $user->save() ? $user : null;
     //creating permissions
     $permissionList = $_POST['SignupForm']['permissions'];
     foreach ($permissionList as $value) {
         $newPermission = new AuthAssignment();
         $newPermission->user_id = $user->id;
         $newPermission->item_name = $value;
         $newPermission->save();
     }
 }
 public function search($params)
 {
     $query = AuthAssignment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'item_name', $this->item_name])->andFilterWhere(['like', 'user_id', $this->user_id]);
     return $dataProvider;
 }
 public function actionAdd()
 {
     $model = new User();
     if (\Yii::$app->request->isPost) {
         $user = \Yii::$app->request->post('User');
         $model->attributes = \Yii::$app->request->post('User');
         $model->position = \Yii::$app->request->post('type');
         $password = \Yii::$app->request->post('password');
         $model->status = 10;
         if ($password) {
             $model->setPassword($password);
             $model->generateAuthKey();
         }
         if ($model->save()) {
             if (\Yii::$app->request->post('type')) {
                 switch (\Yii::$app->request->post('type')) {
                     case 1:
                         $auth = 'thanagorn.role.admin';
                         break;
                     case 2:
                         $auth = 'thanagorn.role.staff';
                         break;
                 }
                 $modelauth = new AuthAssignment();
                 $modelauth->itemname = $auth;
                 $modelauth->userid = $user['username'];
                 $modelauth->data = 'N;';
                 if ($modelauth->save()) {
                     //AuthController::reassign();
                 } else {
                     Ui::setMessage('ไม่สามารถ กำหนนดสิทธิ์ ได้', 'warning');
                 }
             }
             Ui::setMessage('บันทึกข้อมูลสำเร็จ');
             return $this->redirect(Url::toRoute('user/list'));
         } else {
             Ui::setMessage('การบันทึกข้อมูลผิดพลาด', 'warning');
         }
     }
     echo $this->render('add', ['model' => $model]);
 }
Beispiel #7
0
 /**
  * Returns "league" role of user, from roles attributiion. Default is golfer. Null if not loggued in.
  */
 public static function getRole()
 {
     if (!Yii::$app->user->isGuest) {
         if ($role = AuthAssignment::findOne(['user_id' => Yii::$app->user->identity->id])) {
             if ($key = array_search($role->item_name, Yii::$app->params['league_roles'])) {
                 return $key;
             }
         }
         return self::DEFAULT_ROLE;
     }
     return null;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AuthAssignment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['created_at' => $this->created_at, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'item_name', $this->item_name]);
     return $dataProvider;
 }
Beispiel #9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthAssignments()
 {
     return $this->hasMany(AuthAssignment::className(), ['item_name' => 'name']);
 }
 /**
  * Finds the AuthAssignment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $item_name
  * @param string $user_id
  * @return AuthAssignment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($user_id)
 {
     if (($model = AuthAssignment::findOne(['user_id' => $user_id])) !== null) {
         return $model;
     } else {
         return new AuthAssignment();
     }
 }
Beispiel #11
0
 /**
  * @inheritdoc
  * Добавление связи роль=>пользователь в таблицу auth_assignment (RBAC)
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     AuthAssignment::deleteAll(['user_id' => $this->id]);
     /** @var \common\models\AuthItem $role */
     $role = AuthItem::findOne($this->role_id);
     if ($role) {
         $assign = new AuthAssignment();
         $assign->user_id = (string) $this->id;
         $assign->item_name = $role->name;
         $assign->created_at = time();
         $assign->save();
     }
     return true;
 }
Beispiel #12
0
</h1>

            <p>
                <?php 
if (Yii::$app->user->can(User::PERMISSION_CREATE)) {
    ?>
                    <?php 
    echo Html::a('Create User', ['create'], ['class' => 'btn btn-success']);
    ?>
                <?php 
}
?>
            </p>

            <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'auth', 'value' => 'auth.item_name', 'label' => 'Role', 'filter' => Html::activeDropDownList($searchModel, 'auth', \common\models\AuthAssignment::getRoles(), ['class' => 'form-control', 'prompt' => ''])], ['attribute' => 'username', 'filter' => AutoComplete::widget(['model' => $searchModel, 'attribute' => 'username', 'options' => ['class' => 'form-control'], 'clientOptions' => ['source' => User::getAutoCompleteItems('username')]])], ['attribute' => 'email', 'format' => 'email', 'filter' => AutoComplete::widget(['model' => $searchModel, 'attribute' => 'email', 'options' => ['class' => 'form-control'], 'clientOptions' => ['source' => User::getAutoCompleteItems('email')]])], ['attribute' => 'last_login', 'filter' => false, 'format' => 'date'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update}{delete}', 'buttons' => ['update' => function ($url, $model, $key) {
    $options = ['title' => Yii::t('yii', 'Update'), 'aria-label' => Yii::t('yii', 'Update'), 'data-method' => 'post', 'data-pjax' => '0'];
    if (Yii::$app->user->can(User::PERMISSION_UPDATE) && Yii::$app->user->can(User::PERMISSION_CAN_CUD, $model)) {
        return Html::a('<span class="glyphicon glyphicon-pencil"></span>', Url::toRoute(['user/update', 'id' => $model->id]), $options);
    }
    return '';
}, 'delete' => function ($url, $model, $key) {
    $options = ['title' => Yii::t('yii', 'Delete'), 'aria-label' => Yii::t('yii', 'Delete'), 'data-method' => 'post', 'data-confirm' => 'Are you sure you want to delete this item?', 'data-pjax' => '0'];
    if (Yii::$app->user->can(User::PERMISSION_DELETE) && Yii::$app->user->can(User::PERMISSION_CAN_CUD, $model)) {
        return Html::a('<span class="glyphicon glyphicon-trash"></span>', Url::toRoute(['user/delete', 'id' => $model->id]), $options);
    }
    return '';
}]]]]);
?>
        </div>
    </div>
Beispiel #13
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthAssignments()
 {
     return $this->hasMany(AuthAssignment::className(), ['user_id' => 'id']);
 }
Beispiel #14
0
 /**
  * Verifica si el usuario tiene rol indicado
  * @param $usuario
  * @param $rol
  * @return bool
  */
 private static function tieneRolAsignado($usuario, $rol)
 {
     return AuthAssignment::find()->where('user_id = :usuario and item_name = :rol', [':usuario' => $usuario, ':rol' => $rol])->exists();
 }
 /**
  * Finds the AuthAssignment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return AuthAssignment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AuthAssignment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Finds the AuthAssignment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $item_name
  * @param string $user_id
  * @return AuthAssignment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($item_name, $user_id)
 {
     if (($model = AuthAssignment::findOne(['item_name' => $item_name, 'user_id' => $user_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #17
0
 public static function getPeremission($username)
 {
     $query = AuthAssignment::find();
     $query->where(['userid' => $username]);
     $model = $query->one();
     return $model;
 }
Beispiel #18
0
 /**
  * Verifica si un usuario ya tiene asignado un rol
  * @param $rol
  * @param $usuario
  * @return bool
  */
 private function tienePermisosUsuario($rol, $usuario)
 {
     return AuthAssignment::find()->where('item_name = :rol and user_id = :usuario', [':rol' => $rol, ':usuario' => $usuario])->exists();
 }
Beispiel #19
0
            <?php 
echo $form->field($model, 'phone')->textInput(['maxlength' => 100]);
?>

            <?php 
echo $form->field($modelSignUp, 'email')->textInput(['maxlength' => 500]);
?>

            <?php 
if (Yii::$app->user->can("admin") || Yii::$app->user->can("hrm")) {
    echo $form->field($model, 'position')->textInput(['maxlength' => 2000]);
    if ($model->isNewRecord) {
        echo $form->field($model, 'manager')->dropDownList(ArrayHelper::map($model->find()->rightJoin('auth_assignment', 'user_info.user_id = auth_assignment.user_id')->where(array('item_name' => 'director'))->orWhere(array('item_name' => 'manager'))->all(), 'user_id', 'full_name'), array('prompt' => '--Select a manager--'))->label('Manager');
    } else {
        $position = \common\models\AuthAssignment::find()->where(['user_id' => $model->user_id])->one();
        //Neu la staff thi hien thi list manager.
        if ($position !== null && $position->item_name === "staff") {
            echo $form->field($model, 'manager')->dropDownList(ArrayHelper::map($model->find()->rightJoin('auth_assignment', 'user_info.user_id = auth_assignment.user_id')->where(array('item_name' => 'manager'))->all(), 'user_id', 'full_name'), array('prompt' => '--Select a manager--'))->label('Manager');
        }
        if ($position !== null && $position->item_name === "manager" || $position->item_name === "hrm") {
            echo $form->field($model, 'manager')->dropDownList(ArrayHelper::map($model->find()->rightJoin('auth_assignment', 'user_info.user_id = auth_assignment.user_id')->where(array('item_name' => 'director'))->all(), 'user_id', 'full_name'), array('prompt' => '--Select a director--'))->label('Director');
        }
        //Neu la manager thi hien thi director.
    }
}
?>
        </div>
    </div>

    <div class="form-group">
 public function actionCheckApplication($id)
 {
     //$model = $this->findModel($id);
     $query = Application::find();
     $query->joinWith(['user', 'reasonApplication']);
     $query->where(['application.id' => $id]);
     $model = $query->one();
     if ($model === null) {
         throw new NotFoundHttpException('The letter has been deleted.');
     }
     if ($model->load(Yii::$app->request->post())) {
         // Gui mail bao cho manager biet co dua xin nghi.
         $link = Html::a('Click me!', Yii::$app->urlManager->createAbsoluteUrl(['application/view', 'id' => $model->id]));
         $user_manager = UserInfo::findOne(['user_id' => $model->user->manager]);
         if (Yii::$app->user->can('manager')) {
             if ($model->manager_ok == 0) {
                 $title = "Manager Refuse: ";
             }
             if ($model->manager_ok == 1) {
                 $model->manager_id_ok = Yii::$app->user->id;
                 $model->hrm_ok = 1;
                 $title = "Manager Accept: ";
             }
         }
         if (Yii::$app->user->can('hrm')) {
             if ($model->hrm_ok == 0) {
                 $title = "HRM Refuse: ";
             }
             if ($model->hrm_ok == 1) {
                 $model->hrm_id_ok = Yii::$app->user->id;
                 $title = "HRM Accept: ";
             }
         }
         $body = $this->renderPartial('email_result', ['model' => $model, 'link' => $link, 'user_manager' => $user_manager]);
         if ($model->manager_ok == 1 && Yii::$app->user->can('manager')) {
             //Gửi mail báo cho quản lý nhân sự
             $link2 = Html::a('Click me!', Yii::$app->urlManager->createAbsoluteUrl(['application/check-application', 'id' => $model->id]));
             $body = $this->renderPartial('email_result', ['model' => $model, 'link' => $link2, 'user_manager' => $user_manager]);
             $hrm_id = AuthAssignment::findOne(['item_name' => 'hrm'])->user_id;
             $user_hrm = UserInfo::findOne(['user_id' => $hrm_id]);
             $this->sendMail($user_hrm->email, $user_manager->email, $user_manager->full_name, $title . $model->reasonApplication->name, $body);
         }
         if ($model->manager_ok == 0 || $model->hrm_ok == 0) {
             $model->save(false);
             if ($this->sendMail($model->user->email, $user_manager->email, $user_manager->full_name, $title . $model->reasonApplication->name, $body)) {
                 Yii::$app->session->setFlash('success', 'Your message has been sent to the staff !');
             } else {
                 Yii::$app->session->setFlash('error', 'Unable to send a letter to the staff. Please call the staff. Staff\'s phone: .' . $user_manager->phone);
             }
             return $this->redirect(['application/application-of-room', 'id' => Yii::$app->user->id]);
         } else {
             if ($model->save() && $user_manager !== null && ($model->manager_ok != -1 || $model->hrm_ok != -1)) {
                 if ($this->sendMail($model->user->email, $user_manager->email, $user_manager->full_name, $title . $model->reasonApplication->name, $body)) {
                     Yii::$app->session->setFlash('success', 'Your message has been sent to the staff !');
                 } else {
                     Yii::$app->session->setFlash('error', 'Unable to send a letter to the staff. Please call the staff. Staff\'s phone: .' . $user_manager->phone);
                 }
                 return $this->redirect(['application/application-of-room', 'id' => Yii::$app->user->id]);
             }
         }
     } else {
         //Thiet lap truong da doc don cua nhan vien
         if (Yii::$app->user->can('hrm')) {
             $model->hrm_readed = 1;
         }
         if (Yii::$app->user->can('manager')) {
             $model->manager_readed = 1;
         }
         if (!$model->save(true, ['hrm_readed', 'manager_readed'])) {
             throw new NotFoundHttpException('The Error in saving status readed of manager and hrm.');
         }
     }
     return $this->render('check-application', ['model' => $model]);
 }