Skip to content

Commit

Permalink
Merge pull request #4863 from jdarwood007/cookieTime
Browse files Browse the repository at this point in the history
Fix login times not being kept on failed logins
  • Loading branch information
jdarwood007 committed Jul 22, 2018
2 parents 784b500 + 734a9d0 commit 6ed0bb9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
22 changes: 20 additions & 2 deletions Sources/LogInOut.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ function Login()

// Create a one time token.
createToken('login');

// Login Cookie times. Format: time => txt
$context['login_cookie_times'] = array(
60 => 'one_hour',
1440 => 'one_day',
10080 => 'one_week',
43200 => 'one_month',
3153600 => 'always_logged_in',
);
}

/**
Expand Down Expand Up @@ -181,9 +190,18 @@ function Login2()
// Set up the cookie length. (if it's invalid, just fall through and use the default.)
if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
$modSettings['cookieTime'] = 3153600;
elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600))
$modSettings['cookieTime'] = (int) $_POST['cookielength'];

// Login Cookie times. Format: time => txt
$context['login_cookie_times'] = array(
60 => 'one_hour',
1440 => 'one_day',
10080 => 'one_week',
43200 => 'one_month',
3153600 => 'always_logged_in',
);

loadLanguage('Login');
// Load the template stuff.
loadTemplate('Login');
Expand All @@ -192,7 +210,7 @@ function Login2()
// Set up the default/fallback stuff.
$context['default_username'] = isset($_POST['user']) ? preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($_POST['user'])) : '';
$context['default_password'] = '';
$context['never_expire'] = $modSettings['cookieTime'] == 525600 || $modSettings['cookieTime'] == 3153600;
$context['never_expire'] = $modSettings['cookieTime'] <= 525600;
$context['login_errors'] = array($txt['error_occured']);
$context['page_title'] = $txt['login'];

Expand Down
43 changes: 23 additions & 20 deletions Themes/default/Login.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ function template_login()
<dl>
<dt>', $txt['time_logged_in'], ':</dt>
<dd>
<select name="cookielength" id="cookielength">
<option value="60"', $context['never_expire'] ? '' : ' selected', '>', $txt['one_hour'], '</option>
<option value="1440">', $txt['one_day'], '</option>
<option value="10080">', $txt['one_week'], '</option>
<option value="43200">', $txt['one_month'], '</option>
<option value="3153600"', $context['never_expire'] ? ' selected' : '', '>', $txt['always_logged_in'], '</option>
<select name="cookielength" id="cookielength">';

foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt)
echo '
<option value="', $cookie_time, '"', $modSettings['cookieTime'] == $cookie_time ? ' selected' : '', '>', $txt[$cookie_txt], '</option>';

echo '
</select>
</dd>';

Expand Down Expand Up @@ -253,13 +254,14 @@ function template_kick_guest()
<dd><input type="password" name="passwrd" size="20"></dd>
<dt>', $txt['time_logged_in'], ':</dt>
<dd>
<select name="cookielength" id="cookielength">
<option value="60" selected>', $txt['one_hour'], '</option>
<option value="1440">', $txt['one_day'], '</option>
<option value="10080">', $txt['one_week'], '</option>
<option value="43200">', $txt['one_month'], '</option>
<option value="3153600">', $txt['always_logged_in'], '</option>
</select>
<select name="cookielength" id="cookielength">';

foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt)
echo '
<option value="', $cookie_time, '"', $modSettings['cookieTime'] == $cookie_time ? ' selected' : '', '>', $txt[$cookie_txt], '</option>';

echo '
</select>
</dd>
</dl>
<p class="centertext">
Expand Down Expand Up @@ -311,13 +313,14 @@ function template_maintenance()
<dd><input type="password" name="passwrd" size="20"></dd>
<dt>', $txt['time_logged_in'], ':</dt>
<dd>
<select name="cookielength" id="cookielength">
<option value="60" selected>', $txt['one_hour'], '</option>
<option value="1440">', $txt['one_day'], '</option>
<option value="10080">', $txt['one_week'], '</option>
<option value="43200">', $txt['one_month'], '</option>
<option value="3153600">', $txt['always_logged_in'], '</option>
</select>
<select name="cookielength" id="cookielength">';

foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt)
echo '
<option value="', $cookie_time, '"', $modSettings['cookieTime'] == $cookie_time ? ' selected' : '', '>', $txt[$cookie_txt], '</option>';

echo '
</select>
</dd>
</dl>
<input type="submit" value="', $txt['login'], '" class="button">
Expand Down

0 comments on commit 6ed0bb9

Please sign in to comment.