diff --git a/CHANGELOG.md b/CHANGELOG.md index 5379244..5176f7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CHANGELOG ## work in progress + - Fix #378: Add module attribute 'disableIpLogging' (jkmssoft) ## 1.5.1 April 5, 2020 - Fix #370: Extending view fix (effsoft) diff --git a/docs/installation/configuration-options.md b/docs/installation/configuration-options.md index e166aac..47016ed 100644 --- a/docs/installation/configuration-options.md +++ b/docs/installation/configuration-options.md @@ -216,6 +216,9 @@ Configures the name of the session key that will be used to hold the original ad If `false`, allow the assignment of both roles and permissions to users. Set to `true` to restrict user assignments to roles only. +#### disableIpLogging (type: `boolean`, default: `false`) + +If `true` registration and last login IPs are not logged into users table, instead a dummy 127.0.0.1 is used © [2amigos](http://www.2amigos.us/) 2013-2019 diff --git a/src/User/Controller/SecurityController.php b/src/User/Controller/SecurityController.php index c7c6480..f1af821 100644 --- a/src/User/Controller/SecurityController.php +++ b/src/User/Controller/SecurityController.php @@ -141,7 +141,7 @@ class SecurityController extends Controller if ($form->login()) { $form->getUser()->updateAttributes([ 'last_login_at' => time(), - 'last_login_ip' => Yii::$app->request->getUserIP(), + 'last_login_ip' => $this->module->disableIpLogging ? '127.0.0.1' : Yii::$app->request->getUserIP(), ]); $this->trigger(FormEvent::EVENT_AFTER_LOGIN, $event); diff --git a/src/User/Model/User.php b/src/User/Model/User.php index 212ff73..3671c93 100644 --- a/src/User/Model/User.php +++ b/src/User/Model/User.php @@ -125,7 +125,7 @@ class User extends ActiveRecord implements IdentityInterface if ($insert) { $this->setAttribute('auth_key', $security->generateRandomString()); if (Yii::$app instanceof Application) { - $this->setAttribute('registration_ip', Yii::$app->request->getUserIP()); + $this->setAttribute('registration_ip', $this->module->disableIpLogging ? '127.0.0.1' : Yii::$app->request->getUserIP()); } } diff --git a/src/User/Module.php b/src/User/Module.php index 0f10f49..26b8b17 100644 --- a/src/User/Module.php +++ b/src/User/Module.php @@ -206,6 +206,10 @@ class Module extends BaseModule * @var boolean whether to restrict assignment of permissions to users */ public $restrictUserPermissionAssignment = false; + /** + * @var boolean whether to disable IP logging into user table + */ + public $disableIpLogging = false; /** * @return string with the hit to be used with the give consent checkbox diff --git a/src/User/resources/views/admin/index.php b/src/User/resources/views/admin/index.php index ed87cd9..552b460 100644 --- a/src/User/resources/views/admin/index.php +++ b/src/User/resources/views/admin/index.php @@ -47,6 +47,7 @@ $module = Yii::$app->getModule('user'); : $model->registration_ip; }, 'format' => 'html', + 'visible' => !$module->disableIpLogging, ], [ 'attribute' => 'created_at', @@ -78,6 +79,7 @@ $module = Yii::$app->getModule('user'); : $model->last_login_ip; }, 'format' => 'html', + 'visible' => !$module->disableIpLogging, ], [ 'header' => Yii::t('usuario', 'Confirmation'),