Browse Source

Indentation + commentaires modèle LoginForm

dev
Guillaume Bourgeois 6 years ago
parent
commit
d615b17ea6
1 changed files with 17 additions and 7 deletions
  1. +17
    -7
      common/models/LoginForm.php

+ 17
- 7
common/models/LoginForm.php View File

@@ -44,7 +44,8 @@ use yii\base\Model;
/**
* Login form
*/
class LoginForm extends Model {
class LoginForm extends Model
{

public $username;
public $password;
@@ -57,7 +58,8 @@ class LoginForm extends Model {
/**
* @inheritdoc
*/
public function rules() {
public function rules()
{
return [

['email', 'filter', 'filter' => 'trim'],
@@ -104,7 +106,8 @@ class LoginForm extends Model {
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params) {
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
@@ -118,7 +121,8 @@ class LoginForm extends Model {
*
* @return boolean whether the user is logged in successfully
*/
public function login() {
public function login()
{
if ($this->validate()) {
$this->updateDerniereConnexion();
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
@@ -132,7 +136,8 @@ class LoginForm extends Model {
*
* @return User|null
*/
public function getUser() {
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByEmail($this->email);
}
@@ -140,7 +145,8 @@ class LoginForm extends Model {
return $this->_user;
}

public function attributeLabels() {
public function attributeLabels()
{
return [
'id' => 'ID',
'username' => 'Identifiant',
@@ -150,7 +156,11 @@ class LoginForm extends Model {
];
}

public function updateDerniereConnexion() {
/**
* Met à jour la date de dernière connexion de l'utilisateur.
*/
public function updateDerniereConnexion()
{
$user = $this->getUser();
$user->date_derniere_connexion = date('Y-m-d H:i:s');
$user->save();

Loading…
Cancel
Save