Kaynağa Gözat

Utilisateur : dernière connexion

Enregistrement de la dernière connexion de l'utilisateur et affichage de celle-ci dans le backend au niveau de la liste des utilisateurs.
prodstable
keun 8 yıl önce
ebeveyn
işleme
53cf002841
5 değiştirilmiş dosya ile 57 ekleme ve 11 silme
  1. +4
    -2
      backend/controllers/SiteController.php
  2. +18
    -0
      backend/views/user/index.php
  3. +17
    -9
      common/models/LoginForm.php
  4. +1
    -0
      common/models/User.php
  5. +17
    -0
      console/migrations/m161227_130138_champs_date_derniere_connexion.php

+ 4
- 2
backend/controllers/SiteController.php Dosyayı Görüntüle

@@ -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,
]);

+ 18
- 0
backend/views/user/index.php Dosyayı Görüntüle

@@ -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}',

+ 17
- 9
common/models/LoginForm.php Dosyayı Görüntüle

@@ -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() ;
}
}

+ 1
- 0
common/models/User.php Dosyayı Görüntüle

@@ -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'],
];
}


+ 17
- 0
console/migrations/m161227_130138_champs_date_derniere_connexion.php Dosyayı Görüntüle

@@ -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') ;
}
}

Yükleniyor…
İptal
Kaydet