Skip to content
Snippets Groups Projects
Commit 032f4987 authored by GopiKrishnan's avatar GopiKrishnan :speech_balloon:
Browse files

Merge branch 'gopi' into 'master'

updated User.class.php

See merge request GopiKrishnan/photogram!1
parents 1c6c1a82 6a113036
No related branches found
No related tags found
No related merge requests found
......@@ -7,12 +7,10 @@
<title>Login to Photogram</title>
<!-- Bootstrap core CSS -->
<link href="/app/assets/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="/photogram/assets/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Photogram by LAHTP</title>
<?if (file_exists($_SERVER['DOCUMENT_ROOT'].'/app/css/'.basename($_SERVER['PHP_SELF'], ".php").".css")) {?>
<link
href="/app/css/<?=basename($_SERVER['PHP_SELF'], ".php")?>.css"
rel="stylesheet">
<?}?>
<? if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/photogram/css/' . basename($_SERVER['PHP_SELF'], ".php") . ".css")) { ?>
<link href="/photogram/css/<?= basename($_SERVER['PHP_SELF'], ".php") ?>.css" rel="stylesheet">
<? } ?>
</head>
\ No newline at end of file
......@@ -12,56 +12,52 @@ if (isset($_POST['username']) and isset($_POST['password']) and !empty($_POST['p
?>
<?php
if ($signup) {
if (!$error) {
?>
<main class="container">
<div class="bg-light p-5 rounded mt-3">
<h1>Signup Success</h1>
<p class="lead">Now you can login from <a href="/login.php">here</a>.</p>
if ($signup) {
if (!$error) {
?>
<main class="container">
<div class="bg-light p-5 rounded mt-3">
<h1>Signup Success</h1>
<p class="lead">Now you can login from <a href="/photogram/login.php">here</a>.</p>
</div>
</main>
<?php
} else {
?>
<main class="container">
<div class="bg-light p-5 rounded mt-3">
<h1>Signup Fail</h1>
<p class="lead">Something went wrong, <?=$error?>
</p>
</div>
</main>
<?php
}
</div>
</main>
<?php
} else {
?>
<main class="form-signup">
<form method="post" action="signup.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">Signup here</h1>
<div class="form-floating">
<input name="username" type="text" class="form-control" id="floatingInputUsername"
placeholder="name@example.com">
<label for="floatingInputUsername">Username</label>
</div>
<div class="form-floating">
<input name="phone" type="text" class="form-control" id="floatingInputUsername"
placeholder="name@example.com">
<label for="floatingInputUsername">Phone</label>
</div>
<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>
<button class="w-100 btn btn-lg btn-primary hvr-grow-rotate" type="submit">Sign up</button>
</form>
</main>
<?php
?>
<main class="container">
<div class="bg-light p-5 rounded mt-3">
<h1>Signup Fail</h1>
<p class="lead">Something went wrong, <?= $error ?>
</p>
</div>
</main>
<?php
}
} else {
?>
<main class="form-signup">
<form method="post" action="signup.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">Signup here</h1>
<div class="form-floating">
<input name="username" type="text" class="form-control" id="floatingInputUsername" placeholder="name@example.com">
<label for="floatingInputUsername">Username</label>
</div>
<div class="form-floating">
<input name="phone" type="text" class="form-control" id="floatingInputUsername" placeholder="name@example.com">
<label for="floatingInputUsername">Phone</label>
</div>
<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>
<button class="w-100 btn btn-lg btn-primary hvr-grow-rotate" type="submit">Sign up</button>
</form>
</main>
<?php
}
......@@ -6,20 +6,20 @@ include 'libs/load.php';
<!doctype html>
<html lang="en">
<?load_template('_head');?>
<? load_template('_head'); ?>
<body>
<?load_template('_header');?>
<? load_template('_header'); ?>
<main>
<?load_template('_calltoaction');?>
<? load_template('_calltoaction'); ?>
<?load_template('_photogram');?>
<? load_template('_photogram'); ?>
</main>
<?load_template('_footer');?>
<script src="/app/assets/dist/js/bootstrap.bundle.min.js"></script>
<? load_template('_footer'); ?>
<script src="/photogram/assets/dist/js/bootstrap.bundle.min.js"></script>
</body>
......
......@@ -7,10 +7,10 @@ class Database
{
if (Database::$conn == null) {
$servername = "mysql.selfmade.ninja";
$username = "sibidharan";
$password = "gifSaw-nycdag-6kifwa";
$dbname = "sibidharan_newdb";
$username = "gopikrish";
$password = "krishnan";
$dbname = "gopikrish_photogram";
// Create connection
$connection = new mysqli($servername, $username, $password, $dbname);
// Check connection
......
<?php
require_once "Database.class.php";
class User
{
private $conn;
......@@ -19,7 +21,7 @@ class User
// echo "Error: " . $sql . "<br>" . $conn->error;
$error = $conn->error;
}
// $conn->close();
return $error;
}
......@@ -44,12 +46,41 @@ class User
public function __construct($username)
{
//TODO: Write the code to fetch user data from Database for the given username. If username is not present, throw Exception.
$this->conn = Database::getConnection();
$this->conn->query();
$this->username = $username;
$sql = "SELECT `id` FROM `auth` WHERE `username`= '$username' LIMIT 1";
$result = $this->conn->query($sql);
if ($result->num_rows) {
$row = $result->fetch_assoc();
$this->id = $row['id']; //Updating this from database
} else throw new Exception("Username does't exist");
}
//TODO: Write the code to fetch user data from Database for the given username. If username is not present, throw Exception.
$this->id = null; //Update this from database.
//this function helps to retrieve data from the database
private function getData($var)
{
if (!$this->conn) {
$this->conn = Database::getConnection();
}
$sql = "SELECT `$var` FROM `users` WHERE `id` = '$this->id'";
$result = $this->conn->query($sql);
if ($result->num_rows) {
return $result->fetch_assoc()["$var"];
} else return null;
}
//This function helps to set the data in the database
private function setData($var, $data)
{
if (!$this->conn) {
$this->conn = Database::getConnection();
}
$sql = "UPDATE `users` SET `$var`='$data' WHERE `id`='$this->id';";
if ($this->conn->query($sql)) {
return true;
} else return false;
}
public function authenticate()
......@@ -59,18 +90,83 @@ class User
public function setBio($bio)
{
//TODO: Write UPDATE command to change new bio
return $this->setData('bio', $bio);
}
public function getBio()
{
//TODO: Write SELECT command to get the bio.
return $this->getData('bio');
}
public function setAvatar($link)
{
return $this->setData('avatar', $link);
}
public function getAvatar()
{
return $this->getData('avatar');
}
public function setFirstname($name)
{
return $this->setData("firstname", $name);
}
public function getFirstname()
{
return $this->getData('firstname');
}
public function setLastname($name)
{
return $this->setData("lastname", $name);
}
public function getLastname()
{
return $this->getData('lastname');
}
public function setDob($year, $month, $day)
{
if (checkdate($month, $day, $year)) { //checking data is valid
return $this->setData('dob', "$year.$month.$day");
} else return false;
}
public function getDob()
{
return $this->getData('dob');
}
public function setInstagramlink($link)
{
return $this->setData('instagram', $link);
}
public function getInstagramlink()
{
return $this->getData('instagram');
}
public function setTwitterlink($link)
{
return $this->setData('twitter', $link);
}
public function getTwitterlink()
{
return $this->getData('twitter');
}
public function setFacebooklink($link)
{
return $this->setData('facebook', $link);
}
public function getFacebooklink()
{
return $this->getData('facebook');
}
}
<?php
include "User.class.php";
$obj = new User('gopi');
echo $obj->getInstagramlink();
......@@ -8,7 +8,7 @@ Session::start();
function load_template($name)
{
include $_SERVER['DOCUMENT_ROOT']."/app/_templates/$name.php"; //not consistant.
include $_SERVER['DOCUMENT_ROOT'] . "/photogram/_templates/$name.php"; //not consistant.
}
function validate_credentials($username, $password)
......
......@@ -6,18 +6,18 @@ include 'libs/load.php';
<!doctype html>
<html lang="en">
<?load_template('_head');?>
<? load_template('_head'); ?>
<body>
<?load_template('_header');?>
<? load_template('_header'); ?>
<main>
<?load_template('_login');?>
<? load_template('_login'); ?>
</main>
<?load_template('_footer');?>
<script src="/app/assets/dist/js/bootstrap.bundle.min.js"></script>
<? load_template('_footer'); ?>
<script src="/photogram/assets/dist/js/bootstrap.bundle.min.js"></script>
</body>
......
......@@ -6,18 +6,18 @@ include 'libs/load.php';
<!doctype html>
<html lang="en">
<?load_template('_head');?>
<? load_template('_head'); ?>
<body>
<?load_template('_header');?>
<? load_template('_header'); ?>
<main>
<?load_template('_signup');?>
<? load_template('_signup'); ?>
</main>
<?load_template('_footer');?>
<script src="/app/assets/dist/js/bootstrap.bundle.min.js"></script>
<? load_template('_footer'); ?>
<script src="/photogram/assets/dist/js/bootstrap.bundle.min.js"></script>
</body>
......
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