From bf26f87a4a39505e8aef2b4242bbf29b1ba5ea48 Mon Sep 17 00:00:00 2001
From: Sibidharan <sibidharan@icloud.com>
Date: Tue, 11 Jan 2022 15:55:53 +0000
Subject: [PATCH] login implementation basic

---
 _templates/_login.php | 48 +++++++++++++++++++++
 cache.php             | 18 ++++++++
 index.php             |  2 -
 libs/load.php         |  9 ++++
 login.php             | 99 +++++++++++++++++++++++++++++++++++++++++++
 test.php              |  6 +--
 6 files changed, 177 insertions(+), 5 deletions(-)
 create mode 100644 _templates/_login.php
 create mode 100644 cache.php
 create mode 100644 login.php

diff --git a/_templates/_login.php b/_templates/_login.php
new file mode 100644
index 00000000..4f3fc2ce
--- /dev/null
+++ b/_templates/_login.php
@@ -0,0 +1,48 @@
+<?php
+
+$username = $_POST['email_address'];
+$password = $_POST['password'];
+
+$result = validate_credentials($username, $password);
+
+if ($result) {
+    ?>
+<main class="container">
+    <div class="bg-light p-5 rounded mt-3">
+        <h1>Login Success</h1>
+        <p class="lead">This example is a quick exercise to do basic login with html forms.</p>
+    </div>
+</main>
+<?php
+} else {
+        ?>
+
+
+
+<main class="form-signin">
+    <form method="post" action="login.php">
+        <img class="mb-4" src="https://git.selfmade.ninja/uploads/-/system/appearance/logo/1/Logo_Dark.png" alt=""
+            height="50">
+        <h1 class="h3 mb-3 fw-normal">Please sign in</h1>
+
+        <div class="form-floating">
+            <input name="email_address" type="email" class="form-control" id="floatingInput"
+                placeholder="name@example.com">
+            <label for="floatingInput">Email address</label>
+        </div>
+        <div class="form-floating">
+            <input name="password" type="password" class="form-control" id="floatingPassword" placeholder="Password">
+            <label for="floatingPassword">Password</label>
+        </div>
+
+        <div class="checkbox mb-3">
+            <label>
+                <input type="checkbox" value="remember-me"> Remember me
+            </label>
+        </div>
+        <button class="w-100 btn btn-lg btn-primary hvr-grow-rotate" type="submit">Sign in</button>
+    </form>
+</main>
+
+<?php
+    }
diff --git a/cache.php b/cache.php
new file mode 100644
index 00000000..321c78e1
--- /dev/null
+++ b/cache.php
@@ -0,0 +1,18 @@
+<pre>
+<?php
+error_reporting(E_ALL & ~E_NOTICE);
+
+$mc = new Memcached();
+$mc->addServer("memcached.selfmade.ninja", 11211);
+
+// $mc->set("foo", "Hello!");
+// $mc->set("bar", "Memcached...342");
+
+$arr = array(
+    $mc->get("foo"),
+    $mc->get("bar")
+);
+var_dump($arr);
+
+var_dump($mc->getAllKeys());
+?> </pre>
\ No newline at end of file
diff --git a/index.php b/index.php
index 6a58c3a6..38077b2f 100644
--- a/index.php
+++ b/index.php
@@ -15,8 +15,6 @@ include 'libs/load.php';
     <meta name="generator" content="Hugo 0.88.1">
     <title>Photogram by LAHTP</title>
 
-    <link rel="canonical" href="https://getbootstrap.com/docs/5.1/examples/album/">
-
     <!-- Bootstrap core CSS -->
     <link href="/app/assets/dist/css/bootstrap.min.css" rel="stylesheet">
     <style>
diff --git a/libs/load.php b/libs/load.php
index 4bb3047c..2546d202 100644
--- a/libs/load.php
+++ b/libs/load.php
@@ -4,3 +4,12 @@ function load_template($name)
 {
     include $_SERVER['DOCUMENT_ROOT']."/app/_templates/$name.php"; //not consistant.
 }
+
+function validate_credentials($username, $password)
+{
+    if ($username == "sibi@selfmade.ninja" and $password == "password") {
+        return true;
+    } else {
+        return false;
+    }
+}
diff --git a/login.php b/login.php
new file mode 100644
index 00000000..eca0f6cd
--- /dev/null
+++ b/login.php
@@ -0,0 +1,99 @@
+<?php
+
+include 'libs/load.php';
+
+?>
+
+<!doctype html>
+<html lang="en">
+
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <meta name="description" content="">
+    <meta name="author" content="Selfmade Ninja Academy">
+    <meta name="generator" content="Hugo 0.88.1">
+    <title>Login to Photogram</title>
+
+    <!-- Bootstrap core CSS -->
+    <link href="/app/assets/dist/css/bootstrap.min.css" rel="stylesheet">
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/hover.css/2.1.0/css/hover-min.css"
+        integrity="sha512-glciccPoOqr5mfDGmlJ3bpbvomZmFK+5dRARpt62nZnlKwaYZSfFpFIgUoD8ujqBw4TmPa/F3TX28OctJzoLfg=="
+        crossorigin="anonymous" referrerpolicy="no-referrer" />
+    <style>
+        .bd-placeholder-img {
+            font-size: 1.125rem;
+            text-anchor: middle;
+            -webkit-user-select: none;
+            -moz-user-select: none;
+            user-select: none;
+        }
+
+        .form-signin {
+            width: 100%;
+            max-width: 330px;
+            padding: 15px;
+            margin: auto;
+        }
+
+        .form-signin .checkbox {
+            font-weight: 400;
+        }
+
+        .form-signin .form-floating:focus-within {
+            z-index: 2;
+        }
+
+        .form-signin input[type="email"] {
+            margin-bottom: -1px;
+            border-bottom-right-radius: 0;
+            border-bottom-left-radius: 0;
+        }
+
+        .form-signin input[type="password"] {
+            margin-bottom: 10px;
+            border-top-left-radius: 0;
+            border-top-right-radius: 0;
+        }
+    </style>
+</head>
+
+<body>
+
+    <header>
+        <div class="collapse bg-dark" id="navbarHeader">
+            <div class="container">
+                <div class="row">
+                    <div class="col-sm-8 col-md-7 py-4">
+                        <h4 class="text-white">About</h4>
+                        <p class="text-muted">Add some information about the album below, the author, or any other
+                            background
+                            context. Make it a few sentences long so folks can pick up some informative tidbits. Then,
+                            link them off
+                            to some social networking sites or contact information.</p>
+                    </div>
+                    <div class="col-sm-4 offset-md-1 py-4">
+                        <h4 class="text-white">Contact</h4>
+                        <ul class="list-unstyled">
+                            <li><a href="#" class="text-white">Follow on Twitter</a></li>
+                            <li><a href="#" class="text-white">Like on Facebook</a></li>
+                            <li><a href="#" class="text-white">Email me</a></li>
+                        </ul>
+                    </div>
+                </div>
+            </div>
+        </div>
+        <?load_template('_header');?>
+    </header>
+    <main>
+
+        <?load_template('_login');?>
+
+    </main>
+    <?load_template('_footer');?>
+    <script src="/app/assets/dist/js/bootstrap.bundle.min.js"></script>
+
+
+</body>
+
+</html>
\ No newline at end of file
diff --git a/test.php b/test.php
index d51f5b36..2506f469 100644
--- a/test.php
+++ b/test.php
@@ -1,8 +1,8 @@
 <pre>
 <?php
-$cookie_name = "testscript";
-$cookie_value = $_SERVER['REQUEST_URI'];
-setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
+// $cookie_name = "testscript";
+// $cookie_value = $_SERVER['REQUEST_URI'];
+// setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
 print("_SERVER \n");
 print_r($_SERVER);
 print("_GET \n");
-- 
GitLab