From: arno Date: Sun, 20 Mar 2011 13:22:45 +0000 (+0100) Subject: remember me checkbox for login X-Git-Tag: v0.3~11 X-Git-Url: https://dev.renevier.net/?p=syj.git;a=commitdiff_plain;h=482c3abbceb9818ee12c355c5d96d15077c04736 remember me checkbox for login --- diff --git a/application/controllers/LoginController.php b/application/controllers/LoginController.php index 85c7ac1..4c8aca0 100644 --- a/application/controllers/LoginController.php +++ b/application/controllers/LoginController.php @@ -32,7 +32,9 @@ class LoginController extends Zend_Controller_Action } /* form has been filled */ - if (!$this->_helper->SyjUserManager->validate($formData['login_user'], sha1($formData['login_password']))) { + if (!$this->_helper->SyjUserManager->validate($formData['login_user'], + sha1($formData['login_password']), + $formData['login_rememberme'])) { if ($httprequest) { throw new Syj_Exception_Forbidden(); } else { diff --git a/application/controllers/helpers/SyjUserManager.php b/application/controllers/helpers/SyjUserManager.php index 427e6fa..d1f8a60 100644 --- a/application/controllers/helpers/SyjUserManager.php +++ b/application/controllers/helpers/SyjUserManager.php @@ -7,7 +7,7 @@ class Syj_Controller_Action_Helper_SyjUserManager extends Zend_Controller_Action // -1 for undeterminated, null for non logged, Syj_Model_User for a logged user protected static $_current = -1; - static public function validate($username, $hash) { + static public function validate($username, $hash, $rememberme = false) { // TODO: try to make only one sql request $adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($adapter, 'users', 'pseudo', 'password'); @@ -26,8 +26,14 @@ class Syj_Controller_Action_Helper_SyjUserManager extends Zend_Controller_Action } if (!isset ($_COOKIE['syj_user']) or (!isset ($_COOKIE['syj_hashpass']))) { - setcookie("syj_user", $username, 0, "", "", false, true); - setcookie("syj_hashpass", $hash, 0, "", "", false, true); + if ($rememberme) { + // cookie will be valid for 2 weeks + $time = time () + 14 * 60 * 24 * 60; + } else { + $time = 0; + } + setcookie("syj_user", $username, $time, "", "", false, true); + setcookie("syj_hashpass", $hash, $time, "", "", false, true); } self::$_current = $user; return true; diff --git a/application/forms/Login.php b/application/forms/Login.php index a13692a..33fdfe7 100644 --- a/application/forms/Login.php +++ b/application/forms/Login.php @@ -9,8 +9,8 @@ class Syj_Form_Login extends Syj_Form_TableAbstract $user = array('Text', 'login_user', array( 'label' => __("user"), 'required' => true)); $pass = array('Password', 'login_password', array( 'label' => __("password"))); - $this->setMainElements(array($user, $pass)) + ->addElement('Checkbox', 'login_rememberme', array( 'label' => __("remember me"), 'checked' => true)) ->addElement('Hidden', 'login_geom_id', array( 'decorators' => array('ViewHelper'))); $currentUri = $this->getView()->UriPath(true); diff --git a/application/languages/lang_en.po b/application/languages/lang_en.po index 79510df..a56b045 100644 --- a/application/languages/lang_en.po +++ b/application/languages/lang_en.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: syj\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-03-18 17:25+0100\n" +"POT-Creation-Date: 2011-03-20 14:22+0100\n" "PO-Revision-Date: \n" "Last-Translator: arno \n" "Language-Team: arno \n" @@ -436,7 +436,7 @@ msgstr "" "\n" "Syj team" -#: application/controllers/LoginController.php:99 +#: application/controllers/LoginController.php:91 #: application/controllers/IdxController.php:160 msgid "you must enter a login name" msgstr "you must enter a login name" @@ -689,6 +689,10 @@ msgstr "user" msgid "password" msgstr "password" +#: application/forms/Login.php:13 +msgid "remember me" +msgstr "remember me" + #: application/forms/Login.php:20 msgid "I forgot my password" msgstr "I forgot my password" @@ -801,3 +805,4 @@ msgstr "Someone, probably you, has registered an account %s with email address % #: application/forms/Pending/ValidateCreation.php:24 msgid "To cancel account creation, press following button. The account and all its data will be deleted." msgstr "To cancel account creation, press following button. The account and all its data will be deleted." + diff --git a/application/languages/lang_fr.po b/application/languages/lang_fr.po index aa161a9..2669127 100644 --- a/application/languages/lang_fr.po +++ b/application/languages/lang_fr.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: syj\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-03-18 17:25+0100\n" +"POT-Creation-Date: 2011-03-20 14:22+0100\n" "PO-Revision-Date: \n" "Last-Translator: arno \n" "Language-Team: arno \n" @@ -438,7 +438,7 @@ msgstr "" "\n" "L'équipe de Syj" -#: application/controllers/LoginController.php:99 +#: application/controllers/LoginController.php:91 #: application/controllers/IdxController.php:160 msgid "you must enter a login name" msgstr "vous devez entrer un nom d'utilisateur" @@ -691,6 +691,10 @@ msgstr "utilisateur" msgid "password" msgstr "mot de passe" +#: application/forms/Login.php:13 +msgid "remember me" +msgstr "se souvenir de moi" + #: application/forms/Login.php:20 msgid "I forgot my password" msgstr "J'ai oublié mon mot de passe" @@ -803,3 +807,4 @@ msgstr "Quelqu'un, probablement vous, a enregistré un compte %s avec l'adresse #: application/forms/Pending/ValidateCreation.php:24 msgid "To cancel account creation, press following button. The account and all its data will be deleted." msgstr "Pour annuler la création du compte, pressez le bouton suivant. Le compte ainsi que toutes ses données seront supprimés." + diff --git a/application/languages/lang_ja.po b/application/languages/lang_ja.po index 1c270c3..b7f63d4 100644 --- a/application/languages/lang_ja.po +++ b/application/languages/lang_ja.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: syj\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-03-18 17:25+0100\n" +"POT-Creation-Date: 2011-03-20 14:22+0100\n" "PO-Revision-Date: \n" "Last-Translator: S.Higashi \n" "Language: \n" @@ -531,7 +531,7 @@ msgstr "" "\n" "Syj チーム" -#: application/controllers/LoginController.php:99 +#: application/controllers/LoginController.php:91 #: application/controllers/IdxController.php:160 msgid "you must enter a login name" msgstr "ログイン名を入力してください" @@ -785,6 +785,10 @@ msgstr "ユーザ" msgid "password" msgstr "パスワード" +#: application/forms/Login.php:13 +msgid "remember me" +msgstr "" + #: application/forms/Login.php:20 msgid "I forgot my password" msgstr "パスワードを忘れた"