|
|
|
|
|
|
|
|
namespace frontend\models; |
|
|
namespace frontend\models; |
|
|
|
|
|
|
|
|
use common\models\User; |
|
|
use common\models\User; |
|
|
|
|
|
use common\models\Etablissement; |
|
|
use yii\base\Model; |
|
|
use yii\base\Model; |
|
|
use Yii; |
|
|
use Yii; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public $prenom; |
|
|
public $prenom; |
|
|
public $telephone; |
|
|
public $telephone; |
|
|
public $is_boulanger; |
|
|
public $is_boulanger; |
|
|
|
|
|
|
|
|
public $siret; |
|
|
public $siret; |
|
|
public $nom_magasin; |
|
|
public $nom_magasin; |
|
|
|
|
|
|
|
|
|
|
|
public $code_postal; |
|
|
|
|
|
public $ville; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @inheritdoc |
|
|
* @inheritdoc |
|
|
*/ |
|
|
*/ |
|
|
public function rules() |
|
|
public function rules() |
|
|
{ |
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
/*['username', 'filter', 'filter' => 'trim'], |
|
|
|
|
|
['username', 'required'], |
|
|
|
|
|
['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'Cet identifiant est déjà utilisé'], |
|
|
|
|
|
['username', 'string', 'min' => 2, 'max' => 255],*/ |
|
|
|
|
|
|
|
|
|
|
|
['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', 'unique', 'targetClass' => '\common\models\User', 'message' => 'Cet email est déjà utilisé'], |
|
|
|
|
|
|
|
|
['nom','required','message'=>'Champs obligatoire'], |
|
|
|
|
|
['nom', 'string', 'min' => 2, 'max' => 255], |
|
|
|
|
|
|
|
|
|
|
|
['prenom','required','message'=>'Champs obligatoire'], |
|
|
|
|
|
['prenom', 'string', 'min' => 2, 'max' => 255], |
|
|
|
|
|
|
|
|
|
|
|
['telephone','required','message'=>'Champs obligatoire'], |
|
|
|
|
|
['telephone', 'string', 'min' => 2, 'max' => 255, 'message'=>'Bada'], |
|
|
|
|
|
|
|
|
[['nom', 'prenom', 'telephone', 'ville', 'code_postal'],'required','message'=>'Champs obligatoire'], |
|
|
|
|
|
[['nom', 'prenom', 'telephone', 'ville', 'code_postal'], 'string', 'min' => 2, 'max' => 255], |
|
|
|
|
|
|
|
|
['password', 'required','message'=>'Champs obligatoire'], |
|
|
['password', 'required','message'=>'Champs obligatoire'], |
|
|
['password', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'], |
|
|
['password', 'string', 'min' => 6, 'tooShort' => 'Votre mot de passe doit contenir au moins 6 caractères'], |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
if ($this->validate()) { |
|
|
if ($this->validate()) { |
|
|
$user = new User(); |
|
|
$user = new User(); |
|
|
//$user->username = $this->username; |
|
|
|
|
|
$user->username = $this->email; |
|
|
$user->username = $this->email; |
|
|
$user->email = $this->email; |
|
|
$user->email = $this->email; |
|
|
$user->nom = $this->nom ; |
|
|
$user->nom = $this->nom ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($this->is_boulanger) |
|
|
if($this->is_boulanger) |
|
|
{ |
|
|
{ |
|
|
$user->is_boulanger = 1 ; |
|
|
|
|
|
$user->nom_magasin = $this->nom_magasin ; |
|
|
|
|
|
$user->siret = $this->siret ; |
|
|
|
|
|
|
|
|
$etablissement = new Etablissement ; |
|
|
|
|
|
$etablissement->nom = $this->nom_magasin ; |
|
|
|
|
|
$etablissement->siret = $this->siret; |
|
|
|
|
|
$etablissement->code_postal = $this->code_postal; |
|
|
|
|
|
$etablissement->ville = $this->ville; |
|
|
|
|
|
$etablissement->save() ; |
|
|
|
|
|
|
|
|
|
|
|
$user->id_etablissement = $etablissement->id ; |
|
|
|
|
|
$user->status = User::STATUS_BOULANGER ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$user->setPassword($this->password); |
|
|
$user->setPassword($this->password); |
|
|
$user->generateAuthKey(); |
|
|
$user->generateAuthKey(); |
|
|
if ($user->save()) { |
|
|
if ($user->save()) { |
|
|
|
|
|
|
|
|
// envoi d'un mail de confirmation |
|
|
// envoi d'un mail de confirmation |
|
|
$message = "Bonjour, |
|
|
$message = "Bonjour, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'telephone' => 'Téléphone', |
|
|
'telephone' => 'Téléphone', |
|
|
'is_boulanger' => "Je suis professionnel et souhaite mettre en place un système de réservation de pain dans ma boulangerie", |
|
|
'is_boulanger' => "Je suis professionnel et souhaite mettre en place un système de réservation de pain dans ma boulangerie", |
|
|
'nom_magasin' => 'Nom de la boulangerie', |
|
|
'nom_magasin' => 'Nom de la boulangerie', |
|
|
'siret' => 'Numéro SIRET' |
|
|
|
|
|
|
|
|
'siret' => 'Numéro SIRET', |
|
|
|
|
|
'code_postal' => 'Code postal', |
|
|
|
|
|
'ville' => 'Commune' |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |