Skip to content

Commit

Permalink
Logout rework (#3008)
Browse files Browse the repository at this point in the history
* Logout rework

* Uncomment

* Output logout complete message via die()

Co-authored-by: Tadhg Boyle <tadhgsmboyle@gmail.com>

* Add indentation back

Co-authored-by: Tadhg Boyle <tadhgsmboyle@gmail.com>
  • Loading branch information
samerton and tadhgboyle authored Aug 13, 2022
1 parent 52e9559 commit be5c947
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions core/templates/navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
'title' => $language->get('general', 'log_out'),
'link' => URL::build('/logout'),
'target' => '',
'action' => 'logout',
],
],
];
Expand Down
2 changes: 2 additions & 0 deletions custom/languages/en_UK.json
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@
"general/links": "Links",
"general/loading": "Loading...",
"general/log_out": "Log Out",
"general/log_out_click": "Click here to log out",
"general/log_out_complete": "Logout successful. Click {{linkStart}}here{{linkEnd}} to continue.",
"general/more": "More",
"general/next": "Next",
"general/no": "No",
Expand Down
11 changes: 11 additions & 0 deletions custom/templates/DefaultRevamp/js/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ function copy(element) {
});
}

$(document).ready(function () {
$('[data-action="logout"]').click(function () {
const url = $(this).data('link');
$.post(url, {
token: csrfToken
}).done(function () {
window.location.reload();
});
});
});

$(function () {
$('.ui.sidebar').sidebar('attach events', '.toc.item');

Expand Down
11 changes: 9 additions & 2 deletions custom/templates/DefaultRevamp/navbar.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@
{if isset($dropdown.separator)}
<div class="ui divider"></div>
{else}
<a class="item" href="{$dropdown.link}" target="{$dropdown.target}">{$dropdown.icon}
{$dropdown.title}</a>
{if isset($dropdown.action)}
<a class="item" href="#" data-link="{$dropdown.link}" data-action="{$dropdown.action}">
{$dropdown.icon} {$dropdown.title}
</a>
{else}
<a class="item" href="{$dropdown.link}" target="{$dropdown.target}">
{$dropdown.icon} {$dropdown.title}
</a>
{/if}
{/if}
{/foreach}
</div>
Expand Down
5 changes: 3 additions & 2 deletions custom/templates/DefaultRevamp/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public function onPageLoad() {
'loggedIn' => $this->_user->isLoggedIn() ? '1' : '0',
'cookie' => defined('COOKIE_NOTICE') ? '1' : '0',
'loadingTime' => Util::getSetting('page_loading') === '1' ? PAGE_LOAD_TIME : '',
'route' => $route
'route' => $route,
'csrfToken' => Token::get(),
];

if (strpos($route, '/forum/topic/') !== false || PAGE == 'profile') {
Expand All @@ -136,7 +137,7 @@ public function onPageLoad() {
$this->addJSScript($JSVars);

$this->addJSFiles([
$this->_template['path'] . 'js/core/core.js' => [],
$this->_template['path'] . 'js/core/core.js?v=202' => [],
$this->_template['path'] . 'js/core/user.js' => [],
$this->_template['path'] . 'js/core/pages.js' => [],
$this->_template['path'] . 'js/scripts.js' => [],
Expand Down
27 changes: 22 additions & 5 deletions modules/Core/pages/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,35 @@
/*
* Made by Samerton
* https://github.com/NamelessMC/Nameless/
* NamelessMC version 2.0.0-dev
* NamelessMC version 2.0.2
*
* License: MIT
*
* Log user out
*/

if ($user->isLoggedIn()) {
Log::getInstance()->log(Log::Action('user/logout'));
$user->admLogout();
$user->logout();
if (Input::exists()) {
if (Token::check()) {
Log::getInstance()->log(Log::Action('user/logout'));
$user->admLogout();
$user->logout();

Session::flash('home', $language->get('user', 'successfully_logged_out'));
Session::flash('home', $language->get('user', 'successfully_logged_out'));
die($language->get('general', 'log_out_complete', ['linkStart' => '<a href="' . URL::build('/') . '">', 'linkEnd' => '</a>']));
}

echo $language->get('general', 'invalid_token') . '<hr />';
}

echo '
<form method="post" action="" id="logout">
<input type="hidden" name="token" value="' . Token::get() . '">
</form>
<a href="javascript:void(0)" onclick="document.getElementById(\'logout\').submit();">' . $language->get('general', 'log_out_click') . '</a>
';

return;
}

Redirect::to(URL::build('/'));

0 comments on commit be5c947

Please sign in to comment.