protected function findModel($id) { if (($model = UsersData::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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]); }
public function actionGetProtectedImage($userdataid, $file, $w = '1200', $h = '1200') { $resImage = false; if (!Yii::$app->user->isGuest) { $userData = UsersData::findOne($userdataid); if ($userData) { $resImage = $userData->getThumbSecretPhoto($userdataid, $file, $w, $h); } if ($resImage) { $resImage->show('jpg', ['quality' => 80]); } } Yii::$app->end(); }
/** * find user userData from salon userData * * @param $account_id * @return null|static */ public function findUserData() { return UsersData::findOne(['account_id' => $this->account_id, 'salon_account_id' => null]); }
public function getUserData() { //return $this->hasOne(UsersData::className(), ['account_id' => 'id', 'salon_account_id' => 'id']); return UsersData::findOne(['account_id' => $this->id, 'salon_account_id' => null]); }