Add mechanism to check user logged in status.
authorSam White <webmaster@ycra.org.uk>
Wed, 10 Nov 2021 21:01:55 +0000 (21:01 +0000)
committerSam White <webmaster@ycra.org.uk>
Wed, 10 Nov 2021 21:01:55 +0000 (21:01 +0000)
public_html/includes/auth.php [new file with mode: 0644]
public_html/includes/template.php
public_html/login.php

diff --git a/public_html/includes/auth.php b/public_html/includes/auth.php
new file mode 100644 (file)
index 0000000..3b1608e
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+function check_logged_in() {
+  return !empty($_SESSION['user']);
+}
+
+?>
index 38ab376e0491adb46d02d6cf36880ef574820909..2371f75b1f833244851198adf919d9c4d35a021e 100644 (file)
@@ -2,6 +2,8 @@
 require_once('includes/utils.php');
 require_once('includes/html-templating.php');
 require_once('includes/navbar.php');
+
+if (function_exists('pre_html')) pre_html();
 ?>
 <!DOCTYPE html>
 <html>
index 022ddebf5c1bfe433dbdffdaaba401aa7c655264..36c1b393ad2ab05b04145792e5bd1385f229c0f4 100644 (file)
@@ -24,6 +24,10 @@ function validate_login(&$errors, $data) {
   return empty($errors) ? $record['id'] : false;
 }
 
+function pre_html() {
+  session_start();
+}
+
 function page_title() {
   return 'Login';
 }
@@ -38,7 +42,8 @@ function content() {
     $uid = validate_login($errors, $_POST);
     if ($uid) {
       esc('Login successful!.');
-      die();
+      $_SESSION['user'] = $uid;
+      return;
     }
     $params['email_address'] = $_POST['email_address'];
   }?>