diff --git a/data/templates/login.tpl.php b/data/templates/login.tpl.php index e67808d..d389a08 100644 --- a/data/templates/login.tpl.php +++ b/data/templates/login.tpl.php @@ -14,23 +14,24 @@ if (!$userservice->isSessionStable()) { } ?> -
-
- +> + +
- - - + + + - - - + + + - - - + + +

»

diff --git a/www/login.php b/www/login.php index 2a61224..1b4d4cf 100644 --- a/www/login.php +++ b/www/login.php @@ -1,62 +1,139 @@ + * @author Christian Weiske + * @author Eric Dane + * @copyright 2004-2006 Marcus Campbell + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ require_once 'www-header.php'; - -/* Service creation: only useful services are created */ -// No specific services - - -/* Managing all possible inputs */ -isset($_POST['keeppass']) ? define('POST_KEEPPASS', $_POST['keeppass']): define('POST_KEEPPASS', ''); -isset($_POST['submitted']) ? define('POST_SUBMITTED', $_POST['submitted']): define('POST_SUBMITTED', ''); -isset($_POST['username']) ? define('POST_USERNAME', $_POST['username']): define('POST_USERNAME', ''); -isset($_POST['password']) ? define('POST_PASSWORD', $_POST['password']): define('POST_PASSWORD', ''); -isset($_POST['query']) ? define('POST_QUERY', $_POST['query']): define('POST_QUERY', ''); - -$keeppass = (POST_KEEPPASS=='yes')?true:false; - -$login = false; -if (POST_SUBMITTED!='' && POST_USERNAME!='' && POST_PASSWORD!='') { - $posteduser = trim(utf8_strtolower(POST_USERNAME)); - $login = $userservice->login($posteduser, POST_PASSWORD, $keeppass); - if ($login) { - if (POST_QUERY) - header('Location: '. createURL('bookmarks', $posteduser .'?'. POST_QUERY)); - else - header('Location: '. createURL('bookmarks', $posteduser)); - } else { - $tplVars['error'] = T_('The details you have entered are incorrect. Please try again.'); - } +if ($userservice->isLoggedOn()) { + //no need to log in when the user is already logged in + $user = $userservice->getCurrentUser(); + header( + 'Location: ' + . createURL('bookmarks', $user['username']) + ); + exit(); } -if (!$login) { - if ($userservice->isLoggedOn()) { - $cUser = $userservice->getCurrentObjectUser(); - header('Location: '. createURL('bookmarks', strtolower($cUser->getUsername()))); - } - $tplVars['subtitle'] = T_('Log In'); - $tplVars['formaction'] = createURL('login'); - $tplVars['querystring'] = filter($_SERVER['QUERY_STRING']); - $templateservice->loadTemplate('login.tpl', $tplVars); +require_once 'HTML/QuickForm2.php'; +require_once 'SemanticScuttle/QuickForm2/Renderer/CoolArray.php'; + +//do not append '-0' to IDs +HTML_Common2::setOption('id_force_append_index', false); + +$login = new HTML_QuickForm2( + 'login', 'post', + array('action' => createURL('login')), + true +); +$login->addElement( + 'hidden', 'querystring', + array( + 'value' => $_SERVER['QUERY_STRING'] + ) +); + +$user = $login->addElement( + 'text', 'username', + array( + 'size' => 20, + 'class' => 'required' + ) +)->setLabel(T_('Username')); +$user->addRule( + 'required', + T_('You must enter your username and password') +); +$user->addRule( + 'callback', + T_('This username is not valid (too short, too long, forbidden characters...), please make another choice.'), + array($userservice, 'isValidUsername') +); + +$login->addElement( + 'password', 'password', + array( + 'size' => 20, + 'class' => 'required' + ) +) +->setLabel(T_('Password')) +->addRule( + 'required', + T_('You must enter your username and password') +); + +$login->addElement( + 'checkbox', 'keeploggedin' +)->setLabel(T_('Don\'t ask for my password for 2 weeks')); + +$login->addElement( + 'submit', 'submit', + array('value' => T_('Log In')) +); + + +$tplVars['error'] = ''; +if ($login->validate()) { + $arValues = $login->getValue(); + if (!isset($arValues['keeploggedin'])) { + $arValues['keeploggedin'] = false; + } + $bLoginOk = $userservice->login( + $arValues['username'], + $arValues['password'], + (bool)$arValues['keeploggedin'] + ); + if ($bLoginOk) { + if ($arValues['querystring'] != '') { + //append old query string + header( + 'Location: ' + . createURL('bookmarks', $arValues['username']) + . '?' . $arValues['querystring'] + ); + } else { + header( + 'Location: ' + . createURL('bookmarks', $arValues['username']) + ); + } + exit(); + } + $tplVars['error'] = T_('The details you have entered are incorrect. Please try again.'); } + + +HTML_QuickForm2_Renderer::register( + 'coolarray', + 'SemanticScuttle_QuickForm2_Renderer_CoolArray' +); +//$renderer = HTML_QuickForm2_Renderer::factory('coolarray') +$renderer = new SemanticScuttle_QuickForm2_Renderer_CoolArray(); +$renderer->setOption( + array( + 'group_hiddens' => true, + 'group_errors' => true + ) +); + +$tplVars['form'] = $login->render($renderer); +$tplVars['loadjs'] = true; +$tplVars['subtitle'] = T_('Register'); +$tplVars['error'] .= implode( + '
', array_unique($tplVars['form']['errors']) +); +$templateservice->loadTemplate('login.tpl', $tplVars); + ?>