Преглед на файлове

Move logout to a routing callback

ohartl преди 9 години
родител
ревизия
1f736a9746
променени са 3 файла, в които са добавени 16 реда и са изтрити 6 реда
  1. 11 0
      include/php/classes/Auth.php
  2. 0 5
      include/php/pages/logout.php
  3. 5 1
      include/php/routes.inc.php

+ 11 - 0
include/php/classes/Auth.php

@@ -116,6 +116,17 @@ class Auth
 	}
 
 
+	/**
+	 * @return void
+	 */
+	public static function logout()
+	{
+		unset($_SESSION[static::SESSION_IDENTIFIER]);
+
+		session_destroy();
+	}
+
+
 	/**
 	 * Check if current user has a certain role, but User::ROLE_ADMIN will have access to all
 	 *

+ 0 - 5
include/php/pages/logout.php

@@ -1,5 +0,0 @@
-<?php
-require_once 'include/php/default.inc.php';
-
-session_destroy();
-redirect('/');

+ 5 - 1
include/php/routes.inc.php

@@ -7,7 +7,11 @@ Router::addGet('/', 'include/php/pages/start.php');
  * Auth
  */
 Router::addMixed('/login', 'include/php/pages/login.php');
-Router::addGet('/logout', 'include/php/pages/logout.php');
+Router::addGet('/logout', function(){
+	Auth::logout();
+	redirect('/');
+	return;
+});
 
 /**
  * Private area