Possibilité de s'inscrire avec l'adresse email d'un compte 'guest' : création d'un compte 'individual'refactoring
1 => 'Oui' | 1 => 'Oui' | ||||
], []); ?> | ], []); ?> | ||||
<?= $form->field($model, 'option_allow_order_guest') | |||||
<?php echo $form->field($model, 'option_allow_order_guest') | |||||
->dropDownList([ | ->dropDownList([ | ||||
0 => 'Non', | 0 => 'Non', | ||||
1 => 'Oui' | 1 => 'Oui' |
public function verifyEmail($attribute, $params) | public function verifyEmail($attribute, $params) | ||||
{ | { | ||||
if($this->id) { | if($this->id) { | ||||
$user = User::find()->where("email LIKE :email AND id != :id")->params(array(':email' => '%' . $this->email . '%', ':id' => $this->id))->one(); | |||||
$user = User::find()->where("email LIKE :email AND type != :guest AND id != :id")->params(array(':email' => '%' . $this->email . '%', ':id' => $this->id, ':guest' => 'guest'))->one(); | |||||
} | } | ||||
else { | else { | ||||
$user = User::find()->where("email LIKE :email")->params(array(':email' => '%' . $this->email . '%'))->one(); | |||||
$user = User::find()->where("email LIKE :email AND type != :guest")->params(array(':email' => '%' . $this->email . '%', ':guest' => 'guest'))->one(); | |||||
} | } | ||||
if ($user) { | if ($user) { |
$model = new SignupForm(); | $model = new SignupForm(); | ||||
if ($model->load(Yii::$app->request->post())) { | if ($model->load(Yii::$app->request->post())) { | ||||
$user = $model->signup(); | $user = $model->signup(); | ||||
if ($user) { | if ($user) { | ||||
if (Yii::$app->getUser()->login($user)) { | if (Yii::$app->getUser()->login($user)) { | ||||
if ($model->option_user_producer == 'producer') { | if ($model->option_user_producer == 'producer') { |
['email', 'filter', 'filter' => 'trim'], | ['email', 'filter', 'filter' => 'trim'], | ||||
['email', 'required', 'message' => 'Champs obligatoire'], | ['email', 'required', 'message' => 'Champs obligatoire'], | ||||
['email', 'email'], | ['email', 'email'], | ||||
['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'Cet email est déjà utilisé'], | |||||
['email', function($attribute, $params) { | |||||
$email = $this->$attribute; | |||||
$userExist = User::searchOne([ | |||||
'type' => 'individual', | |||||
'email' => $email | |||||
]); | |||||
if($userExist) { | |||||
$this->addError($attribute, 'Cet email est déjà utilisé.'); | |||||
} | |||||
}], | |||||
//['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'Cet email est déjà utilisé'], | |||||
[['name', 'lastname', 'phone'], 'required', 'message' => 'Champs obligatoire'], | [['name', 'lastname', 'phone'], 'required', 'message' => 'Champs obligatoire'], | ||||
[['name', 'lastname', 'phone', 'option_user_producer'], 'string', 'min' => 2, 'max' => 255], | [['name', 'lastname', 'phone', 'option_user_producer'], 'string', 'min' => 2, 'max' => 255], | ||||
['password', 'required', 'message' => 'Champs obligatoire'], | ['password', 'required', 'message' => 'Champs obligatoire'], |