Browse Source

Refactoring services #885

refactoring
Guillaume 1 year ago
parent
commit
1bc40a71fb
4 changed files with 13 additions and 15 deletions
  1. +1
    -1
      common/controllers/CommonController.php
  2. +2
    -2
      common/logic/User/User/Service/UserBuilder.php
  3. +9
    -11
      frontend/controllers/SiteController.php
  4. +1
    -1
      frontend/forms/SignupForm.php

+ 1
- 1
common/controllers/CommonController.php View File

return Yii::$app->urlManagerBackend; return Yii::$app->urlManagerBackend;
} }


public function getUserCurrent(): User
public function getUserCurrent(): ?User
{ {
return Yii::$app->user->identity; return Yii::$app->user->identity;
} }

+ 2
- 2
common/logic/User/User/Service/UserBuilder.php View File



public function initPassword(User $user, string $password) public function initPassword(User $user, string $password)
{ {
$user->setPassword($password);
$user->generateAuthKey();
$this->setPassword($user, $password);
$this->generateAuthKey($user);
} }


public function initProducer(User $user, Producer $producer) public function initProducer(User $user, Producer $producer)

+ 9
- 11
frontend/controllers/SiteController.php View File

if ($model->load(Yii::$app->request->post())) { if ($model->load(Yii::$app->request->post())) {
$user = $model->signup(); $user = $model->signup();


if ($user) {
if ($this->getUser()->login($user)) {
if ($model->isProducer()) {
$this->redirect(Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']));
if ($user && $this->getUserCurrent()->login($user)) {
if ($model->isProducer()) {
$this->redirect(Yii::$app->urlManagerBackend->createAbsoluteUrl(['site/index']));
}
else {
$producer = $producerManager->findOneProducerById($model->id_producer);
if ($producer) {
$this->redirect($this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]));
} }
else { else {
$producer = $producerManager->findOneProducerById($model->id_producer);
if ($producer) {
$this->redirect($this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer->slug]));
}
else {
$this->redirect(['site/index']);
}
$this->redirect(['site/index']);
} }
} }
} }

+ 1
- 1
frontend/forms/SignupForm.php View File



if ($user->save() && $producer) { if ($user->save() && $producer) {
// Liaison User / Producer // Liaison User / Producer
$producerManager->addUser($user->id, $idProducer);
$producerManager->addUser($user, $producer);


// Envoi d'un email de bienvenue à l'utilisateur // Envoi d'un email de bienvenue à l'utilisateur
if ($this->isCustomer()) { if ($this->isCustomer()) {

Loading…
Cancel
Save