Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stay Logged In Plugin #8689

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c924aed
Create config.inc.php
Github-Citizen Aug 25, 2022
3804f50
Create stay_loggedin.js
Github-Citizen Aug 25, 2022
1878ff6
Create stay_loggedin.php
Github-Citizen Aug 25, 2022
ea8bb29
Create en_US.inc
Github-Citizen Aug 25, 2022
5dfc41a
Create cs_CZ.inc
Github-Citizen Aug 25, 2022
8761d62
Create da_DK.inc
Github-Citizen Aug 25, 2022
eaf255c
Create de_DE.inc
Github-Citizen Aug 25, 2022
a0da83f
Create en_CA.inc
Github-Citizen Aug 25, 2022
0045e5e
Create en_GB.inc
Github-Citizen Aug 25, 2022
58776e5
Create es_ES.inc
Github-Citizen Aug 25, 2022
bbaa268
Create fi_FI.inc
Github-Citizen Aug 25, 2022
ff92694
Create fr_FR.inc
Github-Citizen Aug 25, 2022
a708d0a
Create hu_HU.inc
Github-Citizen Aug 25, 2022
8566d37
Create id_ID.inc
Github-Citizen Aug 25, 2022
88719de
Create it_IT.inc
Github-Citizen Aug 25, 2022
9c1058b
Create nl_NL.inc
Github-Citizen Aug 25, 2022
b88a9d8
Create pl_PL.inc
Github-Citizen Aug 25, 2022
32bfe6d
Create ru_RU.inc
Github-Citizen Aug 25, 2022
b85ab70
Create sr_CS.inc
Github-Citizen Aug 25, 2022
ef8c44a
Create sv_SE.inc
Github-Citizen Aug 25, 2022
1c54fb8
Create uk_UA.inc
Github-Citizen Aug 25, 2022
13042f0
Update stay_loggedin.php
Github-Citizen Aug 25, 2022
54fed52
Update stay_loggedin.php
Github-Citizen Aug 25, 2022
ea51783
Delete cs_CZ.inc
Github-Citizen Sep 24, 2022
e14f21b
Delete da_DK.inc
Github-Citizen Sep 24, 2022
ce7d5b0
Delete de_DE.inc
Github-Citizen Sep 24, 2022
7eb6725
Delete en_GB.inc
Github-Citizen Sep 24, 2022
38da3b1
Delete es_ES.inc
Github-Citizen Sep 24, 2022
455f70c
Delete fr_FR.inc
Github-Citizen Sep 24, 2022
670ae56
Delete hu_HU.inc
Github-Citizen Sep 24, 2022
2cd59bf
Delete id_ID.inc
Github-Citizen Sep 24, 2022
200dfca
Delete it_IT.inc
Github-Citizen Sep 24, 2022
cae6bba
Delete nl_NL.inc
Github-Citizen Sep 24, 2022
751e2f3
Delete pl_PL.inc
Github-Citizen Sep 24, 2022
3fd36cb
Delete ru_RU.inc
Github-Citizen Sep 24, 2022
0cecfa1
Delete sr_CS.inc
Github-Citizen Sep 24, 2022
1611f7b
Delete sv_SE.inc
Github-Citizen Sep 24, 2022
a6ee420
Delete en_CA.inc
Github-Citizen Sep 24, 2022
aa6a72d
Delete fi_FI.inc
Github-Citizen Sep 24, 2022
692d0d7
Delete uk_UA.inc
Github-Citizen Sep 24, 2022
a8db0e0
Update en_US.inc
Github-Citizen Sep 25, 2022
79ac633
Update stay_loggedin.js
Github-Citizen Sep 25, 2022
4ad6f5f
Update config
Github-Citizen Sep 25, 2022
b73fcd6
Update stay_loggedin.js
Github-Citizen Sep 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .tx/config
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ file_filter = plugins/password/localization/<lang>.inc
source_file = plugins/password/localization/en_US.inc
source_lang = en_US

[roundcube-webmail.plugin-stay_loggedin]
file_filter = plugins/stay_loggedin/localization/<lang>.inc
source_file = plugins/stay_loggedin/localization/en_US.inc
source_lang = en_US

[roundcube-webmail.plugin-subscriptions_option]
file_filter = plugins/subscriptions_option/localization/<lang>.inc
source_file = plugins/subscriptions_option/localization/en_US.inc
Expand Down
23 changes: 23 additions & 0 deletions plugins/stay_loggedin/config.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
#
# Stay-Logged-In plugin for the Roundcube Elastic skin.
#
# Set the number of days users will stay logged in, if they turn on the toggle switch.
# The maximum number of days that can be set is 365 (1 year).
# Setting to '0' will disable plugin and remove toggle switch from the login page.
#

$config['stay_loggedin_days'] = 7;

#
# Don't forget to add plugin to config/config.inc.php
# $config['plugins'] = [
# ...
# 'stay_loggedin',
# ...
# ];
#
# Notice; This plugin will over-ride $config['session_lifetime']
# (which sets the session garbage collection max lifetime in PHP)
# to match the number of days set above.
#
7 changes: 7 additions & 0 deletions plugins/stay_loggedin/localization/en_US.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
#
# When translating keep the '#' symbol in the sentence and it will be
# converted to the number of days set in the config.inc.php file.
#

$labels['toggle'] = 'Stay logged in for # days';
25 changes: 25 additions & 0 deletions plugins/stay_loggedin/stay_loggedin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$(document).ready(function () {
if (window.rcmail && window.rcmail.env.skin == 'elastic') {
rcmail.addEventListener('init', function () {

let days = rcmail.env.stay_loggedin_days;
let txt = rcmail.gettext('toggle', 'stay_loggedin');
txt = txt.replace("#", days);

let html = '';
html += '<tr class="form-group row">';
html += '<td class="title" style="display: none;"></td>';
html += '<td class="input input-group input-group-lg">';
html += '<div class="custom-control custom-switch" style="padding: 1em 0;">';
html += '<input type="checkbox" class="custom-control-input" id="_stay_loggedin" name="_stay_loggedin" value="1">';
html += '<label class="custom-control-label" for="_stay_loggedin">' + txt + '</label>';
html += '</div>';
html += '</td>';
html += '</tr>';

let element = $('#login-form table tbody');
element.append(html);

});
}
});
41 changes: 41 additions & 0 deletions plugins/stay_loggedin/stay_loggedin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
class stay_loggedin extends rcube_plugin {

private $rc;
private $days;

function onload() {
$this->rc = rcmail::get_instance();
$this->load_config();
$this->days = (int)$this->rc->config->get('stay_loggedin_days', 0);
if ($this->days < 1) $this->days = 0;
if ($this->days > 365) $this->days = 365;
if ($this->days) $this->rc->config->set('session_lifetime', $this->days * 24 * 60);
}

function init() {
if (!$this->days) return;
$this->rc->output->set_env('stay_loggedin_days', $this->days);
$this->add_hook('template_object_loginform', array($this, 'loginPageTemplate'));
$this->add_hook('login_after', array($this, 'loginSuccess'));
}

function loginPageTemplate($args) {
$this->add_texts('localization', true);
$this->include_script('stay_loggedin.js');
return $args;
}

function loginSuccess($args) {
if (!isset($_POST['_stay_loggedin']) || !$_POST['_stay_loggedin']) return $args;
$sessCookieName = $this->rc->config->get('session_name');
$authCookieName = $this->rc->config->get('session_auth_name');
$sessCookieValue = session_id();
$authCookieValue = (isset($_COOKIE[$authCookieName])) ? $_COOKIE[$authCookieName] : 'Error: Auth Cookie Missing';
$exp = time() + ($this->days * 24 * 60 * 60);
rcube_utils::setcookie($sessCookieName, $sessCookieValue, $exp);
rcube_utils::setcookie($authCookieName, $authCookieValue, $exp);
return $args;
}

}