/** * Resets password. * * @param string $token * @return mixed * @throws BadRequestHttpException */ public function actionResetPassword($id) { $user = Account::findOne($id); $model = new ResetPasswordForm($user); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (!$user->findByPasswordResetToken($model->password_reset_token)) { $model->addError('password_reset_token'); } else { $model->resetPassword(); Yii::$app->session->setFlash('success', 'Смена пароля была произведена успешно'); Yii::$app->user->login($user); return $this->redirect(Yii::$app->getUser()->getReturnUrl($this->goHome())); } } return $this->render('resetPassword', ['model' => $model]); /* try { $model = new ResetPasswordForm($token); } catch (InvalidParamException $e) { throw new BadRequestHttpException($e->getMessage()); } if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { Yii::$app->session->setFlash('success', 'New password was saved.'); return $this->goHome(); } return $this->render('resetPassword', [ 'model' => $model, ]); */ }
public function actionReserveACarStep2($id) { if (Yii::$app->user->isGuest) { return $this->redirect(['/cars/reserve-a-car-step-login', 'id' => $id]); } $clientUserData = Yii::$app->user->identity->userData; if (empty($clientUserData)) { $this->setForbiddenHttpException('Произошла ошибка'); //данные по клиенту должны были быть занесены на первом шаге } $rentModel = $this->findRentModel($id); $systemModel = $rentModel->system; $prepareModel = UsersData::findOne($rentModel->user_data_id); $passwordFormModel = new ResetPasswordForm(Yii::$app->user->identity); $passwordFormModel->setScenario('change'); //$prepareModel->setScenario('client-validate'); if (Yii::$app->request->post()) { if ($passwordFormModel->load(Yii::$app->request->post())) { if ($passwordFormModel->validate()) { $passwordFormModel->resetPassword(); Yii::$app->session->setFlash('success', 'Смена пароля была произведена успешно'); } } if ($prepareModel->load(Yii::$app->request->post())) { $changedAttributes = $prepareModel->loadImages(); $changedAttributes = array_merge($prepareModel->getDirtyAttributes(), $changedAttributes); if ($prepareModel->save()) { if (!empty($changedAttributes)) { $clientUserData->setAttributes($changedAttributes); $clientUserData->save(); } if ($rentModel->system->isCanPay) { return $this->redirect(['/cars/reserve-a-car-step3', 'id' => $rentModel->id]); } else { Yii::$app->session->setFlash('info', self::TEXT_RENT_SUCCESS); return $this->redirect($rentModel->system->PageReserve); } } } } else { if (!empty($clientUserData)) { $prepareModel->setAttributes($clientUserData->getAttributes()); } else { $prepareModel->loadDefaultValues(); } } return $this->render('reserveCar', ['systemModel' => $systemModel, 'rentModel' => $rentModel, 'stepForm' => 2, 'prepareModel' => $prepareModel, 'passwordFormModel' => $passwordFormModel]); }
/** * Resets password. * * @param string $token * @return mixed * @throws BadRequestHttpException */ public function actionResetPassword($token) { try { $model = new ResetPasswordForm($token); } catch (InvalidParamException $e) { throw new BadRequestHttpException($e->getMessage()); } if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) { Yii::$app->session->setFlash('success', Yii::t('frontend', 'New password saved.')); return $this->goHome(); } return $this->render('resetPassword', ['model' => $model]); }