made logout dynamic
This commit is contained in:
parent
dc0fc54aad
commit
e38a40e5fe
5 changed files with 53 additions and 29 deletions
|
@ -43,13 +43,13 @@ class AuthController extends Controller
|
||||||
public function logout(): string
|
public function logout(): string
|
||||||
{
|
{
|
||||||
if (!session_check()) {
|
if (!session_check()) {
|
||||||
return view('auth/logout');
|
return $this->json(['error' => 'Logout failed.']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the active session
|
// Destroy the active session
|
||||||
CurrentSession::stop();
|
CurrentSession::stop();
|
||||||
|
|
||||||
return redirect(route('main.index'));
|
return $this->json(['error' => null]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<a class="header__entry fa-home" href="{{ route('main.index') }}">home</a>
|
<a class="header__entry fa-home" href="{{ route('main.index') }}">home</a>
|
||||||
<a class="header__entry fa-comments" href="{{ route('forums.index') }}">forum</a>
|
<a class="header__entry fa-comments" href="{{ route('forums.index') }}">forum</a>
|
||||||
<a class="header__entry fa-cog" href="{{ route('settings.index') }}">settings</a>
|
<a class="header__entry fa-cog" href="{{ route('settings.index') }}">settings</a>
|
||||||
<a class="header__entry fa-sign-out" href="{{ route('auth.logout') }}">logout</a>
|
<a class="header__entry fa-sign-out" href="#">logout</a>
|
||||||
</div>
|
</div>
|
||||||
{% if user.isActive %}
|
{% if user.isActive %}
|
||||||
<a class="header__user" href="{{ route('user.profile', user.id) }}" style="color: {{ user.colour }}">
|
<a class="header__user" href="{{ route('user.profile', user.id) }}" style="color: {{ user.colour }}">
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
{% extends 'master.twig' %}
|
|
||||||
|
|
||||||
{% set title = 'Logout' %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="auth content content--auth">
|
|
||||||
<div class="content__header">
|
|
||||||
Are you sure?
|
|
||||||
</div>
|
|
||||||
<form method="post" action="{{ route('auth.logout') }}" id="logoutForm">
|
|
||||||
<button class="input__button auth__button" name="session" value="{{ session_id() }}">
|
|
||||||
<i class="fa fa-sign-out"></i> Logout
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
|
@ -61,7 +61,7 @@
|
||||||
<a class="header__menu-item fa fa-gavel" href="{{ route('manage.index') }}" title="Manage"></a>
|
<a class="header__menu-item fa fa-gavel" href="{{ route('manage.index') }}" title="Manage"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a class="header__menu-item fa fa-cogs" href="{{ route('settings.index') }}" title="Settings"></a>
|
<a class="header__menu-item fa fa-cogs" href="{{ route('settings.index') }}" title="Settings"></a>
|
||||||
<a class="header__menu-item fa fa-sign-out" href="{{ route('auth.logout') }}" title="Logout"></a>
|
<a class="header__menu-item fa fa-sign-out" href="javascript:yuunoLogout();" title="Logout"></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -91,9 +91,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function yuunoAttemptLogin(form) {
|
function yuunoAttemptLogin(form) {
|
||||||
var ajax = new Sakura.AJAX();
|
var ajax = new Sakura.AJAX;
|
||||||
|
|
||||||
console.log(new FormData(form));
|
|
||||||
|
|
||||||
ajax.SetUrl("{{ route('auth.login') }}");
|
ajax.SetUrl("{{ route('auth.login') }}");
|
||||||
ajax.SetFormData(new FormData(form));
|
ajax.SetFormData(new FormData(form));
|
||||||
|
@ -118,6 +116,50 @@
|
||||||
ajax.Start(Sakura.HTTPMethod.POST);
|
ajax.Start(Sakura.HTTPMethod.POST);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
{% else %}
|
||||||
|
<script>
|
||||||
|
function yuunoLogout() {
|
||||||
|
var confirm = new Sakura.Dialogue;
|
||||||
|
confirm.SetType(Sakura.DialogueType.Confirm);
|
||||||
|
confirm.Text = "Are you sure?";
|
||||||
|
|
||||||
|
confirm.AddCallback(Sakura.DialogueButton.No, function () {
|
||||||
|
this.Close();
|
||||||
|
});
|
||||||
|
|
||||||
|
confirm.AddCallback(Sakura.DialogueButton.Yes, function () {
|
||||||
|
var ajax = new Sakura.AJAX;
|
||||||
|
|
||||||
|
ajax.SetUrl("{{ route('auth.logout') }}");
|
||||||
|
ajax.SetFormData({
|
||||||
|
"sessions": Sakura.Config.SessionId
|
||||||
|
});
|
||||||
|
|
||||||
|
ajax.AddCallback(200, function () {
|
||||||
|
var result = ajax.JSON();
|
||||||
|
confirm.Close();
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
var error = new Sakura.Dialogue;
|
||||||
|
error.Text = result.error;
|
||||||
|
error.SetType(Sakura.DialogueType.Info);
|
||||||
|
|
||||||
|
error.AddCallback(Sakura.DialogueButton.Ok, function () {
|
||||||
|
this.Close();
|
||||||
|
});
|
||||||
|
|
||||||
|
error.Display();
|
||||||
|
} else {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ajax.Start(Sakura.HTTPMethod.POST);
|
||||||
|
});
|
||||||
|
|
||||||
|
confirm.Display();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div id="contentwrapper" class="container__content">
|
<div id="contentwrapper" class="container__content">
|
||||||
|
|
10
routes.php
10
routes.php
|
@ -24,8 +24,8 @@ Router::group(['before' => 'maintenance'], function () {
|
||||||
Router::get('/search', 'MetaController@search', 'main.search');
|
Router::get('/search', 'MetaController@search', 'main.search');
|
||||||
|
|
||||||
// Auth
|
// Auth
|
||||||
Router::get('/login', 'AuthController@login', 'auth.login');
|
|
||||||
Router::post('/login', 'AuthController@login', 'auth.login');
|
Router::post('/login', 'AuthController@login', 'auth.login');
|
||||||
|
Router::post('/logout', 'AuthController@logout', 'auth.logout');
|
||||||
Router::get('/register', 'AuthController@register', 'auth.register');
|
Router::get('/register', 'AuthController@register', 'auth.register');
|
||||||
Router::post('/register', 'AuthController@register', 'auth.register');
|
Router::post('/register', 'AuthController@register', 'auth.register');
|
||||||
Router::get('/resetpassword', 'AuthController@resetPassword', 'auth.resetpassword');
|
Router::get('/resetpassword', 'AuthController@resetPassword', 'auth.resetpassword');
|
||||||
|
@ -33,8 +33,6 @@ Router::group(['before' => 'maintenance'], function () {
|
||||||
Router::get('/reactivate', 'AuthController@reactivate', 'auth.reactivate');
|
Router::get('/reactivate', 'AuthController@reactivate', 'auth.reactivate');
|
||||||
Router::post('/reactivate', 'AuthController@reactivate', 'auth.reactivate');
|
Router::post('/reactivate', 'AuthController@reactivate', 'auth.reactivate');
|
||||||
Router::get('/activate', 'AuthController@activate', 'auth.activate');
|
Router::get('/activate', 'AuthController@activate', 'auth.activate');
|
||||||
Router::get('/logout', 'AuthController@logout', 'auth.logout');
|
|
||||||
Router::post('/logout', 'AuthController@logout', 'auth.logout');
|
|
||||||
|
|
||||||
// Link compatibility layer, prolly remove this in like a year
|
// Link compatibility layer, prolly remove this in like a year
|
||||||
Router::get('/r/{id}', function ($id) {
|
Router::get('/r/{id}', function ($id) {
|
||||||
|
@ -54,12 +52,12 @@ Router::group(['before' => 'maintenance'], function () {
|
||||||
'mcptest' => 'manage.index',
|
'mcptest' => 'manage.index',
|
||||||
//'report' => 'report.something',
|
//'report' => 'report.something',
|
||||||
//'osu' => 'eventual link to flashii team',
|
//'osu' => 'eventual link to flashii team',
|
||||||
'everlastingness' => 'https://i.flash.moe/18661469927746.txt',
|
'everlastingness' => 'https://gist.github.com/fe207557385f0700d719a97b5fab647f',
|
||||||
'fuckingdone' => 'https://i.flash.moe/18671469927761.txt',
|
'fuckingdone' => 'https://gist.github.com/4fac58c40be8a71dbfde50eca149575d',
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!array_key_exists($id, $resolve)) {
|
if (!array_key_exists($id, $resolve)) {
|
||||||
throw new \Phroute\Phroute\Exception\HttpRouteNotFoundException();
|
throw new \Phroute\Phroute\Exception\HttpRouteNotFoundException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$link = $resolve[$id];
|
$link = $resolve[$id];
|
||||||
|
|
Reference in a new issue