Added last_login_at field to user table
This commit is contained in:
@ -4,6 +4,7 @@
|
|||||||
- Fix #37: Fix bower alias in test environment (tekord)
|
- Fix #37: Fix bower alias in test environment (tekord)
|
||||||
- Enh #32: Added Italian Translation (maxxer)
|
- Enh #32: Added Italian Translation (maxxer)
|
||||||
- Fix #30: Prefill username and email in SettingsForm (mattheobjornson)
|
- Fix #30: Prefill username and email in SettingsForm (mattheobjornson)
|
||||||
|
- Enh #39: Added `last_login_at` field to user table (pappfer)
|
||||||
|
|
||||||
## 1.0.9 - July 19, 2017
|
## 1.0.9 - July 19, 2017
|
||||||
- Enh #22: Added impersonation feature (@tonydspaniard)
|
- Enh #22: Added impersonation feature (@tonydspaniard)
|
||||||
|
|||||||
@ -117,6 +117,7 @@ class LoginForm extends Model
|
|||||||
{
|
{
|
||||||
if ($this->validate()) {
|
if ($this->validate()) {
|
||||||
$duration = $this->rememberMe ? $this->module->rememberLoginLifespan : 0;
|
$duration = $this->rememberMe ? $this->module->rememberLoginLifespan : 0;
|
||||||
|
$this->user->updateAttributes(['last_login_at' => time()]);
|
||||||
|
|
||||||
return Yii::$app->getUser()->login($this->user, $duration);
|
return Yii::$app->getUser()->login($this->user, $duration);
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/User/Migration/m000000_000005_add_last_login_at.php
Normal file
27
src/User/Migration/m000000_000005_add_last_login_at.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the 2amigos/yii2-usuario project.
|
||||||
|
*
|
||||||
|
* (c) 2amigOS! <http://2amigos.us/>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Da\User\Migration;
|
||||||
|
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m000000_000004_create_token_table extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$this->addColumn('{{%user}}', 'last_login_at', $this->integer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$this->dropColumn('{{%user}}', 'last_login_at');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -43,6 +43,7 @@ use yii\web\IdentityInterface;
|
|||||||
* @property int $flags
|
* @property int $flags
|
||||||
* @property int $created_at
|
* @property int $created_at
|
||||||
* @property int $updated_at
|
* @property int $updated_at
|
||||||
|
* @property int $last_login_at
|
||||||
*
|
*
|
||||||
* Defined relations:
|
* Defined relations:
|
||||||
* @property SocialNetworkAccount[] $socialNetworkAccounts
|
* @property SocialNetworkAccount[] $socialNetworkAccounts
|
||||||
@ -134,6 +135,7 @@ class User extends ActiveRecord implements IdentityInterface
|
|||||||
'password' => Yii::t('usuario', 'Password'),
|
'password' => Yii::t('usuario', 'Password'),
|
||||||
'created_at' => Yii::t('usuario', 'Registration time'),
|
'created_at' => Yii::t('usuario', 'Registration time'),
|
||||||
'confirmed_at' => Yii::t('usuario', 'Confirmation time'),
|
'confirmed_at' => Yii::t('usuario', 'Confirmation time'),
|
||||||
|
'last_login_at' => Yii::t('usuario', 'Last login'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,10 @@ class UserSearch extends Model
|
|||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $created_at;
|
public $created_at;
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $last_login_at;
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -57,7 +61,7 @@ class UserSearch extends Model
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'safeFields' => [['username', 'email', 'registration_ip', 'created_at'], 'safe'],
|
'safeFields' => [['username', 'email', 'registration_ip', 'created_at', 'last_login_at'], 'safe'],
|
||||||
'createdDefault' => ['created_at', 'default', 'value' => null],
|
'createdDefault' => ['created_at', 'default', 'value' => null],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -72,6 +76,7 @@ class UserSearch extends Model
|
|||||||
'email' => Yii::t('usuario', 'Email'),
|
'email' => Yii::t('usuario', 'Email'),
|
||||||
'created_at' => Yii::t('usuario', 'Registration time'),
|
'created_at' => Yii::t('usuario', 'Registration time'),
|
||||||
'registration_ip' => Yii::t('usuario', 'Registration IP'),
|
'registration_ip' => Yii::t('usuario', 'Registration IP'),
|
||||||
|
'last_login_at' => Yii::t('usuario', 'Last login'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +104,11 @@ class UserSearch extends Model
|
|||||||
$query->andFilterWhere(['between', 'created_at', $date, $date + 3600 * 24]);
|
$query->andFilterWhere(['between', 'created_at', $date, $date + 3600 * 24]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->last_login_at !== null) {
|
||||||
|
$date = strtotime($this->last_login_at);
|
||||||
|
$query->andFilterWhere(['between', 'last_login_at', $date, $date + 3600 * 24]);
|
||||||
|
}
|
||||||
|
|
||||||
$query
|
$query
|
||||||
->andFilterWhere(['like', 'username', $this->username])
|
->andFilterWhere(['like', 'username', $this->username])
|
||||||
->andFilterWhere(['like', 'email', $this->email])
|
->andFilterWhere(['like', 'email', $this->email])
|
||||||
|
|||||||
@ -58,6 +58,18 @@ $module = Yii::$app->getModule('user');
|
|||||||
return date('Y-m-d G:i:s', $model->created_at);
|
return date('Y-m-d G:i:s', $model->created_at);
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'last_login_at',
|
||||||
|
'value' => function ($model) {
|
||||||
|
if (!$model->last_login_at || $model->last_login_at == 0) {
|
||||||
|
return Yii::t('usuario', 'Never');
|
||||||
|
} else if (extension_loaded('intl')) {
|
||||||
|
return Yii::t('usuario', '{0, date, MMMM dd, YYYY HH:mm}', [$model->last_login_at]);
|
||||||
|
} else {
|
||||||
|
return date('Y-m-d G:i:s', $model->last_login_at);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'header' => Yii::t('usuario', 'Confirmation'),
|
'header' => Yii::t('usuario', 'Confirmation'),
|
||||||
'value' => function ($model) {
|
'value' => function ($model) {
|
||||||
|
|||||||
Reference in New Issue
Block a user