<?php
namespace Misuzu;

use Misuzu\Users\User;
use Misuzu\Users\UserSession;

if(!UserSession::hasCurrent()) {
    url_redirect('index');
    return;
}

if(CSRF::validateRequest()) {
    AuthToken::nukeCookie();
    UserSession::getCurrent()->delete();
    UserSession::unsetCurrent();
    User::unsetCurrent();
    url_redirect('index');
    return;
}

Template::render('auth.logout');
