Skip to content
Snippets Groups Projects
Commit 2eb5b67d authored by Sibidharan's avatar Sibidharan :speech_balloon:
Browse files

assignments point 30th aug

parent f739a033
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,11 @@
<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>
<?if(Session::isAuthenticated()){?>
<li><a href="/?logout" class="text-white">Logout</a></li>
<?} else {?>
<li><a href="/login.php" class="text-white">Login</a></li>
<?}?>
</ul>
</div>
</div>
......@@ -30,7 +34,7 @@
<path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z" />
<circle cx="12" cy="13" r="4" />
</svg>
<strong>Album</strong>
<strong>Photogram</strong>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarHeader"
aria-controls="navbarHeader" aria-expanded="false" aria-label="Toggle navigation">
......
<section class="py-5 text-center container">
<div class="row py-lg-5">
<div class="col-lg-6 col-md-8 mx-auto">
<h1 class="fw-light">What are you upto?</h1>
<h1 class="fw-light">What are you upto, <?=Session::getUser()->getUsername()?>?</h1>
<p class="lead text-muted">Share a photo that talks about it.</p>
<p>
<a href="#" class="btn btn-primary my-2">Upload</a>
......
......@@ -4,8 +4,8 @@
<h1 class="fw-light">Join us to share memories.</h1>
<p class="lead text-muted">We remember even when you forget.</p>
<p>
<a href="#" class="btn btn-success my-2">Login</a>
<a href="#" class="btn btn-secondary my-2">Register</a>
<a href="/login.php" class="btn btn-success my-2">Login</a>
<a href="/signup.php" class="btn btn-secondary my-2">Register</a>
</p>
</div>
</div>
......
<?php
$login = true;
Session::set('mode', 'web');
Session::set('test', 'websdkjfnsdkjfn');
//TODO: Redirect to a requested URL instead of base path on login
if (isset($_POST['email_address']) and isset($_POST['password'])) {
$email_address = $_POST['email_address'];
$password = $_POST['password'];
......
<?
if(Session::isAuthenticated()){
print("Yes");
} else {
print("No");
}
\ No newline at end of file
......@@ -2,6 +2,19 @@
include 'libs/load.php';
if (isset($_GET['logout'])) {
if (Session::isset("session_token")) {
$Session = new UserSession(Session::get("session_token"));
if ($Session->removeSession()) {
echo "<h3> Pervious Session is removing from db </h3>";
} else {
echo "<h3>Pervious Session not removing from db </h3>";
}
}
Session::destroy();
header("Location: /");
die();
} else {
Session::renderPage();
}
// Session::renderPage();
Session::renderPage();
......@@ -28,7 +28,7 @@ class Database
return Database::$conn;
}
} else {
printf("Returning existing establishing...");
// printf("Returning existing establishing...");
return Database::$conn;
}
}
......
<?php
use MongoDB\Driver\Session as DriverSession;
class Session
{
public static $isError = false;
public static $user = null;
public static $usersession = null;
public static function start()
{
session_start();
......@@ -44,6 +48,16 @@ class Session
}
}
public static function getUser()
{
return Session::$user;
}
public static function getUserSession(){
return Session::$usersession;
}
public static function loadTemplate($name)
{
$script = $_SERVER['DOCUMENT_ROOT'] . get_config('base_path'). "_templates/$name.php";
......@@ -66,6 +80,17 @@ class Session
public static function isAuthenticated()
{
//TODO: Is it a correct implementation?
if(is_object(Session::getUserSession())){
return Session::getUserSession()->isValid();
}
return false;
}
public static function ensureLogin(){
if(!Session::isAuthenticated()){
header("Location: /login.php");
die();
}
}
}
......@@ -86,7 +86,7 @@ class User
if (!$this->conn) {
$this->conn = Database::getConnection();
}
$sql = "SELECT `$var` FROM `users` WHERE `id` = $this->id";
$sql = "SELECT `$var` FROM `auth` WHERE `id` = $this->id";
//print($sql);
$result = $this->conn->query($sql);
if ($result and $result->num_rows == 1) {
......@@ -103,7 +103,7 @@ class User
if (!$this->conn) {
$this->conn = Database::getConnection();
}
$sql = "UPDATE `users` SET `$var`='$data' WHERE `id`=$this->id;";
$sql = "UPDATE `auth` SET `$var`='$data' WHERE `id`=$this->id;";
if ($this->conn->query($sql)) {
return true;
} else {
......@@ -120,10 +120,10 @@ class User
}
}
public function getUsername()
{
return $this->username;
}
// public function getUsername()
// {
// return $this->username;
// }
public function authenticate()
{
......
......@@ -49,7 +49,8 @@ class UserSession
if ($_SERVER['REMOTE_ADDR'] == $session->getIP()) {
if ($_SERVER['HTTP_USER_AGENT'] == $session->getUserAgent()) {
if ($session->getFingerprint() == $_SESSION['fingerprint']) {
return true;
Session::$user = $session->getUser();
return $session;
} else {
throw new Exception("FingerPrint doesn't match");
}
......@@ -67,7 +68,7 @@ class UserSession
throw new Exception("IP and User_agent is null");
}
} catch (Exception $e) {
return false;
throw new Exception("Something is wrong");
}
}
......
......@@ -24,7 +24,14 @@ class WebAPI
public function initiateSession()
{
Session::start();
if (Session::isset("session_token")) {
try {
Session::$usersession = UserSession::authorize(Session::get('session_token'));
}
catch (Exception $e){
//TODO: Handle error
}
}
// $__base_path = get_config('base_path');
}
}
<?php
include 'libs/load.php';
// echo "Hello world";
if(Session::isAuthenticated()){
header("Location: /");
die();
}
Session::renderPage();
......@@ -2,4 +2,9 @@
include 'libs/load.php';
if(Session::isAuthenticated()){
header("Location: /");
die();
}
Session::renderPage();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment