make login form use quickform
This commit is contained in:
parent
1ba18be35d
commit
3c280ae9ab
@ -14,22 +14,23 @@ if (!$userservice->isSessionStable()) {
|
||||
}
|
||||
?>
|
||||
|
||||
<form action="<?php echo $formaction; ?>" method="post">
|
||||
<div><input type="hidden" name="query" value="<?php echo $querystring; ?>" /></div>
|
||||
<form<?php echo $form['attributes']; ?>>
|
||||
<?php echo implode('', $form['hidden']); ?>
|
||||
<table>
|
||||
<tr>
|
||||
<th align="left"><label for="username"><?php echo T_('Username'); ?></label></th>
|
||||
<td><input type="text" id="username" name="username" size="20" /></td>
|
||||
<th align="left"><?php echo $form['username']['labelhtml']; ?></th>
|
||||
<td><?php echo $form['username']['html']; ?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="left"><label for="password"><?php echo T_('Password'); ?></label></th>
|
||||
<td><input type="password" id="password" name="password" size="20" /></td>
|
||||
<td><input type="checkbox" name="keeppass" id="keeppass" value="yes" /> <label for="keeppass"><?php echo T_("Don't ask for my password for 2 weeks"); ?>.</label></td>
|
||||
<th align="left"><?php echo $form['password']['labelhtml']; ?></th>
|
||||
<td><?php echo $form['password']['html']; ?></td>
|
||||
<td><?php echo $form['keeploggedin']['html']
|
||||
. $form['keeploggedin']['labelhtml']; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><input type="submit" name="submitted" value="<?php echo T_('Log In'); ?>" /></td>
|
||||
<td><?php echo $form['submit']['html']; ?></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
179
www/login.php
179
www/login.php
@ -1,62 +1,139 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
Copyright (C) 2004 - 2006 Scuttle project
|
||||
http://sourceforge.net/projects/scuttle/
|
||||
http://scuttle.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* SemanticScuttle - your social bookmark manager.
|
||||
* User login form.
|
||||
*
|
||||
* PHP version 5.
|
||||
*
|
||||
* @category Bookmarking
|
||||
* @package SemanticScuttle
|
||||
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
|
||||
* @author Christian Weiske <cweiske@cweiske.de>
|
||||
* @author Eric Dane <ericdane@users.sourceforge.net>
|
||||
* @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';
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
/* Service creation: only useful services are created */
|
||||
// No specific services
|
||||
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 <em>must</em> 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 <em>must</em> 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'))
|
||||
);
|
||||
|
||||
|
||||
/* 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));
|
||||
$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.');
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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(
|
||||
'<br/>', array_unique($tplVars['form']['errors'])
|
||||
);
|
||||
$templateservice->loadTemplate('login.tpl', $tplVars);
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user