Enregistrement de la dernière connexion de l'utilisateur et affichage de celle-ci dans le backend au niveau de la liste des utilisateurs.master
@@ -78,9 +78,11 @@ class SiteController extends BackendController | |||
} | |||
$model = new LoginForm(); | |||
if ($model->load(Yii::$app->request->post()) && $model->login()) { | |||
if ($model->load(Yii::$app->request->post()) && $model->login()) | |||
{ | |||
return $this->goBack(); | |||
} else { | |||
} | |||
else { | |||
return $this->render('login', [ | |||
'model' => $model, | |||
]); |
@@ -59,6 +59,24 @@ $this->params['breadcrumbs'][] = $this->title; | |||
['class' => 'form-control'] | |||
) | |||
], | |||
[ | |||
'attribute' => 'created_at', | |||
'label' => 'Date d\'inscription', | |||
'value' => function($model) { | |||
if(isset($model['created_at'])) | |||
return date('m/d/Y à H:i', $model['created_at']); | |||
} | |||
], | |||
[ | |||
'attribute' => 'date_derniere_connexion', | |||
'label' => 'Dernière connexion', | |||
'value' => function($model) { | |||
if(isset($model['date_derniere_connexion'])) | |||
return date('m/d/Y à H:i', strtotime($model['date_derniere_connexion'])); | |||
else | |||
return '' ; | |||
} | |||
], | |||
[ | |||
'class' => 'yii\grid\ActionColumn', | |||
'template' => '{commandes}', |
@@ -24,8 +24,8 @@ class LoginForm extends Model | |||
{ | |||
return [ | |||
['email', 'filter', 'filter' => 'trim'], | |||
['email', 'required','message'=>'Champs obligatoire'], | |||
['email', 'filter', 'filter' => 'trim'], | |||
['email', 'required','message'=>'Champs obligatoire'], | |||
['email', 'email'], | |||
// username and password are both required | |||
@@ -63,6 +63,7 @@ class LoginForm extends Model | |||
public function login() | |||
{ | |||
if ($this->validate()) { | |||
$this->updateDerniereConnexion() ; | |||
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); | |||
} else { | |||
return false; | |||
@@ -83,14 +84,21 @@ class LoginForm extends Model | |||
return $this->_user; | |||
} | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'username' => 'Identifiant', | |||
'password' => 'Mot de passe', | |||
public function attributeLabels() | |||
{ | |||
return [ | |||
'id' => 'ID', | |||
'username' => 'Identifiant', | |||
'password' => 'Mot de passe', | |||
'rememberMe' => 'Se souvenir de moi', | |||
'email' => 'Email', | |||
]; | |||
]; | |||
} | |||
public function updateDerniereConnexion() | |||
{ | |||
$user = $this->getUser() ; | |||
$user->date_derniere_connexion = date('Y-m-d H:i:s') ; | |||
$user->save() ; | |||
} | |||
} |
@@ -62,6 +62,7 @@ class User extends ActiveRecord implements IdentityInterface | |||
['email','verifyEmail'], | |||
['status', 'default', 'value' => self::STATUS_ACTIVE], | |||
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED, self::STATUS_ADMIN,self::STATUS_BOULANGER ]], | |||
[['date_derniere_connexion'],'safe'], | |||
]; | |||
} | |||
@@ -0,0 +1,17 @@ | |||
<?php | |||
use yii\db\Migration; | |||
use yii\db\Schema; | |||
class m161227_130138_champs_date_derniere_connexion extends Migration | |||
{ | |||
public function up() | |||
{ | |||
$this->addColumn('user', 'date_derniere_connexion', Schema::TYPE_DATETIME) ; | |||
} | |||
public function down() | |||
{ | |||
$this->dropColumn('user', 'date_derniere_connexion') ; | |||
} | |||
} |