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; | ||||
} | } |
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) |
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']); | |||||
} | } | ||||
} | } | ||||
} | } |
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()) { |