public function actionIndex($count = DEFAULT_PAGE_SIZE)
 {
     if (Yii::$app->request->isAjax) {
         Yii::$app->controller->module->layout = false;
     }
     $where_clause = null;
     if (isset(\Yii::$app->controller->searchFields)) {
         $argument_data = null;
         if (Yii::$app->request->isAjax) {
             $argument_data = $_REQUEST;
         }
         $where_clause = \vendor\codefire\cfusermgmt\models\Behavior\searchBehavior::search_behavior($argument_data);
     }
     $query = RoleAndPermission::find()->onCondition(['type' => TYPE_ROLE])->where($where_clause);
     //Type 1 is for Role (Type 2 is for permission);
     $activeDataProvider = new \yii\data\ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $count], 'sort' => ['defaultOrder' => ['name' => SORT_DESC], 'attributes' => ['created_at', 'name', 'role_alias', 'allow_registration']]]);
     $models = $activeDataProvider->getModels();
     return $this->render('index', ['activeDataProvider' => $activeDataProvider, 'models' => $models]);
 }
Ejemplo n.º 2
0
 public function register()
 {
     if (NEW_REGISTRATION_IS_ALLOWED) {
         $modelDetail = new UserDetail();
         $model = new User();
         $model->scenario = 'addUser';
         if ($model->load(Yii::$app->request->post())) {
             $file = \yii\web\UploadedFile::getInstance($model, 'img_path');
             if (isset($file) && !empty($file)) {
                 $filePath = USER_DIRECTORY_PATH . DS . USER_PROFILE_IMAGES_DIRECTORY . DS;
                 $model->img_path = Yii::$app->custom->uploadFile($file, $filePath);
             }
             if ($model->validate()) {
                 $model->auth_key = User::generateNewAuthKey();
                 $model->password_hash = User::setNewPassword($model->password);
                 if (isset($model->phone_number)) {
                     $model->phone_number = str_replace("-", "", $model->phone_number);
                 }
                 if (isset($model->dob)) {
                     $model->dob = date("Y-m-d", strtotime($model->dob));
                 }
                 if ($model->save(false)) {
                     /** Associated Model linking ***/
                     $modelDetail->user_id = $model->id;
                     $model->link("userDetail", $modelDetail);
                     $userGroups = RoleAndPermission::find()->onCondition(['type' => '1'])->asArray()->all();
                     $roleNames = [];
                     foreach ($userGroups as $userGroup) {
                         $roleNames[] = $userGroup['name'];
                     }
                     if (in_array(DEFAULT_ROLE_NAME, $roleNames)) {
                         $userRole = new AuthAssignment();
                         $userRole->item_name = DEFAULT_ROLE_NAME;
                         $userRole->user_id = $model->id;
                     }
                     $model->link("userRole", $userRole);
                     /** Associated Model linking ***/
                     if ($model->save(false)) {
                         if (!SEND_REGISTRATION_MAIL) {
                             User::sendMail('welcome-email', $model, $model->email, 'Welcome to - ' . SITE_NAME);
                         }
                         Yii::$app->session->setFlash('success', 'Please verify your Email. A verification link has been sent to your Email Address.');
                         return array('redirect' => true, 'url' => Url::to(['/usermgmt/user/login']));
                     } else {
                         Yii::$app->session->setFlash('success', 'Your registration was not successful.');
                         return array('redirect' => true, 'url' => Yii::$app->homeUrl);
                     }
                 }
             }
         }
         return array('render' => "register", 'model' => $model);
     } else {
         Yii::$app->session->setFlash('danger', 'Currently new registrations are not allowed by administrator. Please try later.');
         return array('redirect' => true, 'url' => Yii::$app->homeUrl);
     }
 }