diff --git a/doc/manual_installation/dovecot.rst b/doc/manual_installation/dovecot.rst index 9c759faf1..568ee29b7 100644 --- a/doc/manual_installation/dovecot.rst +++ b/doc/manual_installation/dovecot.rst @@ -400,3 +400,57 @@ Finally, configure the ``sieve`` plugin by editing the Restart Dovecot. Now, you can go to the :ref:`postfix` section to finish the installation. + +Last-login tracking +=================== + +To update the ``last_login`` attribute of an account after a succesful +IMAP or POP3 login, you can configure a `post-login script +`_. + +Open :file:`conf.d/10-master.conf` add the following configuration +(``imap`` and ``pop3`` services are already defined, you just need to +update them):: + + service imap { + executable = imap postlogin + } + + service pop3 { + executable = pop3 postlogin + } + + service postlogin { + executable = script-login /usr/local/bin/postlogin.sh + user = modoboa + unix_listener postlogin { + } + } + +Then, you must create a script named +:file:`/usr/local/bin/postlogin.sh`. According to your database +engine, the content will differ. + +PostgreSQL +---------- + +:: + #!/bin/sh + + psql -c "UPDATE core_user SET last_login=now() WHERE username='$USER'" > /dev/null + + exec "$@" + +MySQL +----- + +:: + #!/bin/sh + + DBNAME=XXX + DBUSER=XXX + DBPASSWORD=XXX + + echo "UPDATE core_user SET last_login=now() WHERE username='$USER'" | mysql -u $DBUSER -p$DBPASSWORD $DBNAME + + exec "$@" diff --git a/modoboa/core/tests/test_views.py b/modoboa/core/tests/test_views.py index 177ca940d..b9553ed0e 100644 --- a/modoboa/core/tests/test_views.py +++ b/modoboa/core/tests/test_views.py @@ -156,6 +156,7 @@ class SettingsTestCase(ModoTestCase): "core-default_password": "Toto1000", "limits-deflt_user_quota_limit": "0", "core-hide_features_widget": "False", + "core-inactive_account_threshold": "30", } def test_get_settings(self): @@ -169,6 +170,7 @@ class SettingsTestCase(ModoTestCase): """Test settings save.""" url = reverse("core:parameters") response = self.client.post(url, self.settings_sample, format="json") + print response.content self.assertEqual(response.status_code, 200) self.settings_sample["core-rounds_number"] = "" response = self.client.post(url, self.settings_sample, format="json")