Przeglądaj źródła

Better login redirection

Zachary Kotlarek 12 lat temu
rodzic
commit
9201584611
2 zmienionych plików z 16 dodań i 5 usunięć
  1. 8 2
      web/includes/auth.php
  2. 8 3
      web/login.php

+ 8 - 2
web/includes/auth.php

@@ -17,10 +17,16 @@ function login($username, $password) {
 		logout();
 	}
 
-	# Redirect, if we have a target
+	# Redirect, using the provided target if available
+	login_redirect();
+}
+
+function login_redirect() {
+	$url = './';
 	if (isset($_GET['dest'])) {
-		header('Location: ' . $_GET['dest']);
+		$url = $_GET['dest'];
 	}
+	header('Location: ' . $url);
 }
 
 function logout() {

+ 8 - 3
web/login.php

@@ -6,14 +6,19 @@ require_once 'includes/main.php';
 # Send our headers early
 header('Content-type: text/html; charset=utf-8');
 
+# Process logout
+if (isset($_REQUEST['logout'])) {
+	logout();
+}
+
 # Process login
 if (isset($_POST['username']) && isset($_POST['password'])) {
 	login($_POST['username'], $_POST['password']);
 }
 
-# Process logout
-if (isset($_REQUEST['logout'])) {
-	logout();
+# Redirect if we're already authenticated
+if (authenticated()) {
+	login_redirect();
 }
 
 #=========================================================================================