diff --git a/example/includes/config.yml b/example/includes/config.yml index b04dc28..697ef8d 100644 --- a/example/includes/config.yml +++ b/example/includes/config.yml @@ -172,6 +172,12 @@ auth: http: "HTTP" cas: "SSO" + # Remember username + # Enable the feature (default: true) + # remember_username: true + # Cookie name (default: remember_username) + # remember_username_cookie_name: "remember_username" + # # HTTP Authentication Configuration # diff --git a/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.mo b/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.mo index ff101fe..cd49795 100644 Binary files a/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.mo and b/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.mo differ diff --git a/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.po b/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.po index ce07897..ed9a609 100644 --- a/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.po +++ b/locales/fr_FR.UTF8/LC_MESSAGES/EESYPHP.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"POT-Creation-Date: 2023-03-22 19:13+0100\n" +"POT-Creation-Date: 2023-04-22 18:48+0200\n" "PO-Revision-Date: \n" "Last-Translator: Benjamin Renard \n" "Language-Team: \n" @@ -28,11 +28,11 @@ msgstr "Inconnu" msgid "Unable to connect to the database." msgstr "Impossible de se connecter à la base de données." -#: Auth/Form.php:41 +#: Auth/Form.php:51 msgid "Invalid username or password." msgstr "Nom d'utilisateur ou mot de passe invalide." -#: Auth/Form.php:74 +#: Auth/Form.php:92 msgid "Sign in" msgstr "Connexion" @@ -581,15 +581,19 @@ msgstr "Merci de patienter pendant le traitement de votre requête." msgid "Are you sure?" msgstr "Êtes-vous sure ?" -#: templates/login.tpl:19 templates/login.tpl:20 +#: templates/login.tpl:20 templates/login.tpl:21 msgid "Username" msgstr "Nom d'utilisateur" -#: templates/login.tpl:24 templates/login.tpl:25 +#: templates/login.tpl:26 templates/login.tpl:27 msgid "Password" msgstr "Mot de passe" -#: templates/login.tpl:29 +#: templates/login.tpl:33 +msgid "Remember username" +msgstr "Mémoriser nom d'utilisateur" + +#: templates/login.tpl:38 msgid "Submit" msgstr "Envoyer" diff --git a/locales/messages.pot b/locales/messages.pot index 2608939..f2af714 100644 --- a/locales/messages.pot +++ b/locales/messages.pot @@ -1,7 +1,7 @@ msgid "" msgstr "" -"POT-Creation-Date: 2023-03-22 19:13+0100\n" -"PO-Revision-Date: 2023-03-22 19:13+0100\n" +"POT-Creation-Date: 2023-04-22 18:48+0200\n" +"PO-Revision-Date: 2023-04-22 18:48+0200\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -22,11 +22,11 @@ msgstr "" msgid "Unable to connect to the database." msgstr "" -#: Auth/Form.php:41 +#: Auth/Form.php:51 msgid "Invalid username or password." msgstr "" -#: Auth/Form.php:74 +#: Auth/Form.php:92 msgid "Sign in" msgstr "" @@ -504,15 +504,19 @@ msgstr "" msgid "Are you sure?" msgstr "" -#: templates/login.tpl:19 templates/login.tpl:20 +#: templates/login.tpl:20 templates/login.tpl:21 msgid "Username" msgstr "" -#: templates/login.tpl:24 templates/login.tpl:25 +#: templates/login.tpl:26 templates/login.tpl:27 msgid "Password" msgstr "" -#: templates/login.tpl:29 +#: templates/login.tpl:33 +msgid "Remember username" +msgstr "" + +#: templates/login.tpl:38 msgid "Submit" msgstr "" diff --git a/skel/config.yml b/skel/config.yml index 21480ef..2b4bfab 100644 --- a/skel/config.yml +++ b/skel/config.yml @@ -172,6 +172,12 @@ auth: http: "HTTP" cas: "SSO" + # Remember username + # Enable the feature (default: true) + # remember_username: true + # Cookie name (default: remember_username) + # remember_username_cookie_name: "remember_username" + # # HTTP Authentication Configuration # diff --git a/src/Auth/Form.php b/src/Auth/Form.php index 30edd43..c04efd5 100644 --- a/src/Auth/Form.php +++ b/src/Auth/Form.php @@ -22,6 +22,8 @@ class Form extends Method { array( 'display_other_methods' => array(), 'include_navbar' => true, + 'remember_username' => true, + 'remember_username_cookie_name' => 'remember_username', ) ); Url :: add_url_handler('#^login$#', array('EesyPHP\\Auth\\Form', 'handle_login'), null, false); @@ -38,7 +40,15 @@ class Form extends Method { $user = null; if (isset($_REQUEST['username']) && isset($_REQUEST['password'])) { $user = Auth :: authenticate($_REQUEST['username'], $_REQUEST['password']); - if (!$user) Tpl::add_error(_('Invalid username or password.')); + if ($user) { + setcookie( + App::get('auth.login_form.remember_username_cookie_name'), + App::get('auth.login_form.remember_username') && isset($_REQUEST['remember-username'])? + $user->username:null + ); + } + else + Tpl::add_error(_('Invalid username or password.')); } if ($force && !$user) { if (Url :: get_current_url() != 'login') @@ -67,8 +77,15 @@ class Form extends Method { } if ($user) Url :: redirect(isset($_REQUEST['next'])?urldecode($_REQUEST['next']):null); - else - Tpl :: assign('next', (isset($_REQUEST['next'])?urldecode($_REQUEST['next']):'')); + + $remember_username = App::get('auth.login_form.remember_username', null, 'bool'); + Tpl :: assign('remember_username', $remember_username); + if ($remember_username) { + $cookie_name = App::get('auth.login_form.remember_username_cookie_name'); + Tpl :: assign('username', isset($_COOKIE[$cookie_name])?$_COOKIE[$cookie_name]:null); + } + + Tpl :: assign('next', isset($_REQUEST['next'])?urldecode($_REQUEST['next']):''); Tpl :: assign('display_other_methods', $display_other_methods); Tpl :: assign('include_navbar', App::get('auth.login_form.include_navbar', null, 'bool')); Tpl :: display('login.tpl', I18n::_('Sign in')); diff --git a/templates/login.tpl b/templates/login.tpl index ce67497..91cae70 100644 --- a/templates/login.tpl +++ b/templates/login.tpl @@ -16,7 +16,7 @@
+ placeholder="{t domain=$CORE_TEXT_DOMAIN}Username{/t}" value="{if $remember_username && $username}{$username|escape:"quotes"}{/if}"/>
@@ -25,6 +25,15 @@
+ {if $remember_username} +
+ +
+ {/if} +