1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-07 01:06:48 +02:00

Merge pull request #6012 from rxu/ticket/16533

[ticket/16533] Add autologin keys management UCP module events
This commit is contained in:
Marc Alexander
2020-08-13 21:15:59 +02:00
6 changed files with 166 additions and 14 deletions

View File

@@ -2730,6 +2730,62 @@ ucp_prefs_view_select_menu_prepend
* Purpose: Add options to the top of the drop-down lists block of the Edit
Display Options screen
ucp_profile_autologin_keys_tbody_key_after
===
* Locations:
+ styles/prosilver/template/ucp_profile_autologin_keys.html
* Since: 3.3.2-RC1
* Purpose: Add table column after the first column.
ucp_profile_autologin_keys_tbody_key_before
===
* Locations:
+ styles/prosilver/template/ucp_profile_autologin_keys.html
* Since: 3.3.2-RC1
* Purpose: Add table column before the first column.
ucp_profile_autologin_keys_tbody_mark_after
===
* Locations:
+ styles/prosilver/template/ucp_profile_autologin_keys.html
* Since: 3.3.2-RC1
* Purpose: Add table column after the last column.
ucp_profile_autologin_keys_tbody_mark_before
===
* Locations:
+ styles/prosilver/template/ucp_profile_autologin_keys.html
* Since: 3.3.2-RC1
* Purpose: Add table column before the last column.
ucp_profile_autologin_keys_thead_key_after
===
* Locations:
+ styles/prosilver/template/ucp_profile_autologin_keys.html
* Since: 3.3.2-RC1
* Purpose: Add table header content after the first column.
ucp_profile_autologin_keys_thead_key_before
===
* Locations:
+ styles/prosilver/template/ucp_profile_autologin_keys.html
* Since: 3.3.2-RC1
* Purpose: Add table header content before the first column.
ucp_profile_autologin_keys_thead_mark_after
===
* Locations:
+ styles/prosilver/template/ucp_profile_autologin_keys.html
* Since: 3.3.2-RC1
* Purpose: Add table header content after the last column.
ucp_profile_autologin_keys_thead_mark_before
===
* Locations:
+ styles/prosilver/template/ucp_profile_autologin_keys.html
* Since: 3.3.2-RC1
* Purpose: Add table header content before the last column.
ucp_profile_profile_info_after
===
* Locations:

View File

@@ -810,23 +810,50 @@ class ucp_profile
$error = array_map(array($user, 'lang'), $error);
}
$sql = 'SELECT key_id, last_ip, last_login
FROM ' . SESSIONS_KEYS_TABLE . '
WHERE user_id = ' . (int) $user->data['user_id'] . '
ORDER BY last_login ASC';
$sql_ary = [
'SELECT' => 'sk.key_id, sk.last_ip, sk.last_login',
'FROM' => [SESSIONS_KEYS_TABLE => 'sk'],
'WHERE' => 'sk.user_id = ' . (int) $user->data['user_id'],
'ORDER_BY' => 'sk.last_login ASC',
];
$result = $db->sql_query($sql);
/**
* Event allows changing SQL query for autologin keys
*
* @event core.ucp_profile_autologin_keys_sql
* @var array sql_ary Array with autologin keys SQL query
* @since 3.3.2-RC1
*/
$vars = ['sql_ary'];
extract($phpbb_dispatcher->trigger_event('core.ucp_profile_autologin_keys_sql', compact($vars)));
while ($row = $db->sql_fetchrow($result))
$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
$sessions = (array) $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$template_vars = [];
foreach ($sessions as $row)
{
$template->assign_block_vars('sessions', array(
'KEY' => substr($row['key_id'], 0, 8),
$key = substr($row['key_id'], 0, 8);
$template_vars[$key] = [
'KEY' => $key,
'IP' => $row['last_ip'],
'LOGIN_TIME' => $user->format_date($row['last_login']),
));
];
}
$db->sql_freeresult($result);
/**
* Event allows changing template variables
*
* @event core.ucp_profile_autologin_keys_template_vars
* @var array sessions Array with session keys data
* @var array template_vars Array with template variables
* @since 3.3.2-RC1
*/
$vars = ['sessions', 'template_vars'];
extract($phpbb_dispatcher->trigger_event('core.ucp_profile_autologin_keys_template_vars', compact($vars)));
$template->assign_block_vars_array('sessions', $template_vars);
break;
}

View File

@@ -1457,7 +1457,7 @@ class session
*/
function set_login_key($user_id = false, $key = false, $user_ip = false)
{
global $db;
global $db, $phpbb_dispatcher;
$user_id = ($user_id === false) ? $this->data['user_id'] : $user_id;
$user_ip = ($user_ip === false) ? $this->ip : $user_ip;
@@ -1489,6 +1489,29 @@ class session
{
$sql = 'INSERT INTO ' . SESSIONS_KEYS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
}
/**
* Event to adjust autologin keys process
*
* @event core.set_login_key
* @var string|false key Current autologin key if exists, false otherwise
* @var string key_id New autologin key
* @var string sql SQL query to update/insert autologin key
* @var array sql_ary Aray with autologin key data
* @var int user_id Current user's ID
* @var string user_ip Current user's IP address
* @since 3.3.2-RC1
*/
$vars = [
'key',
'key_id',
'sql',
'sql_ary',
'user_id',
'user_ip',
];
extract($phpbb_dispatcher->trigger_event('core.set_login_key', compact($vars)));
$db->sql_query($sql);
$this->cookie_data['k'] = $key_id;

View File

@@ -7,25 +7,34 @@
<div class="inner">
<p>{L_PROFILE_AUTOLOGIN_KEYS}</p>
<!-- IF ERROR --><p class="error">{ERROR}</p><!-- ENDIF -->
{% DEFINE COLSPAN = 4 %}
<table class="table1">
<thead>
<tr>
{% EVENT ucp_profile_autologin_keys_thead_key_before %}
<th class="name">{L_LOGIN_KEY}</th>
{% EVENT ucp_profile_autologin_keys_thead_key_after %}
<th class="center">{L_IP}</th>
<th class="center">{L_LOGIN_TIME}</th>
{% EVENT ucp_profile_autologin_keys_thead_mark_before %}
<th class="center mark">{L_MARK}</th>
{% EVENT ucp_profile_autologin_keys_thead_mark_after %}
</tr>
</thead>
<tbody>
<!-- BEGIN sessions -->
<!-- IF sessions.S_ROW_COUNT is even --><tr class="bg1"><!-- ELSE --><tr class="bg2"><!-- ENDIF -->
{% EVENT ucp_profile_autologin_keys_tbody_key_before %}
<td><label for="{sessions.KEY}">{sessions.KEY}</label></td>
{% EVENT ucp_profile_autologin_keys_tbody_key_after %}
<td class="center">{sessions.IP}</td>
<td class="center">{sessions.LOGIN_TIME}</td>
{% EVENT ucp_profile_autologin_keys_tbody_mark_before %}
<td class="center mark"><input type="checkbox" name="keys[]" value="{sessions.KEY}" id="{sessions.KEY}" /></td>
{% EVENT ucp_profile_autologin_keys_tbody_mark_after %}
</tr>
<!-- BEGINELSE -->
<tr><td colspan="4" class="bg1" style="text-align: center">{L_PROFILE_NO_AUTOLOGIN_KEYS}</td></tr>
<tr><td colspan="{{ definition.COLSPAN }}" class="bg1" style="text-align: center">{L_PROFILE_NO_AUTOLOGIN_KEYS}</td></tr>
<!-- END sessions -->
</tbody>
</table>