Only open question: The onLogout generate a flash message which would be displayed on the /logout page if there wouldnt be a redirect. How to pass the message to the redirected page or how to add a custom flash message to this redirect page?
Sorry at that point - I did read it but this here is all I could do:
{% set result = ajaxHandler('onLogout') %}
{{ result.flash.success }}
This here stores the result of the handler, but the handler does not logout anymore, so… its kinda usless
{% do ajaxHandler('onLogout') %}
{% do redirect('/') %}
This here works, but the logout mssage is not displayed on the start page.
url = "/logout"
layout = "default"
title = "Logout"
==
function onEnd()
{
Flash::success('You have been successfully logged out!');
return Redirect::to('/');
}
==
{% do ajaxHandler('onLogout') %}
This here works as expected with the logout message on the startpage which you’re redirected to.
I just hoped there’s a combination of all to call the handler, then get the message from the handler somehow and pass this message as flash message to the redirect - the redirect with flash in twig is my problem, not the call of the handler.
The solution from the last post still had bugs. This here is the final solution:
url = "/logout"
layout = "none"
title = "Logout"
==
function onStart()
{
# Not logged in
if(Auth::getUser() === null) {
return Cms::redirect('/login');
}
# Logged in, call logout handler and redirect. Message comes from handler.
else {
$sessionComponent = new RainLab\User\Components\Session;
$sessionComponent->onLogout();
return Cms::redirect('/login/');
}
}
==
So if you call the /logout from anywhere in your website now, there’s a redirect if the user is not logged in and if there’s a user logged in, he’s logged out.
I got a Layout called “none” btw… which is very empty obviously…