public function run() { $request = Yii::$app->request; $ident = Yii::$app->user->getIdentity(); $form = new ProfileForm(); if ($request->isPost) { $form->load($request->bodyParams); if ($form->validate()) { $transaction = Yii::$app->db->beginTransaction(); try { $ident->attributes = $form->attributes; $ident->env_id = $this->findOrCreateEnvironmentId($form->env); $ident->is_black_out_others = $form->is_black_out_others == '1'; if ($ident->save()) { $transaction->commit(); $this->controller->redirect(['user/profile']); return; } } catch (\Exception $e) { } $transaction->rollback(); } } else { $form->attributes = $ident->attributes; if ($ident->env) { $form->env = $ident->env->text; } $form->is_black_out_others = $ident->is_black_out_others ? '1' : '0'; } return $this->controller->render('edit-profile.tpl', ['user' => $ident, 'form' => $form]); }
/** * Creates a new ProfileForm model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ProfileForm(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionProfile() { if (!is_null($user = $this->getLoggedUser())) { $profile = new ProfileForm($user); if (Yii::$app->request->isPost && $profile->load(Yii::$app->request->post()) && $profile->validate() && $profile->update($user)) { } return $this->render('profile', ['model' => $profile, 'user' => $user]); } else { return $this->redirect(['site/register']); } }
public function actionUpdate() { $user = $this->findModel(); $model = new ProfileForm($user); if ($model->load(Yii::$app->request->post()) && $model->update()) { return $this->redirect(['profile']); } else { echo 'F**K! Update() does not work!'; if ($model->status == User::SCENARIO_PERSON) { return $this->render('update-person', ['model' => $model]); } elseif ($model->status == User::SCENARIO_COMPANY) { return $this->render('update-company', ['model' => $model]); } else { false; } } }
public function actionIndex() { $request = \Yii::$app->request; $session = \Yii::$app->session; $profileForm = new ProfileForm(); $user = \Yii::$app->user->identity; $accountId = $user->getId(); if (!$this->checkForProfile($accountId)) { if ($profileForm->load($request->post())) { $session->set('newProfile', $request->post('ProfileForm')); return $this->redirect('@web/index.php/profile/add-profile'); } else { return $this->render('setup-profile', ["ProfileForm" => $profileForm]); } } return $this->redirect('@web/index.php/profile/view-profile'); }
public function run() { $request = Yii::$app->request; $ident = Yii::$app->user->getIdentity(); $form = new ProfileForm(); if ($request->isPost) { $form->load($request->bodyParams); if ($form->validate()) { $ident->attributes = $form->attributes; if ($ident->save()) { $this->controller->redirect(['user/profile']); return; } } } else { $form->attributes = $ident->attributes; } return $this->controller->render('edit-profile.tpl', ['user' => $ident, 'form' => $form]); }