[ 'class' => AccessControl::class, 'only' => ['logout', 'signup'], 'rules' => [ [ 'actions' => ['signup'], 'allow' => true, 'roles' => ['?'], ], [ 'actions' => ['logout'], 'allow' => true, 'roles' => ['@'], ], ], ], 'verbs' => [ 'class' => VerbFilter::class, 'actions' => [ 'logout' => ['get'], ], ], ]; } /** * @inheritdoc */ public function actions() { return [ 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, ], ]; } /** * Affiche la page d'erreur. * * @return mixed */ public function actionError() { $exception = \Yii::$app->errorHandler->exception; if ($exception->getMessage() == 'Producteur introuvable' || \Yii::$app->getRequest()->getQueryParam('producer_not_found')) { return $this->render('error-404-producer', ['exception' => $exception]); } if ($exception !== null) { return $this->render('error', ['exception' => $exception]); } } /** * Affiche la page d'accueil. */ public function actionIndex() { return $this->render('index', [ 'producerDemoAccount' => $this->getProducerManager()->findOneProducerDemoAccount(), 'dataProviderPrices' => $this->getDataProviderPrices() ]); } /** * Page de présentation des tarifs. */ public function actionPrices() { return $this->render('prices', [ 'dataProviderPrices' => $this->getDataProviderPrices() ]); } public function getDataProviderPrices() { return new ActiveDataProvider([ 'query' => $this->getProducerPriceRangeManager()->queryProducerPriceRanges(), 'pagination' => [ 'pageSize' => 100, ], ]); } /** * Liste les producteurs utilisant la plateforme. */ public function actionProducers() { $dataProviderProducers = new ActiveDataProvider([ 'query' => $this->getProducerManager()->queryProducersActive(), 'pagination' => [ 'pageSize' => 100, ], ]); return $this->render('producers', [ 'dataProviderProducers' => $dataProviderProducers ]); } /** * Affiche la page de connexion et traite le formulaire de connexion. */ public function actionLogin() { if (!\Yii::$app->user->isGuest) { return \Yii::$app->getResponse()->redirect(['site/index']); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { $returnUrl = \Yii::$app->request->get('return_url'); if ($returnUrl) { return $this->redirect($returnUrl); } else { $userProducerArray = $this->getUserProducerManager()->findUserProducersByUser(GlobalParam::getCurrentUser()); if ($userProducerArray && is_array($userProducerArray) && count($userProducerArray) == 1) { $urlRedirect = $this->getUrlManagerProducer() ->createAbsoluteUrl([ 'site/index', 'slug_producer' => $userProducerArray[0]->producer->slug ]); return $this->redirect($urlRedirect); } else { return $this->goBack(); } } } else { return $this->render('@frontend/views/site/login', [ 'model' => $model, ]); } } /** * Déconnecte l'utilisateur. */ public function actionLogout() { \Yii::$app->user->logout(); return $this->goHome(); } /** * Affiche la page de contact et traite le formulaire s'il est soumis. */ public function actionContact() { $model = new ContactForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->sendEmail(Yii::$app->params['adminEmail'])) { $this->setFlash('success', 'Votre message a bien été envoyé. Nous vous répondrons dès que possible.'); } else { $this->setFlash('error', 'Il y a eu une erreur lors de l\'envoi de votre message.'); } return $this->refresh(); } else { return $this->render('contact', [ 'model' => $model, ]); } } /** * Affiche la page d'inscription et traite son formulaire. */ public function actionSignup() { $model = new SignupForm(); $producerManager = $this->getProducerManager(); if ($model->load(Yii::$app->request->post())) { $user = $model->signup(); if ($user && Yii::$app->getUser()->login($user)) { if ($model->isProducer()) { $this->redirect(['site/signup-confirm']); } else { $producer = $producerManager->findOneProducerById($model->id_producer); if ($producer) { $this->redirect(['site/signup-confirm', 'idProducerRedirect' => $producer->id]); } else { $this->redirect(['site/index']); } } } } // Liste des producteurs disponibles $producersArray = $producerManager->populateProducerDropdown(); $dataProducers = $producersArray['data']; $optionsProducers = $producersArray['options']; return $this->render('signup', [ 'model' => $model, 'dataProducers' => $dataProducers, 'dataProviderPrices' => $this->getDataProviderPrices(), 'optionsProducers' => $optionsProducers, ]); } public function actionSignupConfirm($idProducerRedirect = null) { $producerManager = $this->getProducerManager(); $user = $this->getUserCurrent(); $producerRedirect = $idProducerRedirect ? $producerManager->findOneProducerById($idProducerRedirect) : null ; if(!$user) { throw new NotFoundHttpException('Page introuvable'); } return $this->render('signup_confirm', [ 'user' => $user, 'producerRedirect' => $producerRedirect ]); } /** * Affiche la page de demande de nouveau mot de passe. * Traitement du formulaire. */ public function actionRequestPasswordReset() { $model = new PasswordResetRequestForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->sendEmail()) { $this->setFlash('success', 'Un lien vous permettant de réinitialiser votre mot de passe vient d\'être envoyé sur votre boîte mail.'); return $this->goHome(); } else { $this->setFlash('error', 'Sorry, we are unable to reset password for email provided.'); } } return $this->render('requestPasswordResetToken', [ 'model' => $model, ]); } /** * Met à jour le mot de passe de l'utilisateur. */ public function actionResetPassword($token) { try { $model = new ResetPasswordForm($token); } catch (InvalidParamException $e) { throw new BadRequestHttpException($e->getMessage()); } if ($model->load($this->getRequest()->post()) && $model->validate() && $model->resetPassword()) { $this->setFlash('success', 'Votre nouveau mot de passe vient d\'être sauvegardé.'); return $this->goHome(); } return $this->render('resetPassword', [ 'model' => $model, ]); } /** * Affiche le formulaire de demande de code pour accéder à certains producteurs. */ public function actionProducerCode(int $id) { $producerManager = $this->getProducerManager(); $producer = $producerManager->findOneProducerById($id); if (!$producer) { throw new \yii\web\HttpException(404, 'Producteur introuvable'); } $producerCodeForm = new ProducerCodeForm(); $producerCodeForm->id_producer = $id; if ($producerCodeForm->load($this->getRequest()->post()) && $producerCodeForm->validate()) { $producerManager->addUser(GlobalParam::getCurrentUser(), $producer); $this->redirect($this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); } return $this->render('producer_code', [ 'producer' => $producer, 'producerCodeForm' => $producerCodeForm, ]); } /** * Affiche la page de connexion / inscription pour accéder notamment au * formulaire de commande des producteurs. */ public function actionProducer(int $id) { $loginForm = new LoginForm(); $signupForm = new SignupForm(); $producerManager = $this->getProducerManager(); $producer = $producerManager->findOneProducerById($id); $loginForm->id_producer = $id; $signupForm->id_producer = $id; $signupForm->option_user_producer = 'user'; $returnUrl = $this->getRequest()->get('returnUrl', $this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug])); if ($this->getUser()->isGuest) { if ($loginForm->load($this->getRequest()->post()) && $loginForm->login()) { if (!strlen($producer->code)) { $producerManager->addUser(GlobalParam::getCurrentUser(), $producer); } $this->redirect($returnUrl); } if ($signupForm->load($this->getRequest()->post()) && ($user = $signupForm->signup()) && $this->getUser()->login($user)) { $this->redirect($returnUrl); } } else { $this->redirect($returnUrl); } return $this->render('producer', [ 'loginForm' => $loginForm, 'signupForm' => $signupForm, 'producer' => $producer, ]); } /** * Indique à l'utilisateur que l'espace d'un producteur est hors ligne. */ public function actionProducerOffline(int $id) { return $this->render('producer_offline', [ 'producer' => $this->getProducerManager()->findOneProducerById($id), ]); } /** * Affiche les mentions légales. */ public function actionMentions() { return $this->render('mentions'); } /** * Affiche les conditions générale de service. */ public function actionCgv() { return $this->render('cgv'); } /** * Affiche les précisions concernant l'utilisation du crédit. */ public function actionCredit() { return $this->render('credit'); } }