From 188f15f53f17d7660e6ebe8b6f5cca8f98dbafca Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Mon, 24 Jul 2023 13:30:42 +0700 Subject: [PATCH] Minor improvements (#845) --- library/ajax/gen_passkey.php | 42 +++++++++++++------ src/Legacy/Torrent.php | 13 +++++- styles/templates/default/page_header.tpl | 2 +- .../templates/default/usercp_viewprofile.tpl | 4 +- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/library/ajax/gen_passkey.php b/library/ajax/gen_passkey.php index 67c534895..cfb7f78f4 100644 --- a/library/ajax/gen_passkey.php +++ b/library/ajax/gen_passkey.php @@ -14,22 +14,40 @@ if (!defined('IN_AJAX')) { global $userdata, $lang; $req_uid = (int)$this->request['user_id']; +$mode = (string)$this->request['mode']; if ($req_uid == $userdata['user_id'] || IS_ADMIN) { - $first_creation = !\TorrentPier\Legacy\Torrent::getPasskey($req_uid); + switch ($mode) { + case 'create': + $first_creation = !\TorrentPier\Legacy\Torrent::getPasskey($req_uid); - if (empty($this->request['confirmed']) && !$first_creation) { - $this->prompt_for_confirm($lang['BT_GEN_PASSKEY_NEW']); + if (empty($this->request['confirmed']) && !$first_creation) { + $this->prompt_for_confirm($lang['BT_GEN_PASSKEY_NEW']); + } + + if (!$passkey = \TorrentPier\Legacy\Torrent::generate_passkey($req_uid, IS_ADMIN)) { + $this->ajax_die('Could not insert passkey'); + } + + \TorrentPier\Legacy\Torrent::tracker_rm_user($req_uid); + + $this->response['first_creation'] = $first_creation; + $this->response['passkey'] = $passkey; + break; + case 'remove': + if (empty($this->request['confirmed'])) { + $this->prompt_for_confirm($lang['QUESTION']); + } + + if (!$delete = \TorrentPier\Legacy\Torrent::deletePasskey($req_uid)) { + $this->ajax_die('Could not remove passkey'); + } + + $this->response['passkey_removed'] = $delete; + break; + default: + $this->ajax_die('Invalid mode'); } - - if (!$passkey = \TorrentPier\Legacy\Torrent::generate_passkey($req_uid, IS_ADMIN)) { - $this->ajax_die('Could not insert passkey'); - } - - \TorrentPier\Legacy\Torrent::tracker_rm_user($req_uid); - - $this->response['first_creation'] = $first_creation; - $this->response['passkey'] = $passkey; } else { $this->ajax_die($lang['NOT_AUTHORISED']); } diff --git a/src/Legacy/Torrent.php b/src/Legacy/Torrent.php index 2c7662a92..43000b065 100644 --- a/src/Legacy/Torrent.php +++ b/src/Legacy/Torrent.php @@ -739,7 +739,7 @@ class Torrent } /** - * Returns the user's passkey, false otherwise + * Returns the user passkey, false otherwise * * @param int|string $user_id * @return bool|string @@ -752,4 +752,15 @@ class Torrent return false; } + + /** + * Removes user passkey, false otherwise + * + * @param int|string $user_id + * @return bool + */ + public static function deletePasskey($user_id): bool + { + return (bool)DB()->query("DELETE FROM " . BB_BT_USERS . " WHERE user_id = " . (int)$user_id); + } } diff --git a/styles/templates/default/page_header.tpl b/styles/templates/default/page_header.tpl index 25df0dca6..73733d67d 100644 --- a/styles/templates/default/page_header.tpl +++ b/styles/templates/default/page_header.tpl @@ -483,7 +483,7 @@ $(document).ready(function() {

{L_PASSKEY_ALERT_TITLE}


{L_PASSKEY_ALERT_INFO} - {L_BT_GEN_PASSKEY} + {L_BT_GEN_PASSKEY}
diff --git a/styles/templates/default/usercp_viewprofile.tpl b/styles/templates/default/usercp_viewprofile.tpl index 24f37acb3..faca3507d 100644 --- a/styles/templates/default/usercp_viewprofile.tpl +++ b/styles/templates/default/usercp_viewprofile.tpl @@ -169,7 +169,7 @@ ajax.callback.index_data = function(data) {