Merge pull request #556 from ArthurHoaro/login-refill

Prefill the login field when the authentication has failed
This commit is contained in:
Arthur 2016-05-14 11:09:39 +02:00
commit 52ccf0d7ee
2 changed files with 33 additions and 20 deletions

View file

@ -495,9 +495,9 @@ function ban_canLogin()
else else
{ {
ban_loginFailed(); ban_loginFailed();
$redir = ''; $redir = '&username='. $_POST['login'];
if (isset($_GET['post'])) { if (isset($_GET['post'])) {
$redir = '?post=' . urlencode($_GET['post']); $redir .= '&post=' . urlencode($_GET['post']);
foreach (array('description', 'source', 'title') as $param) { foreach (array('description', 'source', 'title') as $param) {
if (!empty($_GET[$param])) { if (!empty($_GET[$param])) {
$redir .= '&' . $param . '=' . urlencode($_GET[$param]); $redir .= '&' . $param . '=' . urlencode($_GET[$param]);
@ -943,6 +943,9 @@ function renderPage()
if ($GLOBALS['config']['OPEN_SHAARLI']) { header('Location: ?'); exit; } // No need to login for open Shaarli if ($GLOBALS['config']['OPEN_SHAARLI']) { header('Location: ?'); exit; } // No need to login for open Shaarli
$token=''; if (ban_canLogin()) $token=getToken(); // Do not waste token generation if not useful. $token=''; if (ban_canLogin()) $token=getToken(); // Do not waste token generation if not useful.
$PAGE->assign('token',$token); $PAGE->assign('token',$token);
if (isset($_GET['username'])) {
$PAGE->assign('username', escape($_GET['username']));
}
$PAGE->assign('returnurl',(isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):'')); $PAGE->assign('returnurl',(isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):''));
$PAGE->renderPage('loginform'); $PAGE->renderPage('loginform');
exit; exit;

View file

@ -1,26 +1,36 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head>{include="includes"}</head> <head>{include="includes"}</head>
<body{if="ban_canLogin()"} onload="document.loginform.login.focus();"{/if}> <body
{if="ban_canLogin()"}
{if="empty($username)"}
onload="document.loginform.login.focus();"
{else}
onload="document.loginform.password.focus();"
{/if}
{/if}>
<div id="pageheader"> <div id="pageheader">
{include="page.header"} {include="page.header"}
<div id="headerform"> <div id="headerform">
{if="!ban_canLogin()"} {if="!ban_canLogin()"}
You have been banned from login after too many failed attempts. Try later. You have been banned from login after too many failed attempts. Try later.
{else} {else}
<form method="post" name="loginform"> <form method="post" name="loginform">
<label for="login">Login: <input type="text" id="login" name="login" tabindex="1"></label> <label for="login">Login: <input type="text" id="login" name="login" tabindex="1"
<label for="password">Password: <input type="password" id="password" name="password" tabindex="2"></label> {if="!empty($username)"}value="{$username}"{/if}>
<input type="submit" value="Login" class="bigbutton" tabindex="4"> </label>
<label for="longlastingsession"> <label for="password">Password: <input type="password" id="password" name="password" tabindex="2">
<input type="checkbox" name="longlastingsession" id="longlastingsession" tabindex="3"> </label>
Stay signed in (Do not check on public computers)</label> <input type="submit" value="Login" class="bigbutton" tabindex="4">
<input type="hidden" name="token" value="{$token}"> <label for="longlastingsession">
{if="$returnurl"}<input type="hidden" name="returnurl" value="{$returnurl}">{/if} <input type="checkbox" name="longlastingsession" id="longlastingsession" tabindex="3">
</form> Stay signed in (Do not check on public computers)</label>
{/if} <input type="hidden" name="token" value="{$token}">
</div> {if="$returnurl"}<input type="hidden" name="returnurl" value="{$returnurl}">{/if}
</form>
{/if}
</div>
</div> </div>
{include="page.footer"} {include="page.footer"}