News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

"Always stay logged in" as default

Started by Dylert, October 19, 2019, 04:53:37 PM

Previous topic - Next topic

Dylert

Hello! Is it possible to make "Always stay logged in" as the default choice when logging in?  :)

Arantor

Not without a code change (which for RCs is not recommended since it needs to be redone in future versions as there's no patch upgrade)

shawnb61

This has been requested quite a bit & a fix is on its way.  Not targeting RC3, but it's coming.
https://github.com/SimpleMachines/SMF2.1/pull/5802
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Dylert


Sir Osis of Liver

In 2.0 I've always removed the select menu and set cookielength to -1, that makes all logins forever -



<input type="hidden" name="cookielength" value="-1" />



Haven't tried it, but you should be able to do same thing in 2.1 in Login.template.php, and remove the input field.  I've never understood the purpose of giving members choice of cookielength.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Dylert

I don't know if this works. I can't find the exact same line in my login.template.php file.

<?php
/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines http://www.simplemachines.org
 * @copyright 2019 Simple Machines and individual contributors
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.1 RC2
 */

/**
 * This is just the basic "login" form.
 */
function template_login()
{
global $context$settings$scripturl$modSettings$txt;

echo '
<div class="login">
<div class="cat_bar">
<h3 class="catbg">
<img src="'
$settings['images_url'], '/icons/login_hd.png" alt="" class="icon"> '$txt['login'], '
</h3>
</div>
<div class="roundframe">
<form class="login" action="'
$context['login_url'], '" name="frmLogin" id="frmLogin" method="post" accept-charset="'$context['character_set'], '">';

// Did they make a mistake last time?
if (!empty($context['login_errors']))
echo '
<div class="errorbox">'
implode('<br>'$context['login_errors']), '</div>
<br>'
;

// Or perhaps there's some special description for this time?
if (isset($context['description']))
echo '
<div class="information">'
$context['description'], '</div>';

// Now just get the basic information - username, password, etc.
echo '
<dl>
<dt>'
$txt['username'], ':</dt>
<dd>
<input type="text" id="'
, !empty($context['from_ajax']) ? 'ajax_' '''loginuser" name="user" size="20" value="'$context['default_username'], '">
</dd>
<dt>'
$txt['password'], ':</dt>
<dd>
<input type="password" id="'
, !empty($context['from_ajax']) ? 'ajax_' '''loginpass" name="passwrd" value="'$context['default_password'], '" size="20">
</dd>
</dl>
<dl>
<dt>'
$txt['time_logged_in'], ':</dt>
<dd>
<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>'
;

// If they have deleted their account, give them a chance to change their mind.
if (isset($context['login_show_undelete']))
echo '
<dt class="alert">'
$txt['undelete_account'], ':</dt>
<dd><input type="checkbox" name="undelete"></dd>'
;

echo '
</dl>
<p>
<input type="submit" value="'
$txt['login'], '" class="button">
</p>
<p class="smalltext">
<a href="'
$scripturl'?action=reminder">'$txt['forgot_your_password'], '</a>
</p>
<input type="hidden" name="hash_passwrd" value="">'
;

// OneAll Social Login (https://docs.oneall.com/plugins/)
template_oneall_social_login();

echo '
<input type="hidden" name="'
$context['session_var'], '" value="'$context['session_id'], '">
<input type="hidden" name="'
$context['login_token_var'], '" value="'$context['login_token'], '">
<script>
setTimeout(function() {
document.getElementById("'
, !empty($context['from_ajax']) ? 'ajax_' '', isset($context['default_username']) && $context['default_username'] != '' 'loginpass' 'loginuser''").focus();
}, 150);'
;

if (!empty($context['from_ajax']))
echo '
form = $("#frmLogin");
form.submit(function(e) {
e.preventDefault();
e.stopPropagation();

$.ajax({
url: form.prop("action"),
method: "POST",
data: form.serialize(),
success: function(data) {
if (data.indexOf("<bo" + "dy") > -1) {
document.open();
document.write(data);
document.close();
}
else
form.parent().html($(data).find(".roundframe").html());
},
error: function(xhr) {
var data = xhr.responseText;
if (data.indexOf("<bo" + "dy") > -1) {
document.open();
document.write(data);
document.close();
}
else
form.parent().html($(data).filter("#fatal_error").html());
}
});

return false;
});'
;

echo '
</script>
</form>'
;

// It is a long story as to why we have this when we're clearly not going to use it.
if (!empty($context['from_ajax']))
echo '
<br>
<a href="javascript:self.close();"></a>'
;

echo '
</div><!-- .roundframe -->
</div><!-- .login -->'
;
}

/**
 * TFA authentication form
 */
function template_login_tfa()
{
global $context$scripturl$txt;

echo '
<div class="login">
<div class="cat_bar">
<h3 class="catbg">
'
$txt['tfa_profile_label'], '
</h3>
</div>
<div class="roundframe">'
;

if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error']))
echo '
<div class="error">
'
$txt['tfa_' . (!empty($context['tfa_error']) ? 'code_' 'backup_') . 'invalid'], '
</div>'
;

echo '
<form action="'
$context['tfa_url'], '" method="post" id="frmTfa">
<div id="tfaCode">
<p style="margin-bottom: 0.5em">'
$txt['tfa_login_desc'], '</p>
<div class="centertext">
<strong>'
$txt['tfa_code'], ':</strong>
<input type="text" name="tfa_code" value="'
, !empty($context['tfa_value']) ? $context['tfa_value'] : '''">
<input type="submit" class="button" name="submit" value="'
$txt['login'], '">
</div>
<hr>
<div class="centertext">
<input type="button" class="button" name="backup" value="'
$txt['tfa_backup'], '">
</div>
</div>
<div id="tfaBackup" style="display: none;">
<p style="margin-bottom: 0.5em">'
$txt['tfa_backup_desc'], '</p>
<div class="centertext">
<strong>'
$txt['tfa_backup_code'], ': </strong>
<input type="text" name="tfa_backup" value="'
, !empty($context['tfa_backup']) ? $context['tfa_backup'] : '''">
<input type="submit" class="button" name="submit" value="'
$txt['login'], '">
</div>
</div>
</form>
<script>
form = $("#frmTfa");'
;

if (!empty($context['from_ajax']))
echo '
form.submit(function(e) {
// If we are submitting backup code, let normal workflow follow since it redirects a couple times into a different page
if (form.find("input[name=tfa_backup]:first").val().length > 0)
return true;

e.preventDefault();
e.stopPropagation();

$.post(form.prop("action"), form.serialize(), function(data) {
if (data.indexOf("<bo" + "dy") > -1)
document.location = '
JavaScriptEscape(!empty($_SESSION['login_url']) ? $_SESSION['login_url'] : $scripturl), ';
else {
form.parent().html($(data).find(".roundframe").html());
}
});

return false;
});'
;

echo '
form.find("input[name=backup]").click(function(e) {
$("#tfaBackup").show();
$("#tfaCode").hide();
});
</script>
</div><!-- .roundframe -->
</div><!-- .login -->'
;
}

/**
 * Tell a guest to get lost or login!
 */
function template_kick_guest()
{
global $context$settings$scripturl$modSettings$txt;

// This isn't that much... just like normal login but with a message at the top.
echo '
<form action="'
$context['login_url'], '" method="post" accept-charset="'$context['character_set'], '" name="frmLogin" id="frmLogin">
<div class="login">
<div class="cat_bar">
<h3 class="catbg">'
$txt['warning'], '</h3>
</div>'
;

// Show the message or default message.
echo '
<p class="information centertext">
'
, empty($context['kick_message']) ? $txt['only_members_can_access'] : $context['kick_message'], '<br>';

if ($context['can_register'])
echo sprintf($txt['login_below_or_register'], $scripturl '?action=signup'$context['forum_name_html_safe']);
else
echo $txt['login_below'];

// And now the login information.
echo '
<div class="cat_bar">
<h3 class="catbg">
<img src="'
$settings['images_url'], '/icons/login_hd.png" alt="" class="icon"> '$txt['login'], '
</h3>
</div>
<div class="roundframe">
<dl>
<dt>'
$txt['username'], ':</dt>
<dd><input type="text" name="user" size="20"></dd>
<dt>'
$txt['password'], ':</dt>
<dd><input type="password" name="passwrd" size="20"></dd>
<dt>'
$txt['time_logged_in'], ':</dt>
<dd>
<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">
<input type="submit" value="'
$txt['login'], '" class="button">
</p>
<p class="centertext smalltext">
<a href="'
$scripturl'?action=reminder">'$txt['forgot_your_password'], '</a>
</p>
</div>'
;

// OneAll Social Login (https://docs.oneall.com/plugins/)
template_oneall_social_login();

echo '
<input type="hidden" name="'
$context['session_var'], '" value="'$context['session_id'], '">
<input type="hidden" name="'
$context['login_token_var'], '" value="'$context['login_token'], '">
<input type="hidden" name="hash_passwrd" value="">
</div><!-- .login -->
</form>'
;

// Do the focus thing...
echo '
<script>
document.forms.frmLogin.user.focus();
</script>'
;
}

/**
 * This is for maintenance mode.
 */
function template_maintenance()
{
global $context$settings$txt$modSettings;

// Display the administrator's message at the top.
echo '
<form action="'
$context['login_url'], '" method="post" accept-charset="'$context['character_set'], '">
<div class="login" id="maintenance_mode">
<div class="cat_bar">
<h3 class="catbg">'
$context['title'], '</h3>
</div>
<div class="information">
<img class="floatleft" src="'
$settings['images_url'], '/construction.png" width="40" height="40" alt="'$txt['in_maintain_mode'], '">
'
$context['description'], '<br class="clear">
</div>
<div class="title_bar">
<h4 class="titlebg">'
$txt['admin_login'], '</h4>
</div>
<div class="roundframe">
<dl>
<dt>'
$txt['username'], ':</dt>
<dd><input type="text" name="user" size="20"></dd>
<dt>'
$txt['password'], ':</dt>
<dd><input type="password" name="passwrd" size="20"></dd>
<dt>'
$txt['time_logged_in'], ':</dt>
<dd>
<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">
<br class="clear">
</div>
<input type="hidden" name="hash_passwrd" value="">
<input type="hidden" name="'
$context['session_var'], '" value="'$context['session_id'], '">
<input type="hidden" name="'
$context['login_token_var'], '" value="'$context['login_token'], '">
</div><!-- #maintenance_mode -->
</form>'
;
}

/**
 * This is for the security stuff - makes administrators login every so often.
 */
function template_admin_login()
{
global $context$settings$scripturl$txt$modSettings;

// Since this should redirect to whatever they were doing, send all the get data.
echo '
<form action="'
, !empty($modSettings['force_ssl']) ? strtr($scripturl, array('http://' => 'https://')) : $scripturl$context['get_data'], '" method="post" accept-charset="'$context['character_set'], '" name="frmLogin" id="frmLogin">
<div class="login" id="admin_login">
<div class="cat_bar">
<h3 class="catbg">
<img src="'
$settings['images_url'], '/icons/login_hd.png" alt="" class="icon"> '$txt['login'], '
</h3>
</div>
<div class="roundframe centertext">'
;

if (!empty($context['incorrect_password']))
echo '
<div class="error">'
$txt['admin_incorrect_password'], '</div>';

echo '
<strong>'
$txt['password'], ':</strong>
<input type="password" name="'
$context['sessionCheckType'], '_pass" size="24">
<a href="'
$scripturl'?action=helpadmin;help=securityDisable_why" onclick="return reqOverlayDiv(this.href);" class="help"><span class="main_icons help" title="'$txt['help'], '"></span></a><br>
<input type="hidden" name="'
$context['session_var'], '" value="'$context['session_id'], '">
<input type="hidden" name="'
$context['admin-login_token_var'], '" value="'$context['admin-login_token'], '">
<input type="submit" value="'
$txt['login'], '" class="button">';

// Make sure to output all the old post data.
echo $context['post_data'], '
</div><!-- .roundframe -->
</div><!-- #admin_login -->
<input type="hidden" name="'
$context['sessionCheckType'], '_hash_pass" value="">
</form>'
;

// Focus on the password box.
echo '
<script>
document.forms.frmLogin.'
$context['sessionCheckType'], '_pass.focus();
</script>'
;
}

/**
 * Activate your account manually?
 */
function template_retry_activate()
{
global $context$txt$scripturl;

// Just ask them for their code so they can try it again...
echo '
<form action="'
$scripturl'?action=activate;u='$context['member_id'], '" method="post" accept-charset="'$context['character_set'], '">
<div class="title_bar">
<h3 class="titlebg">'
$context['page_title'], '</h3>
</div>
<div class="roundframe">
<dl>'
;

// You didn't even have an ID?
if (empty($context['member_id']))
echo '
<dt>'
$txt['invalid_activation_username'], ':</dt>
<dd><input type="text" name="user" size="30"></dd>'
;

echo '
<dt>'
$txt['invalid_activation_retry'], ':</dt>
<dd><input type="text" name="code" size="30"></dd>
</dl>
<p><input type="submit" value="'
$txt['invalid_activation_submit'], '" class="button"></p>
</div>
</form>'
;
}

/**
 * The form for resending the activation code.
 */
function template_resend()
{
global $context$txt$scripturl;

// Just ask them for their code so they can try it again...
echo '
<form action="'
$scripturl'?action=activate;sa=resend" method="post" accept-charset="'$context['character_set'], '">
<div class="title_bar">
<h3 class="titlebg">'
$context['page_title'], '</h3>
</div>
<div class="roundframe">
<dl>
<dt>'
$txt['invalid_activation_username'], ':</dt>
<dd><input type="text" name="user" size="40" value="'
$context['default_username'], '"></dd>
</dl>
<p>'
$txt['invalid_activation_new'], '</p>
<dl>
<dt>'
$txt['invalid_activation_new_email'], ':</dt>
<dd><input type="text" name="new_email" size="40"></dd>
<dt>'
$txt['invalid_activation_password'], ':</dt>
<dd><input type="password" name="passwd" size="30"></dd>
</dl>'
;

if ($context['can_activate'])
echo '
<p>'
$txt['invalid_activation_known'], '</p>
<dl>
<dt>'
$txt['invalid_activation_retry'], ':</dt>
<dd><input type="text" name="code" size="30"></dd>
</dl>'
;

echo '
<p><input type="submit" value="'
$txt['invalid_activation_resend'], '" class="button"></p>
</div><!-- .roundframe -->
</form>'
;
}

// OneAll Social Login (https://docs.oneall.com/plugins/)
function template_oneall_social_login()
{
global $txt$modSettings$boardurl;

if (!empty ($modSettings['oasl_api_key']) && !empty ($modSettings['oasl_enabled_providers']))
{
// Extract the chosen providers.
$providers explode (','trim ($modSettings['oasl_enabled_providers']));

// Create Random integer to prevent id collision.
$rand mt_rand (999999999999);

// Separe from the traditional login.
echo '<hr />';

// Display error messages if there are any.
if ( isset ($_REQUEST['oasl_err']))
{
switch ($_REQUEST['oasl_err'])
{
case 'user_does_not_exist':
echo '<p class="error">'.$txt['oasl_user_does_not_exist'].'</p>';
break;

case 'user_require_activation':
echo '<p class="error">'.$txt['oasl_user_require_activation'].'</p>';
break;

case 'user_registration_disabled':
echo '<p class="error">'.$txt['oasl_user_may_not_register'].'</p>';
break;
}
}

if ( ! empty ($modSettings['oasl_settings_login_caption']))
{
echo '
<p style="text-align:left;">
<strong>'
$modSettings['oasl_settings_login_caption'], '</strong>
</p>'
;
}

echo '
<p style="text-align:left;">
<div class="oneall_social_login_providers" id="oneall_social_login_providers_'
$rand'"></div>
<script type="text/javascript">
oneall.api.plugins.social_login.build("oneall_social_login_providers_'
$rand'", {
"providers": [\''
implode ("', '"$providers), '\'], 
"callback_uri": \''
$boardurl'/index.php?action=oasl_callback;oasl_source=login\',
});
</script>
<!-- OneAll.com / Social Login for SMF -->
</p>'
;
}
}

?>

Sir Osis of Liver

I've commented out the input field, and set cookielength with hidden input -



<!--dt>', $txt['time_logged_in'], ':</dt>
<dd>
<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-->';

// If they have deleted their account, give them a chance to change their mind.
if (isset($context['login_show_undelete']))
echo '
<dt class="alert">', $txt['undelete_account'], ':</dt>
<dd><input type="checkbox" name="undelete"></dd>';

echo '
</dl>
<p>
<input type="submit" value="', $txt['login'], '" class="button">
</p>
<p class="smalltext">
<a href="', $scripturl, '?action=reminder">', $txt['forgot_your_password'], '</a>
</p>
<input type="hidden" name="hash_passwrd" value="">
<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '">
<input type="hidden" name="cookielength" value="-1" />
<script>



This is for the primary login from index header link.  You should also make the change in function template_kick_guest() and function template_maintenance().  Don't think there're any more, unless you use a theme that has a header login.



Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Dylert

Ok, I don't understand much of this. Should I put your code into my login.template.php file somewhere??? Or...

Sir Osis of Liver

No, just make the changes.  At the top of the code I posted, you're commenting out the "Time to stay logged in:" input field (or you can delete that code).  At the bottom, you're adding the hidden input that sets cookielength to -1 (forever) for all logins.  Backup the original file, then you can tinker with the code til you get it.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Dylert

And then my login.template.php should look like....?

Sir Osis of Liver

Find the original code -



<dt>', $txt['time_logged_in'], ':</dt>
<dd>
<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>';

// If they have deleted their account, give them a chance to change their mind.
if (isset($context['login_show_undelete']))
echo '
<dt class="alert">', $txt['undelete_account'], ':</dt>
<dd><input type="checkbox" name="undelete"></dd>';

echo '
</dl>
<p>
<input type="submit" value="', $txt['login'], '" class="button">
</p>
<p class="smalltext">
<a href="', $scripturl, '?action=reminder">', $txt['forgot_your_password'], '</a>
</p>
<input type="hidden" name="hash_passwrd" value="">
<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '">
<script>



Then make the changes posted above.  Commenting out the first code block removes the input field from login window -



<!--dt>', $txt['time_logged_in'], ':</dt>
<dd>
<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-->';



Adding the hidden input makes all logins forever -



<input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '">
<input type="hidden" name="cookielength" value="-1" />
<script>



Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Dylert

Maybe you can put your code into my file??  :) :)

<?php
/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines http://www.simplemachines.org
 * @copyright 2019 Simple Machines and individual contributors
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.1 RC2
 */

/**
 * This is just the basic "login" form.
 */
function template_login()
{
global $context$settings$scripturl$modSettings$txt;

echo '
<div class="login">
<div class="cat_bar">
<h3 class="catbg">
<img src="'
$settings['images_url'], '/icons/login_hd.png" alt="" class="icon"> '$txt['login'], '
</h3>
</div>
<div class="roundframe">
<form class="login" action="'
$context['login_url'], '" name="frmLogin" id="frmLogin" method="post" accept-charset="'$context['character_set'], '">';

// Did they make a mistake last time?
if (!empty($context['login_errors']))
echo '
<div class="errorbox">'
implode('<br>'$context['login_errors']), '</div>
<br>'
;

// Or perhaps there's some special description for this time?
if (isset($context['description']))
echo '
<div class="information">'
$context['description'], '</div>';

// Now just get the basic information - username, password, etc.
echo '
<dl>
<dt>'
$txt['username'], ':</dt>
<dd>
<input type="text" id="'
, !empty($context['from_ajax']) ? 'ajax_' '''loginuser" name="user" size="20" value="'$context['default_username'], '">
</dd>
<dt>'
$txt['password'], ':</dt>
<dd>
<input type="password" id="'
, !empty($context['from_ajax']) ? 'ajax_' '''loginpass" name="passwrd" value="'$context['default_password'], '" size="20">
</dd>
</dl>
<dl>
<dt>'
$txt['time_logged_in'], ':</dt>
<dd>
<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>'
;

// If they have deleted their account, give them a chance to change their mind.
if (isset($context['login_show_undelete']))
echo '
<dt class="alert">'
$txt['undelete_account'], ':</dt>
<dd><input type="checkbox" name="undelete"></dd>'
;

echo '
</dl>
<p>
<input type="submit" value="'
$txt['login'], '" class="button">
</p>
<p class="smalltext">
<a href="'
$scripturl'?action=reminder">'$txt['forgot_your_password'], '</a>
</p>
<input type="hidden" name="hash_passwrd" value="">'
;

// OneAll Social Login (https://docs.oneall.com/plugins/)
template_oneall_social_login();

echo '
<input type="hidden" name="'
$context['session_var'], '" value="'$context['session_id'], '">
<input type="hidden" name="'
$context['login_token_var'], '" value="'$context['login_token'], '">
<script>
setTimeout(function() {
document.getElementById("'
, !empty($context['from_ajax']) ? 'ajax_' '', isset($context['default_username']) && $context['default_username'] != '' 'loginpass' 'loginuser''").focus();
}, 150);'
;

if (!empty($context['from_ajax']))
echo '
form = $("#frmLogin");
form.submit(function(e) {
e.preventDefault();
e.stopPropagation();

$.ajax({
url: form.prop("action"),
method: "POST",
data: form.serialize(),
success: function(data) {
if (data.indexOf("<bo" + "dy") > -1) {
document.open();
document.write(data);
document.close();
}
else
form.parent().html($(data).find(".roundframe").html());
},
error: function(xhr) {
var data = xhr.responseText;
if (data.indexOf("<bo" + "dy") > -1) {
document.open();
document.write(data);
document.close();
}
else
form.parent().html($(data).filter("#fatal_error").html());
}
});

return false;
});'
;

echo '
</script>
</form>'
;

// It is a long story as to why we have this when we're clearly not going to use it.
if (!empty($context['from_ajax']))
echo '
<br>
<a href="javascript:self.close();"></a>'
;

echo '
</div><!-- .roundframe -->
</div><!-- .login -->'
;
}

/**
 * TFA authentication form
 */
function template_login_tfa()
{
global $context$scripturl$txt;

echo '
<div class="login">
<div class="cat_bar">
<h3 class="catbg">
'
$txt['tfa_profile_label'], '
</h3>
</div>
<div class="roundframe">'
;

if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error']))
echo '
<div class="error">
'
$txt['tfa_' . (!empty($context['tfa_error']) ? 'code_' 'backup_') . 'invalid'], '
</div>'
;

echo '
<form action="'
$context['tfa_url'], '" method="post" id="frmTfa">
<div id="tfaCode">
<p style="margin-bottom: 0.5em">'
$txt['tfa_login_desc'], '</p>
<div class="centertext">
<strong>'
$txt['tfa_code'], ':</strong>
<input type="text" name="tfa_code" value="'
, !empty($context['tfa_value']) ? $context['tfa_value'] : '''">
<input type="submit" class="button" name="submit" value="'
$txt['login'], '">
</div>
<hr>
<div class="centertext">
<input type="button" class="button" name="backup" value="'
$txt['tfa_backup'], '">
</div>
</div>
<div id="tfaBackup" style="display: none;">
<p style="margin-bottom: 0.5em">'
$txt['tfa_backup_desc'], '</p>
<div class="centertext">
<strong>'
$txt['tfa_backup_code'], ': </strong>
<input type="text" name="tfa_backup" value="'
, !empty($context['tfa_backup']) ? $context['tfa_backup'] : '''">
<input type="submit" class="button" name="submit" value="'
$txt['login'], '">
</div>
</div>
</form>
<script>
form = $("#frmTfa");'
;

if (!empty($context['from_ajax']))
echo '
form.submit(function(e) {
// If we are submitting backup code, let normal workflow follow since it redirects a couple times into a different page
if (form.find("input[name=tfa_backup]:first").val().length > 0)
return true;

e.preventDefault();
e.stopPropagation();

$.post(form.prop("action"), form.serialize(), function(data) {
if (data.indexOf("<bo" + "dy") > -1)
document.location = '
JavaScriptEscape(!empty($_SESSION['login_url']) ? $_SESSION['login_url'] : $scripturl), ';
else {
form.parent().html($(data).find(".roundframe").html());
}
});

return false;
});'
;

echo '
form.find("input[name=backup]").click(function(e) {
$("#tfaBackup").show();
$("#tfaCode").hide();
});
</script>
</div><!-- .roundframe -->
</div><!-- .login -->'
;
}

/**
 * Tell a guest to get lost or login!
 */
function template_kick_guest()
{
global $context$settings$scripturl$modSettings$txt;

// This isn't that much... just like normal login but with a message at the top.
echo '
<form action="'
$context['login_url'], '" method="post" accept-charset="'$context['character_set'], '" name="frmLogin" id="frmLogin">
<div class="login">
<div class="cat_bar">
<h3 class="catbg">'
$txt['warning'], '</h3>
</div>'
;

// Show the message or default message.
echo '
<p class="information centertext">
'
, empty($context['kick_message']) ? $txt['only_members_can_access'] : $context['kick_message'], '<br>';

if ($context['can_register'])
echo sprintf($txt['login_below_or_register'], $scripturl '?action=signup'$context['forum_name_html_safe']);
else
echo $txt['login_below'];

// And now the login information.
echo '
<div class="cat_bar">
<h3 class="catbg">
<img src="'
$settings['images_url'], '/icons/login_hd.png" alt="" class="icon"> '$txt['login'], '
</h3>
</div>
<div class="roundframe">
<dl>
<dt>'
$txt['username'], ':</dt>
<dd><input type="text" name="user" size="20"></dd>
<dt>'
$txt['password'], ':</dt>
<dd><input type="password" name="passwrd" size="20"></dd>
<dt>'
$txt['time_logged_in'], ':</dt>
<dd>
<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">
<input type="submit" value="'
$txt['login'], '" class="button">
</p>
<p class="centertext smalltext">
<a href="'
$scripturl'?action=reminder">'$txt['forgot_your_password'], '</a>
</p>
</div>'
;

// OneAll Social Login (https://docs.oneall.com/plugins/)
template_oneall_social_login();

echo '
<input type="hidden" name="'
$context['session_var'], '" value="'$context['session_id'], '">
<input type="hidden" name="'
$context['login_token_var'], '" value="'$context['login_token'], '">
<input type="hidden" name="hash_passwrd" value="">
</div><!-- .login -->
</form>'
;

// Do the focus thing...
echo '
<script>
document.forms.frmLogin.user.focus();
</script>'
;
}

/**
 * This is for maintenance mode.
 */
function template_maintenance()
{
global $context$settings$txt$modSettings;

// Display the administrator's message at the top.
echo '
<form action="'
$context['login_url'], '" method="post" accept-charset="'$context['character_set'], '">
<div class="login" id="maintenance_mode">
<div class="cat_bar">
<h3 class="catbg">'
$context['title'], '</h3>
</div>
<div class="information">
<img class="floatleft" src="'
$settings['images_url'], '/construction.png" width="40" height="40" alt="'$txt['in_maintain_mode'], '">
'
$context['description'], '<br class="clear">
</div>
<div class="title_bar">
<h4 class="titlebg">'
$txt['admin_login'], '</h4>
</div>
<div class="roundframe">
<dl>
<dt>'
$txt['username'], ':</dt>
<dd><input type="text" name="user" size="20"></dd>
<dt>'
$txt['password'], ':</dt>
<dd><input type="password" name="passwrd" size="20"></dd>
<dt>'
$txt['time_logged_in'], ':</dt>
<dd>
<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">
<br class="clear">
</div>
<input type="hidden" name="hash_passwrd" value="">
<input type="hidden" name="'
$context['session_var'], '" value="'$context['session_id'], '">
<input type="hidden" name="'
$context['login_token_var'], '" value="'$context['login_token'], '">
</div><!-- #maintenance_mode -->
</form>'
;
}

/**
 * This is for the security stuff - makes administrators login every so often.
 */
function template_admin_login()
{
global $context$settings$scripturl$txt$modSettings;

// Since this should redirect to whatever they were doing, send all the get data.
echo '
<form action="'
, !empty($modSettings['force_ssl']) ? strtr($scripturl, array('http://' => 'https://')) : $scripturl$context['get_data'], '" method="post" accept-charset="'$context['character_set'], '" name="frmLogin" id="frmLogin">
<div class="login" id="admin_login">
<div class="cat_bar">
<h3 class="catbg">
<img src="'
$settings['images_url'], '/icons/login_hd.png" alt="" class="icon"> '$txt['login'], '
</h3>
</div>
<div class="roundframe centertext">'
;

if (!empty($context['incorrect_password']))
echo '
<div class="error">'
$txt['admin_incorrect_password'], '</div>';

echo '
<strong>'
$txt['password'], ':</strong>
<input type="password" name="'
$context['sessionCheckType'], '_pass" size="24">
<a href="'
$scripturl'?action=helpadmin;help=securityDisable_why" onclick="return reqOverlayDiv(this.href);" class="help"><span class="main_icons help" title="'$txt['help'], '"></span></a><br>
<input type="hidden" name="'
$context['session_var'], '" value="'$context['session_id'], '">
<input type="hidden" name="'
$context['admin-login_token_var'], '" value="'$context['admin-login_token'], '">
<input type="submit" value="'
$txt['login'], '" class="button">';

// Make sure to output all the old post data.
echo $context['post_data'], '
</div><!-- .roundframe -->
</div><!-- #admin_login -->
<input type="hidden" name="'
$context['sessionCheckType'], '_hash_pass" value="">
</form>'
;

// Focus on the password box.
echo '
<script>
document.forms.frmLogin.'
$context['sessionCheckType'], '_pass.focus();
</script>'
;
}

/**
 * Activate your account manually?
 */
function template_retry_activate()
{
global $context$txt$scripturl;

// Just ask them for their code so they can try it again...
echo '
<form action="'
$scripturl'?action=activate;u='$context['member_id'], '" method="post" accept-charset="'$context['character_set'], '">
<div class="title_bar">
<h3 class="titlebg">'
$context['page_title'], '</h3>
</div>
<div class="roundframe">
<dl>'
;

// You didn't even have an ID?
if (empty($context['member_id']))
echo '
<dt>'
$txt['invalid_activation_username'], ':</dt>
<dd><input type="text" name="user" size="30"></dd>'
;

echo '
<dt>'
$txt['invalid_activation_retry'], ':</dt>
<dd><input type="text" name="code" size="30"></dd>
</dl>
<p><input type="submit" value="'
$txt['invalid_activation_submit'], '" class="button"></p>
</div>
</form>'
;
}

/**
 * The form for resending the activation code.
 */
function template_resend()
{
global $context$txt$scripturl;

// Just ask them for their code so they can try it again...
echo '
<form action="'
$scripturl'?action=activate;sa=resend" method="post" accept-charset="'$context['character_set'], '">
<div class="title_bar">
<h3 class="titlebg">'
$context['page_title'], '</h3>
</div>
<div class="roundframe">
<dl>
<dt>'
$txt['invalid_activation_username'], ':</dt>
<dd><input type="text" name="user" size="40" value="'
$context['default_username'], '"></dd>
</dl>
<p>'
$txt['invalid_activation_new'], '</p>
<dl>
<dt>'
$txt['invalid_activation_new_email'], ':</dt>
<dd><input type="text" name="new_email" size="40"></dd>
<dt>'
$txt['invalid_activation_password'], ':</dt>
<dd><input type="password" name="passwd" size="30"></dd>
</dl>'
;

if ($context['can_activate'])
echo '
<p>'
$txt['invalid_activation_known'], '</p>
<dl>
<dt>'
$txt['invalid_activation_retry'], ':</dt>
<dd><input type="text" name="code" size="30"></dd>
</dl>'
;

echo '
<p><input type="submit" value="'
$txt['invalid_activation_resend'], '" class="button"></p>
</div><!-- .roundframe -->
</form>'
;
}

// OneAll Social Login (https://docs.oneall.com/plugins/)
function template_oneall_social_login()
{
global $txt$modSettings$boardurl;

if (!empty ($modSettings['oasl_api_key']) && !empty ($modSettings['oasl_enabled_providers']))
{
// Extract the chosen providers.
$providers explode (','trim ($modSettings['oasl_enabled_providers']));

// Create Random integer to prevent id collision.
$rand mt_rand (999999999999);

// Separe from the traditional login.
echo '<hr />';

// Display error messages if there are any.
if ( isset ($_REQUEST['oasl_err']))
{
switch ($_REQUEST['oasl_err'])
{
case 'user_does_not_exist':
echo '<p class="error">'.$txt['oasl_user_does_not_exist'].'</p>';
break;

case 'user_require_activation':
echo '<p class="error">'.$txt['oasl_user_require_activation'].'</p>';
break;

case 'user_registration_disabled':
echo '<p class="error">'.$txt['oasl_user_may_not_register'].'</p>';
break;
}
}

if ( ! empty ($modSettings['oasl_settings_login_caption']))
{
echo '
<p style="text-align:left;">
<strong>'
$modSettings['oasl_settings_login_caption'], '</strong>
</p>'
;
}

echo '
<p style="text-align:left;">
<div class="oneall_social_login_providers" id="oneall_social_login_providers_'
$rand'"></div>
<script type="text/javascript">
oneall.api.plugins.social_login.build("oneall_social_login_providers_'
$rand'", {
"providers": [\''
implode ("', '"$providers), '\'], 
"callback_uri": \''
$boardurl'/index.php?action=oasl_callback;oasl_source=login\',
});
</script>
<!-- OneAll.com / Social Login for SMF -->
</p>'
;
}
}

?>

Sir Osis of Liver

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Dylert


skb

Thanks.

What if 'Always stay logged in' is required as a default, but the other options are required as well.
I tried the GH changes, they put 'Always Stay logged in" on the top of the drop down menu, but default 1 Hour remains unchanged. 

SMF 2.1.4 / TP 2.2.2

Sir Osis of Liver

You can change the default cookielength in Admin -> Server Settings -> Cookies and Sessions -> Default login cookies length, that should do what you want.

Bear in mind that if you're running an RC, future upgrades leading to final release may overwrite Login.template.php, which will require restoring code edits manually.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Dylert

Quote from: Sir Osis of Liver on October 19, 2019, 07:54:40 PM
<sigh>  Try the attached.

With this login-file I lose my social login. See attachment.
How can I keep the sosial login? Any suggestion?

Dylert


Sir Osis of Liver

You'll have to do the code edits manually, the template has been modified by the social login mod, or try uninstall/reinstall the mod on the new template (you'll get errors).
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Advertisement: