Generate a "Logout" link in Concrete 5.7

696 Views Asked by At

I want to create a Logout link in my Concrete 5.7 theme.

What function do I call to generate that URL, seeing as it contains special security tokens?

2

There are 2 best solutions below

1
On BEST ANSWER

This function should generate a logout URL:

URL::to('/login', 'logout', \Core::make('helper/validation/token')->generate('logout'));

If you only want to show it when the user is actually logged in, you can combine it with this if statement:

if (!(new User())->isLoggedIn()) {
    $url = URL::to('/login');
} else {
    $url = URL::to('/login', 'logout', 
                   \Core::make('helper/validation/token')->generate('logout'));
}
0
On

In 5.7+ you should no longer use Loader, it should all use Core::make() so we can take the code from @simon-east and change it like so:

if (!(new User())->isLoggedIn()) {
    $url = URL::to('/login');
} else {
    $url = URL::to('/login', 'logout', \Core::make('helper/validation/token')->generate('logout'));
}