Exemplo n.º 1
0
 /**
  * Create user page.
  */
 public function actionCreate()
 {
     $user = new User(['scenario' => 'admin-create']);
     $profile = new Profile();
     $statusArray = User::getStatusArray();
     $roleArray = User::getRoleArray();
     if ($user->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 return $this->redirect(['update', 'id' => $user->id]);
             } else {
                 Yii::$app->session->setFlash('danger', Module::t('users', 'BACKEND_FLASH_FAIL_ADMIN_CREATE'));
                 return $this->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return array_merge(ActiveForm::validate($user), ActiveForm::validate($profile));
         }
     }
     return $this->render('create', ['user' => $user, 'profile' => $profile, 'roleArray' => $roleArray, 'statusArray' => $statusArray]);
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied.
  *
  * @param array $params Search params
  *
  * @return ActiveDataProvider DataProvider
  */
 public function search($params)
 {
     $query = self::find()->joinWith(['profile']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['name'] = ['asc' => [Profile::tableName() . '.name' => SORT_ASC], 'desc' => [Profile::tableName() . '.name' => SORT_DESC]];
     $dataProvider->sort->attributes['surname'] = ['asc' => [Profile::tableName() . '.surname' => SORT_ASC], 'desc' => [Profile::tableName() . '.surname' => SORT_DESC]];
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status_id' => $this->status_id, 'role' => $this->role, 'FROM_UNIXTIME(created_at, "%d.%m.%Y")' => $this->created_at, 'FROM_UNIXTIME(updated_at, "%d.%m.%Y")' => $this->updated_at]);
     $query->andFilterWhere(['like', Profile::tableName() . '.name', $this->name]);
     $query->andFilterWhere(['like', Profile::tableName() . '.surname', $this->surname]);
     $query->andFilterWhere(['like', 'username', $this->username]);
     $query->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * User update page.
  */
 public function actionUpdate()
 {
     $model = Profile::findByUserId(Yii::$app->user->id);
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if ($model->save(false)) {
                 Yii::$app->session->setFlash('success', Yii::t('users', 'FRONTEND_FLASH_SUCCES_UPDATE'));
             } else {
                 Yii::$app->session->setFlash('danger', Yii::t('users', 'FRONTEND_FLASH_FAIL_UPDATE'));
             }
             return $this->refresh();
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
     }
     return $this->render('update', ['model' => $model]);
 }
Exemplo n.º 4
0
 /**
  * @return Profile|null User profile
  */
 public function getProfile()
 {
     return $this->hasOne(Profile::className(), ['user_id' => 'id'])->inverseOf('user');
 }
Exemplo n.º 5
-1
 /**
  * Sign Up page.
  * If record will be successful created, user will be redirected to home page.
  */
 public function actionSignup()
 {
     $user = new User(['scenario' => 'signup']);
     $profile = new Profile();
     if ($user->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 if ($this->module->requireEmailConfirmation === true) {
                     Yii::$app->session->setFlash('success', Module::t('users', 'FRONTEND_FLASH_SUCCESS_SIGNUP_WITHOUT_LOGIN', ['url' => Url::toRoute('resend')]));
                 } else {
                     Yii::$app->user->login($user);
                     Yii::$app->session->setFlash('success', Module::t('users', 'FRONTEND_FLASH_SUCCESS_SIGNUP_WITH_LOGIN'));
                 }
                 return $this->goHome();
             } else {
                 Yii::$app->session->setFlash('danger', Module::t('users', 'FRONTEND_FLASH_FAIL_SIGNUP'));
                 return $this->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($user);
         }
     }
     return $this->render('signup', ['user' => $user, 'profile' => $profile]);
 }