2

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?

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
Simon East
  • 55,742
  • 17
  • 139
  • 133

2 Answers2

3

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'));
}
Simon East
  • 55,742
  • 17
  • 139
  • 133
2

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'));
}
Mnkras
  • 300
  • 1
  • 7