User Account Registration (Signup)

This commit is contained in:
Underemployed 2023-01-03 13:11:23 +06:30
parent 8b9c99c7b4
commit 564166bb0a
14 changed files with 168 additions and 29 deletions

View file

@ -1,2 +1,6 @@
<?php
define("ROOT_URL", "https://localhost/blog/");
define("ROOT_URL", "https://localhost/blog/");
define('DB_HOST', 'localhost');
define('DB_USER', 'underemployed');
define('DB_PASS', 'admin1234');
define('DB_NAME', 'blog');

View file

@ -1,2 +1,8 @@
<?php
require "constants.php";
require "constants.php";
$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(mysqli_errno($connection)){
die(mysqli_error($connection));
}

View file

@ -20,7 +20,7 @@ include "partials/header.php";
<li>
<a href="<?= ROOT_URL ?>admin/index.php" class="active" >
<i class="uil uil-pen"></i>
<i class="uil uil-postcard"></i>
<h5>Manage Posts</h5>
</a>
</li>
@ -70,7 +70,7 @@ include "partials/header.php";
</tr>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore, corrupti!</td>
<td><a href="<?= ROOT_URL ?>admin/edit-posts.php" class="btn sm">Edit</a></td>
<td><a href="<?= ROOT_URL ?>admin/edit-post.php" class="btn sm">Edit</a></td>
<td><a href="<?= ROOT_URL ?>admin/delete-category.php" class="btn sm danger">Delete</a></td>
</tr>
<tr>

View file

@ -20,8 +20,7 @@ include "partials/header.php";
<li>
<a href="<?= ROOT_URL ?>admin/index.php">
<i class="uil uil-pen"></i>
<h5>Manage Posts</h5>
<i class="uil uil-postcard"></i> <h5>Manage Posts</h5>
</a>
</li>

View file

@ -20,8 +20,7 @@ include "partials/header.php";
<li>
<a href="<?= ROOT_URL ?>admin/index.php">
<i class="uil uil-pen"></i>
<h5>Manage Posts</h5>
<i class="uil uil-postcard"></i> <h5>Manage Posts</h5>
</a>
</li>

View file

@ -1,5 +1,5 @@
<?php
require '../config/database.php';
require 'config/database.php';
?>

View file

@ -1,2 +1,7 @@
<?php
define("ROOT_URL", "https://localhost/blog/");
define("ROOT_URL", "https://localhost/blog/");
define('DB_HOST', 'localhost');
define('DB_USER', 'underemployed');
define('DB_PASS', 'admin1234');
define('DB_NAME', 'blog');

View file

@ -1,2 +1,8 @@
<?php
require 'constants.php';
require 'constants.php';
$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(mysqli_errno($connection)){
die(mysqli_error($connection));
}

View file

@ -466,7 +466,7 @@ GENERAL FORM
==============================================================================*/
.form__section{
margin: 6rem 0 6rem;
margin: 4rem 0 4rem;
display: grid;
place-items: center;
height: 100vh;

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -4,7 +4,7 @@
<a href="https://www.youtube.com/channel/UCvtrqmex9f7J9hxZfmhoHRw" target="_blank"><i class="uil uil-youtube"></i></a>
<a href="https://www.instagram.com/_underemployed_/" target="_blank"><i class="uil uil-instagram-alt"></i></a>
<a href="https://www.linkedin.com/in/nithin-a-06b946256/" target="_blank"><i class="uil uil-linkedin"></i></a>
<a href="" target="_blank"><i class="uil uil-facebook-f"></i></a>
</div>
<div class="container footer__container">
<article>

View file

@ -28,8 +28,8 @@ 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">
<li><a href="<?= ROOT_URL ?>signin.php">SignIn</a></li>
<!--<li class="nav__profile">
<div class="avatar">
<img src="./images/avatar1.jpg">
</div>
@ -37,7 +37,7 @@ require 'config/database.php';
<li><a href="<?= ROOT_URL ?>/admin/index.php">Dashboard</a></li>
<li><a href="<?= ROOT_URL ?>logout.php">Logout</a></li>
</ul>
</li>
</li>-->
</ul>
<button id="open__nav-btn"><i class="uil uil-bars"></i></button>

94
signup-logic.php Normal file
View file

@ -0,0 +1,94 @@
<?php
require "config/database.php";
session_start();
//get signup form data
if(isset($_POST["submit"])){
$firstname = filter_var($_POST['firstname'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$lastname = filter_var($_POST['lastname'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$username = filter_var($_POST['username'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$createpassword = filter_var($_POST['createpassword'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$confirmpassword = filter_var($_POST['confirmpassword'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$avatar = $_FILES['avatar'];
if(!$firstname){
$_SESSION['signup'] = 'Please enter your First Name';
}elseif(!$lastname){
$_SESSION['signup'] = 'Please enter your Last Name';
}elseif(!$username){
$_SESSION['signup'] = 'Please enter your Username';
}elseif(!$email){
$_SESSION['signup'] = 'Please enter your Email';
}elseif(strlen($createpassword)<8 || strlen($confirmpassword)<8){
$_SESSION['signup'] = 'Password should be 8+ characters';
}elseif(!$avatar['name']){
$_SESSION['signup'] = 'Please add Avatar ';
}else{
if($createpassword !== $confirmpassword){
$_SESSION['signup']="Passwords donot match";
}else{
$hashed_password = password_hash($createpassword,PASSWORD_DEFAULT);
$user_check_query="SELECT * FROM users WHERE username='$username' OR email ='$email'";
$user_check_result = mysqli_query($connection, $user_check_query);
if(mysqli_num_rows($user_check_result)>0){
$_SESSION['signup'] = "Username or Email already exists";
}else{
//WORK ON AVATAR
//rename avatar
$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;
//,ake sure file is an image
$allowed_files = ['png', 'jpg', 'jpeg'];
$extension = explode('.', $avatar_name);
$extension = end($extension);
if(in_array($extension,$allowed_files)){
//if image not too large
if($avatar['size']<1000000){
//upload avatar
move_uploaded_file($avatar_tmp_name, $avatar_destination_path);
}else{
$_SESSION['signup']="Folder size too big.Should be less than 1mb";
}
}else{
$_SESSION['signup']="File should be png, jpg or jpeg";
}
}
}
}
// redirect back t signup on error
if(isset($_SESSION['signup'])){
// pass data back to sign up page
$_SESSION['signup-data'] = $_POST;
header('location: ' . ROOT_URL . 'signup.php');
die();
}else{
//insert new user into users table
$inset_user_query = "INSERT INTO users SET firstname ='$firstname' ,lastname='$lastname',username='$username',email ='$email' ,password='$hashed_password',avatar='$avatar_name',is_admin=0";
$inset_user_result = mysqli_query($connection, $inset_user_query);
if(!mysqli_errno($connection)){
$_SESSION['signup-success'] = "Registration Successful Please login";
header('location: ' . ROOT_URL . 'signin.php');
}
}
}else{
//button not clicked
header('location: ' . ROOT_URL . "signup.php");
die();
}

View file

@ -1,3 +1,20 @@
<?php
session_start();
include "config/constants.php";
//get beck form DATA IF THERE IS A REGISTRATION ERROR
$firstname=$_SESSION['signup-data']['firstname'] ?? null;
$lastname=$_SESSION['signup-data']['lastname'] ?? null;
$username=$_SESSION['signup-data']['username'] ?? null;
$email=$_SESSION['signup-data']['email'] ?? null;
$createpassword=$_SESSION['signup-data']['createpassword'] ?? null;
$confirmpassword = $_SESSION['signup-data']['confirmpassword'] ?? null;
//delete signup data session
unset($_SESSION['signup-data']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
@ -6,7 +23,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UNDEREMPLOYED</title>
<!-- CUSTOM STYLESHEET -->
<link rel="stylesheet" href="./css/style.css">
<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) -->
@ -19,21 +36,30 @@
<div class="container form__section-container">
<h2>Sign Up</h2>
<div class="alert__message error">
<p>This is an error message</p>
</div>
<form action="" enctype="multipart/form-data">
<input type="text" placeholder="First Name">
<input type="text" placeholder="Last Name">
<input type="text" placeholder="Username">
<input type="email" placeholder="Email">
<input type="password" placeholder="Create Password">
<input type="password" placeholder="Confirm Password">
<?php
if(isset($_SESSION['signup'])): ?>
<div class="alert__message error">
<p>
<?= $_SESSION['signup'];
unset($_SESSION['signup']);
?>
</p>
</div>
<?php endif ?>
<form action="<?=ROOT_URL?>signup-logic.php" enctype="multipart/form-data" method="POST">
<input type="text" name ="firstname" value ="<?= $firstname?>" placeholder="First Name">
<input type="text" name ="lastname" value ="<?= $lastname?>" placeholder="Last Name">
<input type="text" name ="username" value ="<?= $username ?>" placeholder="Username">
<input type="email" name ="email" value ="<?= $email ?>" placeholder="email">
<input type="password" name ="createpassword" value ="<?= $createpassword ?>" placeholder="Password">
<input type="password" name ="confirmpassword" value ="<?= $confirmpassword?>" placeholder="Confirm Password">
<div class="form__control">
<label for="avatar">User Avatar</label>
<input type="file" id="avatar">
<input type="file" name="avatar" id="avatar">
</div>
<button type="submit" class="btn">Sign Up</button>
<button type="submit" name ="submit"class="btn">Sign Up</button>
<small>Already have an Account? <a href="signin.php">Sign in</a></small>
</form>
</div>