User Account Registration (Signup)
This commit is contained in:
parent
73d97f9f1d
commit
cde36783e4
11 changed files with 51 additions and 57 deletions
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
define("ROOT_URL", "https://localhost/blog/");
|
||||
session_start();
|
||||
define("ROOT_URL", "http://localhost/blog/");
|
||||
define('DB_HOST', 'localhost');
|
||||
define('DB_USER', 'underemployed');
|
||||
define('DB_PASS', 'admin1234');
|
||||
|
|
|
@ -24,7 +24,7 @@ include "partials/header.php";
|
|||
<h5>Manage Posts</h5>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<?php if(isset($_SESSION['user_is_admin'])) : ?>
|
||||
<li>
|
||||
<a href="<?= ROOT_URL ?>admin/add-user.php">
|
||||
<i class="uil uil-user-plus"></i>
|
||||
|
@ -50,6 +50,7 @@ include "partials/header.php";
|
|||
<h5>Manage Categories</h5>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
</aside>
|
||||
<main>
|
||||
|
|
|
@ -20,10 +20,11 @@ include "partials/header.php";
|
|||
|
||||
<li>
|
||||
<a href="<?= ROOT_URL ?>admin/index.php">
|
||||
<i class="uil uil-postcard"></i> <h5>Manage Posts</h5>
|
||||
<i class="uil uil-postcard"></i>
|
||||
<h5>Manage Posts</h5>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<?php if(isset($_SESSION['user_is_admin'])) : ?>
|
||||
<li>
|
||||
<a href="<?= ROOT_URL ?>admin/add-user.php">
|
||||
<i class="uil uil-user-plus"></i>
|
||||
|
@ -49,6 +50,7 @@ include "partials/header.php";
|
|||
<h5>Manage Categories</h5>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
</aside>
|
||||
<main>
|
||||
|
|
|
@ -20,10 +20,11 @@ include "partials/header.php";
|
|||
|
||||
<li>
|
||||
<a href="<?= ROOT_URL ?>admin/index.php">
|
||||
<i class="uil uil-postcard"></i> <h5>Manage Posts</h5>
|
||||
<i class="uil uil-postcard"></i>
|
||||
<h5>Manage Posts</h5>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<?php if(isset($_SESSION['user_is_admin'])) : ?>
|
||||
<li>
|
||||
<a href="<?= ROOT_URL ?>admin/add-user.php">
|
||||
<i class="uil uil-user-plus"></i>
|
||||
|
@ -49,6 +50,8 @@ include "partials/header.php";
|
|||
<h5>Manage Categories</h5>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
|
||||
</ul>
|
||||
</aside>
|
||||
<main>
|
||||
|
|
|
@ -1,48 +1,10 @@
|
|||
<?php
|
||||
require 'config/database.php';
|
||||
|
||||
require '../partials/header.php';
|
||||
// check login status
|
||||
if(!isset($_SESSION['user-id'])) {
|
||||
header('location: ' . ROOT_URL . 'signin.php');
|
||||
die();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE HTML>
|
||||
<php lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>php & mysql blog app with admin panel</title>
|
||||
<!-- CUSTOM STYLESHEET -->
|
||||
<link rel="stylesheet" href="<?= ROOT_URL ?>css/style.css">
|
||||
<!-- ICONSCOUT CDN -->
|
||||
<link rel="stylesheet" href="https://unicons.iconscout.com/release/v4.0.0/css/line.css">
|
||||
<!-- GOOGLE FONT(MONTSERATE) -->
|
||||
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,500;0,600;0,800;1,700&display=swap" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav>
|
||||
<div class="container nav__container">
|
||||
<a href="<?= ROOT_URL ?>index.php" class="nav__logo">UNDEREMPLOYED</a>
|
||||
<ul class="nav__items">
|
||||
<li><a href="<?= ROOT_URL ?>blog.php">Blog</a></li>
|
||||
<li><a href="<?= ROOT_URL ?>about.php">About</a></li>
|
||||
<li><a href="<?= ROOT_URL ?>services.php">Services</a></li>
|
||||
<li><a href="<?= ROOT_URL ?>contact.php">Contact</a></li>
|
||||
<li><a href="<?= ROOT_URL ?>signin.php">SignIn</a></li>
|
||||
<li class="nav__profile">
|
||||
<div class="avatar">
|
||||
<img src="./images/avatar1.jpg">
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="<?= ROOT_URL ?>/admin/index.php">Dashboard</a></li>
|
||||
<li><a href="<?= ROOT_URL ?>logout.php">Logout</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<button id="open__nav-btn"><i class="uil uil-bars"></i></button>
|
||||
<button id="close__nav-btn"><i class="uil uil-multiply"></i></button>
|
||||
</div>
|
||||
</nav>
|
||||
<!-- ======================== END OF NAV ======================== -->
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
define("ROOT_URL", "https://localhost/blog/");
|
||||
session_start();
|
||||
define("ROOT_URL", "http://localhost/blog/");
|
||||
define('DB_HOST', 'localhost');
|
||||
define('DB_USER', 'underemployed');
|
||||
define('DB_PASS', 'admin1234');
|
||||
|
|
8
logout.php
Normal file
8
logout.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
require 'config/constants.php';
|
||||
//destroy all sessions and redirect user to login page
|
||||
session_destroy();
|
||||
|
||||
header('location: ' . ROOT_URL);
|
||||
die;
|
||||
?>
|
|
@ -1,6 +1,12 @@
|
|||
<?php
|
||||
require 'config/database.php';
|
||||
|
||||
if(isset($_SESSION['user-id'])) {
|
||||
$id = filter_var($_SESSION['user-id'], FILTER_SANITIZE_NUMBER_INT);
|
||||
$query = "SELECT avatar FROM users WHERE id='$id'";
|
||||
$result = mysqli_query($connection, $query);
|
||||
$avatar = mysqli_fetch_assoc($result);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
@ -28,16 +34,20 @@ require 'config/database.php';
|
|||
<li><a href="<?= ROOT_URL ?>about.php">About</a></li>
|
||||
<li><a href="<?= ROOT_URL ?>services.php">Services</a></li>
|
||||
<li><a href="<?= ROOT_URL ?>contact.php">Contact</a></li>
|
||||
<li><a href="<?= ROOT_URL ?>signin.php">SignIn</a></li>
|
||||
<!--<li class="nav__profile">
|
||||
<?php if(isset($_SESSION['user-id'])) : ?>
|
||||
|
||||
<li class="nav__profile">
|
||||
<div class="avatar">
|
||||
<img src="./images/avatar1.jpg">
|
||||
<img src="<?= ROOT_URL . 'images/' . $avatar['avatar'] ?>">
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="<?= ROOT_URL ?>/admin/index.php">Dashboard</a></li>
|
||||
<li><a href="<?= ROOT_URL ?>logout.php">Logout</a></li>
|
||||
</ul>
|
||||
</li>-->
|
||||
</li>
|
||||
<?php else : ?>
|
||||
<li><a href="<?= ROOT_URL ?>signin.php">SignIn</a></li>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
|
||||
<button id="open__nav-btn"><i class="uil uil-bars"></i></button>
|
||||
|
|
|
@ -4,17 +4,22 @@ require "config/database.php";
|
|||
session_start();
|
||||
|
||||
if(isset($_POST['submit'])){
|
||||
// getting input
|
||||
$username_email = filter_var($_POST['username_email'] , FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$password = filter_var(($_POST['password']), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
|
||||
if(!$username_email){
|
||||
$_SESSION['signin'] = 'Username or Email is Inccorrect';
|
||||
|
||||
}
|
||||
elseif(!$password){
|
||||
$_SESSION['signin'] = 'Password required';
|
||||
|
||||
}else{
|
||||
// fetch user from database
|
||||
$fetch_user_query = "SELECT * FROM users WHERE username = '$username_email' OR email = '$username_email'";
|
||||
$fetch_user_result = mysqli_query($connection, $fetch_user_query);
|
||||
|
||||
if(mysqli_num_rows($fetch_user_result) == 1){
|
||||
//convert the record into assoc array
|
||||
$user_record=mysqli_fetch_assoc($fetch_user_result);
|
||||
|
@ -22,12 +27,14 @@ if(isset($_POST['submit'])){
|
|||
|
||||
// compare form password with database password
|
||||
if(password_verify($password,$db_password)){
|
||||
|
||||
// set session for access control
|
||||
$_SESSION['user-id'] = $user_record['id'];
|
||||
|
||||
//set session if user is admin
|
||||
if($user_record['is_admin']==1){
|
||||
$_SESSION['user_is_admin'] == true;
|
||||
|
||||
}
|
||||
//log in user
|
||||
header('location: ' . ROOT_URL . 'admin/');
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
session_start();
|
||||
include 'config/constants.php';
|
||||
|
||||
$username_email = $_SESSION['signin-data']['username_email'] ??null ;
|
||||
|
|
|
@ -45,7 +45,7 @@ if(isset($_POST["submit"])){
|
|||
$time = time(); // make each image name unique using current timestamp
|
||||
$avatar_name = $time . $avatar['name'];
|
||||
$avatar_tmp_name=$avatar['tmp_name'];
|
||||
$avatar_destination_path='images/ ' . $avatar_name;
|
||||
$avatar_destination_path='images/' . $avatar_name;
|
||||
|
||||
//,ake sure file is an image
|
||||
$allowed_files = ['png', 'jpg', 'jpeg'];
|
||||
|
|
Loading…
Reference in a new issue