made logout dynamic

This commit is contained in:
Pachira 2016-12-08 19:45:20 +01:00
parent dc0fc54aad
commit e38a40e5fe
5 changed files with 53 additions and 29 deletions

View file

@ -43,13 +43,13 @@ class AuthController extends Controller
public function logout(): string
{
if (!session_check()) {
return view('auth/logout');
return $this->json(['error' => 'Logout failed.']);
}
// Destroy the active session
CurrentSession::stop();
return redirect(route('main.index'));
return $this->json(['error' => null]);
}
/**

View file

@ -25,7 +25,7 @@
<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-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>
{% if user.isActive %}
<a class="header__user" href="{{ route('user.profile', user.id) }}" style="color: {{ user.colour }}">

View file

@ -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 %}

View file

@ -61,7 +61,7 @@
<a class="header__menu-item fa fa-gavel" href="{{ route('manage.index') }}" title="Manage"></a>
{% endif %}
<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 %}
</div>
</div>
@ -91,9 +91,7 @@
<script>
function yuunoAttemptLogin(form) {
var ajax = new Sakura.AJAX();
console.log(new FormData(form));
var ajax = new Sakura.AJAX;
ajax.SetUrl("{{ route('auth.login') }}");
ajax.SetFormData(new FormData(form));
@ -118,6 +116,50 @@
ajax.Start(Sakura.HTTPMethod.POST);
}
</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 %}
<div id="contentwrapper" class="container__content">

View file

@ -24,8 +24,8 @@ Router::group(['before' => 'maintenance'], function () {
Router::get('/search', 'MetaController@search', 'main.search');
// Auth
Router::get('/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::post('/register', 'AuthController@register', 'auth.register');
Router::get('/resetpassword', 'AuthController@resetPassword', 'auth.resetpassword');
@ -33,8 +33,6 @@ Router::group(['before' => 'maintenance'], function () {
Router::get('/reactivate', 'AuthController@reactivate', 'auth.reactivate');
Router::post('/reactivate', 'AuthController@reactivate', 'auth.reactivate');
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
Router::get('/r/{id}', function ($id) {
@ -54,12 +52,12 @@ Router::group(['before' => 'maintenance'], function () {
'mcptest' => 'manage.index',
//'report' => 'report.something',
//'osu' => 'eventual link to flashii team',
'everlastingness' => 'https://i.flash.moe/18661469927746.txt',
'fuckingdone' => 'https://i.flash.moe/18671469927761.txt',
'everlastingness' => 'https://gist.github.com/fe207557385f0700d719a97b5fab647f',
'fuckingdone' => 'https://gist.github.com/4fac58c40be8a71dbfde50eca149575d',
];
if (!array_key_exists($id, $resolve)) {
throw new \Phroute\Phroute\Exception\HttpRouteNotFoundException();
throw new \Phroute\Phroute\Exception\HttpRouteNotFoundException;
}
$link = $resolve[$id];