|
|
@@ -46,14 +46,13 @@ use yii\base\Model; |
|
|
|
*/ |
|
|
|
class LoginForm extends Model |
|
|
|
{ |
|
|
|
|
|
|
|
public $username; |
|
|
|
public $password; |
|
|
|
public $rememberMe = true; |
|
|
|
public $email; |
|
|
|
private $_user = false; |
|
|
|
public $code ; |
|
|
|
public $id_etablissement ; |
|
|
|
public $id_producer ; |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
@@ -72,26 +71,26 @@ class LoginForm extends Model |
|
|
|
// password is validated by validatePassword() |
|
|
|
['password', 'validatePassword'], |
|
|
|
['code', 'required', 'message' => 'Champs obligatoire', 'when' => function($model) { |
|
|
|
$etablissement = Etablissement::findOne($this->id_etablissement); |
|
|
|
if ($etablissement) { |
|
|
|
return strlen($etablissement->code); |
|
|
|
$producer = Producer::findOne($this->id_producr); |
|
|
|
if ($producer) { |
|
|
|
return strlen($producer->code); |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
}], |
|
|
|
['code', function($attribute, $params) { |
|
|
|
$code = $this->$attribute; |
|
|
|
$etablissement = Etablissement::findOne($this->id_etablissement); |
|
|
|
$producer = Producer::findOne($this->id_producer); |
|
|
|
|
|
|
|
if ($etablissement && strtolower(trim($code)) != strtolower(trim($etablissement->code))) { |
|
|
|
if ($producer && strtolower(trim($code)) != strtolower(trim($producer->code))) { |
|
|
|
$this->addError($attribute, 'Code incorrect'); |
|
|
|
} |
|
|
|
}], |
|
|
|
['id_etablissement', 'integer'], |
|
|
|
['id_etablissement', function($attribute, $params) { |
|
|
|
if ($this->id_etablissement) { |
|
|
|
$etablissement = Etablissement::findOne($this->id_etablissement); |
|
|
|
if (!$etablissement) { |
|
|
|
['id_producer', 'integer'], |
|
|
|
['id_producer', function($attribute, $params) { |
|
|
|
if ($this->id_producr) { |
|
|
|
$producer = Producer::findOne($this->id_producer); |
|
|
|
if (!$producer) { |
|
|
|
$this->addError($attribute, 'Ce producteur n\'existe pas.'); |
|
|
|
} |
|
|
|
} |
|
|
@@ -124,7 +123,7 @@ class LoginForm extends Model |
|
|
|
public function login() |
|
|
|
{ |
|
|
|
if ($this->validate()) { |
|
|
|
$this->updateDerniereConnexion(); |
|
|
|
$this->updateLastConnection(); |
|
|
|
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); |
|
|
|
} else { |
|
|
|
return false; |
|
|
@@ -153,16 +152,17 @@ class LoginForm extends Model |
|
|
|
'password' => 'Mot de passe', |
|
|
|
'rememberMe' => 'Se souvenir de moi', |
|
|
|
'email' => 'Email', |
|
|
|
'id_producer' => 'Producteur' |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Met à jour la date de dernière connexion de l'utilisateur. |
|
|
|
*/ |
|
|
|
public function updateDerniereConnexion() |
|
|
|
public function updateLastConnecion() |
|
|
|
{ |
|
|
|
$user = $this->getUser(); |
|
|
|
$user->date_derniere_connexion = date('Y-m-d H:i:s'); |
|
|
|
$user->date_last_connection = date('Y-m-d H:i:s'); |
|
|
|
$user->save(); |
|
|
|
} |
|
|
|
|