initial login and signup form created. profile is the usersite wich has to be configured now.

This commit is contained in:
Ivan Hörler 2017-02-03 18:03:11 +01:00
parent 7dc004705e
commit 171eed216c
12 changed files with 594 additions and 29 deletions

94
Website/class.user.php Normal file
View File

@ -0,0 +1,94 @@
<?php
require_once('dbconfig.php');
class USER
{
private $conn;
public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}
public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}
public function register($uname,$upass)
{
try
{
//$new_password = password_hash($upass, PASSWORD_DEFAULT); // 3.2.17 ivan changed to cleartext password saving to make it more easy...
$new_password = $upass;
$stmt = $this->conn->prepare("INSERT INTO users(user_name,user_pass)
VALUES(:uname, :upass)");
$stmt->bindparam(":uname", $uname);
$stmt->bindparam(":upass", $new_password);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function doLogin($uname,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT user_id, user_name, user_pass FROM users WHERE user_name=:uname");
$stmt->execute(array(':uname'=>$uname));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
//if(password_verify($upass, $userRow['user_pass'])) // 3.2.17 ivan changed to cleartext password saving to make it more easy...
if($upass == $userRow['user_pass'])
{
$_SESSION['user_session'] = $userRow['user_id'];
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function is_loggedin()
{
if(isset($_SESSION['user_session']))
{
return true;
}
}
public function redirect($url)
{
header("Location: $url");
}
public function doLogout()
{
session_destroy();
unset($_SESSION['user_session']);
return true;
}
}
?>

27
Website/dbconfig.php Normal file
View File

@ -0,0 +1,27 @@
<?php
class Database
{
private $host = "localhost";
private $db_name = "dblogin";
private $username = "root";
private $password = "";
public $conn;
public function dbConnection()
{
$this->conn = null;
try
{
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $exception)
{
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
?>

39
Website/dblogin.sql Normal file
View File

@ -0,0 +1,39 @@
-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Jan 07, 2016 at 03:05 AM
-- Server version: 5.6.17
-- PHP Version: 5.5.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `dblogin`
--
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(15) NOT NULL,
`user_pass` varchar(255) NOT NULL,
`joining_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

93
Website/home.php Normal file
View File

@ -0,0 +1,93 @@
<?php
require_once("session.php");
require_once("class.user.php");
$auth_user = new USER();
$user_id = $_SESSION['user_session'];
$stmt = $auth_user->runQuery("SELECT * FROM users WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" type="text/css" />
<title>welcome - <?php print($userRow['user_name']); ?></title>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://www.codingcage.com">Coding Cage</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="http://www.codingcage.com/2015/04/php-login-and-registration-script-with.html">Back to Article</a></li>
<li><a href="http://www.codingcage.com/search/label/jQuery">jQuery</a></li>
<li><a href="http://www.codingcage.com/search/label/PHP">PHP</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-user">
</span>&nbsp;Hi'
<?php echo $userRow['user_name'];
?>&nbsp;
<span class="caret">
</span>
</a>
<ul class="dropdown-menu">
<li><a href="profile.php"><span class="glyphicon glyphicon-user"></span>&nbsp;View Profile</a></li>
<li><a href="logout.php?logout=true"><span class="glyphicon glyphicon-log-out"></span>&nbsp;Sign Out</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="clearfix">
</div>
<div class="container-fluid" style="margin-top:80px;">
<div class="container">
<label class="h5">welcome :
<?php print($userRow['user_name']);
?>
</label>
<hr />
<h1>
<a href="home.php">
<span class="glyphicon glyphicon-home">
</span> home
</a> &nbsp;
<a href="profile.php">
<span class="glyphicon glyphicon-user">
</span> profile
</a>
</h1>
<hr />
<p class="h4">User Home Page
</p>
<p class="blockquote-reverse" style="margin-top:200px;">
Programming Blog Featuring Tutorials on PHP, MySQL, Ajax, jQuery, Web Design and More...
<br />
<br />
<a href="http://www.codingcage.com/2015/04/php-login-and-registration-script-with.html">tutorial link
</a>
</p>
</div>
</div>
</body>
</html>

BIN
Website/images/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -1,29 +0,0 @@
<!DOCTYPE HTML>
<meta charset="UTF-8">
<html>
<head></head>
<body>
<header>
<h1> Most important heading </h1>
<h3> Less important heading </h3>
</header>
<nav>
<ul>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
</ul>
</nav>
<article>
<h1>The article title</h1>
<p>Contents of the article element </p>
</article>
<article>
<h1>A new article</h1>
<section>
<h1>Heading</h1>
<p>content or image</p>
</section>
</article>
<footer></footer>
</body>
</html>

75
Website/index.php Normal file
View File

@ -0,0 +1,75 @@
<?php
session_start();
require_once("class.user.php");
$login = new USER();
if($login->is_loggedin()!=""){
$login->redirect('home.php');
}
if(isset($_POST['btn-login'])){
$uname = strip_tags($_POST['txt_uname']);
$upass = strip_tags($_POST['txt_password']);
if($login->doLogin($uname,$upass)){
$login->redirect('home.php');
} else {
$error = "Wrong Details !";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BusinessStreamline : Login</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="signin-form">
<div class="container">
<form class="form-signin" method="post" id="login-form">
<div class="logo">
<a href="."><img id="logo" src="images/logo.png" alt="Business Streamline" /></a>
</div>
<h2 class="form-signin-heading">Log In to WebApp.</h2>
<hr />
<div id="error">
<?php
if(isset($error)){
?>
<div class="alert alert-danger">
<i class="form-signin-line"></i> &nbsp;
<?php echo $error; ?> !
</div>
<?php
} else if(isset($_GET['joined'])) {
?>
<div class="alert alert-info">
<i class="form-signin-line">
</i> &nbsp; Successfully registered, please login now:
</div>
<?php
}
?>
</div>
<br />
<div class="form-group">
<input type="text" class="form-control" name="txt_uname" placeholder="Username" required />
<span id="check-e">
</span>
</div>
<div class="form-group">
<input type="password" class="form-control" name="txt_password" placeholder="Your Password" />
<button type="submit" name="btn-login" class="btn btn-default">
<i class="btn-big"></i>SIGN IN
</button>
</div>
<hr />
<br />
<label class="form-signin-line">You don't have account yet ?
<a href="sign-up.php">Sign Up</a>
</label>
</form>
</div>
</div>
</body>
</html>

14
Website/logout.php Normal file
View File

@ -0,0 +1,14 @@
<?php
require_once('session.php');
require_once('class.user.php');
$user_logout = new USER();
if($user_logout->is_loggedin()!="")
{
$user_logout->redirect('home.php');
}
if(isset($_GET['logout']) && $_GET['logout']=="true")
{
$user_logout->doLogout();
$user_logout->redirect('index.php');
}

75
Website/profile.php Normal file
View File

@ -0,0 +1,75 @@
<?php
require_once("session.php");
require_once("class.user.php");
$auth_user = new USER();
$user_id = $_SESSION['user_session'];
$stmt = $auth_user->runQuery("SELECT * FROM users WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css" type="text/css" />
<title>welcome - <?php print($userRow['user_name']); ?></title>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://www.codingcage.com">Coding Cage</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="http://www.codingcage.com/2015/11/ajax-login-script-with-jquery-php-mysql.html">Back to Article</a></li>
<li><a href="http://www.codingcage.com/search/label/jQuery">jQuery</a></li>
<li><a href="http://www.codingcage.com/search/label/PHP">PHP</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-user"></span>&nbsp;Hi' <?php echo $userRow['user_name']; ?>&nbsp;<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#"><span class="glyphicon glyphicon-user"></span>&nbsp;View Profile</a></li>
<li><a href="logout.php?logout=true"><span class="glyphicon glyphicon-log-out"></span>&nbsp;Sign Out</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="clearfix">
</div>
<div class="container-fluid" style="margin-top:80px;">
<div class="container">
<label class="h5">welcome : <?php print($userRow['user_name']); ?></label>
<hr />
<h1>
<a href="home.php"><span class="glyphicon glyphicon-home"></span> home</a> &nbsp;
<a href="profile.php"><span class="glyphicon glyphicon-user"></span> profile</a></h1>
<hr />
<p class="h4">Another Secure Profile Page</p>
<p class="blockquote-reverse" style="margin-top:200px;">
Programming Blog Featuring Tutorials on PHP, MySQL, Ajax, jQuery, Web Design and More...
<br />
<br />
<a href="http://www.codingcage.com/2015/04/php-login-and-registration-script-with.html">tutorial link</a>
</p>
</div>
</div>
</body>
</html>

15
Website/session.php Normal file
View File

@ -0,0 +1,15 @@
<?php
session_start();
require_once 'class.user.php';
$session = new USER();
// if user session is not active(not loggedin) this page will help 'home.php and profile.php' to redirect to login page
// put this file within secured pages that users (users can't access without login)
if(!$session->is_loggedin())
{
// session no set redirects to login page
$session->redirect('index.php');
}

95
Website/sign-up.php Normal file
View File

@ -0,0 +1,95 @@
<?php
session_start();
require_once('class.user.php');
$user = new USER();
if($user->is_loggedin()!=""){
$user->redirect('home.php');
}
if(isset($_POST['btn-signup'])){
$uname = strip_tags($_POST['txt_uname']);
$upass = strip_tags($_POST['txt_upass']);
if($uname=="") {
$error[] = "provide username !";
} else if($upass=="") {
$error[] = "provide password !";
} else if(strlen($upass) < 6){
$error[] = "Password must be atleast 6 characters";
} else {
try {
$stmt = $user->runQuery("SELECT user_name FROM users WHERE user_name=:uname");
$stmt->execute(array(':uname'=>$uname));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
if($row['user_name']==$uname) {
$error[] = "sorry username already taken !";
} else {
if($user->register($uname,$upass)){
$user->redirect('index.php?joined');
}
}
} catch(PDOException $e) {
echo $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Coding Cage : Sign up</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="signin-form">
<div class="container">
<form method="post" class="form-signin">
<div class="logo">
<a href="."><img id="logo" src="images/logo.png" alt="Business Streamline" /></a>
</div>
<h2 class="form-signin-heading">Sign up.</h2>
<hr />
<div id="error">
<?php
if(isset($error)){
foreach($error as $error){
?>
<div class="alert alert-danger">
<i class="form-signin-line"></i> &nbsp;
<?php echo $error; ?>
</div>
<?php
}
} else if(isset($_GET['joined'])) {
?>
<div class="alert alert-info">
<i class="form-signin-line">
</i> &nbsp; Successfully registered
<a href='index.php'>login</a> here
</div>
<?php
}
?>
</div>
<br />
<div class="form-group">
<input type="text" class="form-control" name="txt_uname" placeholder="Enter Username" value="<?php if(isset($error)){echo $uname;}?>" />
</div>
<div class="form-group">
<input type="password" class="form-control" name="txt_upass" placeholder="Enter Password" />
<button type="submit" class="btn btn-primary" name="btn-signup">
<i class="btn-big"></i>SIGN UP
</button>
</div>
<hr />
<br />
<label class="form-signin-line">You already have an account ?
<a href="index.php">Sign In</a>
</label>
</form>
</div>
</div>
</body>
</html>

67
Website/style.css Normal file
View File

@ -0,0 +1,67 @@
@charset "utf-8";
/* CSS Document */
body{
background:#f1f9f9;
}
.form-signin {
max-width: 500px;
padding: 19px 29px 29px;
margin: 0 auto;
//margin-top:90px;
background-color: #fff;
border: 1px solid #e5e5e5;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
box-shadow: 0 1px 2px rgba(0,0,0,.05);
font-family:Tahoma, Geneva, sans-serif;
color:#990000;
font-weight:lighter;
}
.form-signin .form-signin-heading{
color:#00A2D1;
}
.form-signin .form-signin-line{
color:#AAA2D1;
font-size: 18px;
}
.form-signin input[type="text"],
.form-signin input[type="password"]{
font-size: 16px;
height: 45px;
padding: 7px 9px;
}
.btn-big{
font-size: 16px;
height:45px;
}
.btn{
font-size: 14px;
height:45px;
}
.signin-form, .body-container
{
//border:solid red 1px;
margin-top:110px;
}
.navbar-brand{
font-family:"Lucida Handwriting";
}
#btn-submit{
height:45px;
}
.h5{
font-family:Verdana, Geneva, sans-serif;
}
h1{
font-family:Verdana, Geneva, sans-serif;
}