Skip to content

Commit

Permalink
optimize the login, log out and register module; integrate all the mo…
Browse files Browse the repository at this point in the history
…dule into system
  • Loading branch information
fqyyang committed Nov 18, 2015
1 parent 9ccd90e commit 7b4473f
Show file tree
Hide file tree
Showing 24 changed files with 451 additions and 141 deletions.
32 changes: 11 additions & 21 deletions debug_log.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
0
update food: update food
set name = 'noodle', price = '89', description ='good'
where food_id = 2
update food: update food
set name = 'lobster', price = '1999', description ='hello Some default panel content here. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit.s'
where food_id = 1
update food: update food
set name = 'lobster', price = '986', description ='hello Some default panel content here. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit.s'
where food_id = 1
update food: update food
set name = 'lobster', price = '456', description ='hello Some default panel content here. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit.s'
where food_id = 1
update food: update food
set name = 'lobster', price = '45877', description ='hello Some default panel content here. Nulla vitae elit libero, a pharetra augue. Aenean lacinia bibendum nulla sed consectetur. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit.s'
where food_id = 1
old user id: and old merchant id: 1 and name: guchen
now user id: and now merchant id: and name: guchen
old user id: 9 and old merchant id: and name: nanding
now user id: and now merchant id: and name: nanding
begin================
end=======================
begin================
end=======================
begin================
end=======================
begin================
end=======================
begin================
insert into malign_according values(NULL,
1,
'24'
)
end=======================
begin================
insert into malign_according values(NULL,
1,
'25'
'31'
)
end=======================
5 changes: 3 additions & 2 deletions food_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ function display_food_details($food_info){
}

function display_food_reviews($food_info){
session_start(); $id = $_SESSION['valid_user'];

$food_id = $food_info[0]['food_id'];

echo "<div class=\"form-group\">
<a href=\"write_food_review.php?food_id=".$food_id."\" class=\"btn btn-primary\" role=\"button\">Write Review</a>
</div>
<div class=\"form-group\">
<a href=\"write_complaints.php?food_id=".$food_id."&customer_id=1\" class=\"btn btn-primary\" role=\"button\">Write Complaints</a>
<a href=\"write_complaints.php?food_id=".$food_id."&customer_id=".$id."\" class=\"btn btn-primary\" role=\"button\">Write Complaints</a>
</div>";

echo "<h3>Reviews made by customers:</h3>";
Expand Down Expand Up @@ -84,7 +85,7 @@ function display_food_reviews($food_info){
<a href=\"write_food_review.php?food_id=".$food_id."\" class=\"btn btn-primary\" role=\"button\">Write Review</a>
</div>
<div class=\"form-group\">
<a href=\"write_complaints.php?food_id=".$food_id."&customer_id=1\" class=\"btn btn-primary\" role=\"button\">Write Complaints</a>
<a href=\"write_complaints.php?food_id=".$food_id."&customer_id=".$id."\" class=\"btn btn-primary\" role=\"button\">Write Complaints</a>
</div>";
/*
Expand Down
2 changes: 2 additions & 0 deletions food_galaxy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ create table merchant
(
merchant_id int unsigned not null auto_increment primary key,
name char(60) not null,
password char(80) not null,
email char(80) not null,
address char(80) not null,
phone1 char(20) not null,
phone2 char(20),
Expand Down
11 changes: 3 additions & 8 deletions food_of_merchant.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<?php
include_once('food_galaxy_fns.php');
do_html_header("Food of Merchant:");


do_html_header("Food of Merchant:");

if($_GET['delete_food_id']){
if(!delete_food($_GET['delete_food_id']))
echo "Error: Failed to delete food";


echo "Error: Failed to delete food";
}

display_food_of_merchant();

display_food_of_merchant();
?>


Expand Down
19 changes: 18 additions & 1 deletion galaxy_fns.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function write_food_review(){
require_once ('food_galaxy_fns.php');

$conn = db_connect();
$query = "insert into review values(NULL,'".$_POST['type']."','".$_POST['food_id']."','".$_POST['author_id']."','".$_POST['title']."','".$_POST['review_content']."','".$_POST['date']."')";
$query = "insert into review values(NULL,'".$_POST['type']."','".$_POST['food_id']."','".$_POST['author_id']."','".$_POST['title']."','".$_POST['review_content']."','".$_POST['date']."')";
$result = $conn->query($query);
if (!$result) return false;

Expand All @@ -108,5 +108,22 @@ function write_food_review(){
}
return true;
}

function test_session(){
session_start();
$old_user = $_SESSION['valid_user'];
$old_merchant = $_SESSION['valid_merchant'];
$old_name = $_SESSION['name'];
write_log("old user id: ".$old_user." and old merchant id: ".$old_merchant." and name: ".$old_name);


unset($_SESSION['valid_user']);
unset($_SESSION['valid_merchant']);
session_destroy();
$new_user = $_SESSION['valid_user'];
$new_merchant = $_SESSION['valid_merchant'];
$new_name = $_SESSION['name'];
write_log("now user id: ".$new_user." and now merchant id: ".$new_merchant." and name: ".$new_name);
}

?>
50 changes: 50 additions & 0 deletions home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

// include function files for this application
require_once('food_galaxy_fns.php');
session_start();


//create short variable names
$username = $_POST['username'];
$passwd = $_POST['passwd'];
$type = $_POST['type'];

if ($username && $passwd) {
// they have just tried logging in

$id = login($username, $passwd, $type);
if($id != -1){
if($type == 0)
$_SESSION['valid_user'] = $id;
else if($type == 1)
$_SESSION['valid_merchant'] = $id;
$_SESSION['name'] = $username;
do_html_header('Home Page');
echo '<div class="form-group" id="success_message">
<div class="col-sm-offset-2 col-sm-8">
<div class="alert alert-success">
<h3> Log in Success! Now, you can use more service! </h3>
</div>
</div>
</div>';

}
else{
echo '<div class="form-group" id="success_message">
<div class="col-sm-offset-2 col-sm-8">
<div class="alert alert-danger">
<h3> logged in Failure. <a href="login.php">Click here to log in again</a></h3>
</div>
</div>
</div>';

}


}



do_html_footer();
?>
Binary file added img/26.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/27.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/28.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/29.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/30.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/31.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 57 additions & 40 deletions login.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Food Galaxy Manager</title>
<meta name="keywords" content="">
<meta name="description" content="">
<?php
require_once('food_galaxy_fns.php');
do_html_header('Welcome to Food Galaxy, please login');

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="">
<link rel="shortcut icon" href="favicon.png">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="https://manager.wasify.com/assets/css/public.css" rel="stylesheet">
</head>
<body>
<div class="container container-body" id="managerLogin">
<div class="row">
<div class="col-sm-offset-4 col-sm-4 text-center">
<div style="margin-top:25%">
<div class="loginLogo"><img class="img-responsive" src="https://manager.wasify.com/assets/img/logo-big.png"></div>
<div class="alert alert-danger">Wrong username or password, please try again</div>
<form class="form-signin" role="form" action="login" method="post">
<div class="form-group">
<input type="email" class="form-control" id="email" name="email" maxlength="50" placeholder="Email" value="">
<input type="password" class="form-control" id="pass" name="pass" maxlength="20" placeholder="Password" value="">
</div>
<button type="submit" class="btn btn-lg btn-success btn-block" name="commandLogin" value="1">Login</button>
<div class="loginLinks">
<a href="#">Forgotten password?</a>
<br><a href="#" rel="nofollow" data-toggle="modal" data-target="#signUp">Not a user yet? Try Food Galaxy!</a>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
//display_site_info();
?>



<div class = "container">
<form class="form-horizontal" method="post" action="home.php">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="username" placeholder="">
</div>
</div>

<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="passwd" placeholder="">
</div>
</div>

<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Login as:</label>
<div class="col-sm-10">
<select class="form-control" name="type">
<option value="0">Customer</option>
<option value="1">Merchant</option>
</select>
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
<label for="inputEmail3" class=" control-label"><a href="register_form.php"><b>Not a member?</b></a></label>
<label for="inputEmail3" class=" control-label"><a href="forgot_form.php"><b>Forgot your password?</b></a></label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Sign in</button>
</div>
</div>
</form>
</div>


<?php
do_html_footer();
?>
72 changes: 69 additions & 3 deletions login_back.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,75 @@
<?php
require_once('food_galaxy_fns.php');
do_html_header('');
do_html_header('Welcome to Food Galaxy, please login');

display_site_info();
display_login_form();
//display_site_info();
?>

<p><a href="register_form.php">Not a member?</a></p>
<form method="post" action="home.php">
<table bgcolor="#cccccc">
<tr>
<td colspan="2">Members log in here:</td>
<tr>
<td>Username:</td>
<td><input type="text" name="username"/></td></tr>
<tr>
<td>Password:</td>
<td><input type="password" name="passwd"/></td></tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Log in"/></td></tr>
<tr>
<td colspan="2"><a href="forgot_form.php">Forgot your password?</a></td>
</tr>
</table></form>

<div class = "container">
<form class="form-horizontal" method="post" action="home.php">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="username" placeholder="">
</div>
</div>

<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="passwd" placeholder="">
</div>
</div>

<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Login as:</label>
<div class="col-sm-10">
<select class="form-control" name="type">
<option value="0">Customer</option>
<option value="1">Merchant</option>
</select>
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
<label for="inputEmail3" class=" control-label"><a href="register_form.php"><b>Not a member?</b></a></label>
<label for="inputEmail3" class=" control-label"><a href="forgot_form.php"><b>Forgot your password?</b></a></label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Sign in</button>
</div>
</div>
</form>
</div>


<?php
do_html_footer();
?>
14 changes: 14 additions & 0 deletions logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
session_start();
unset($_SESSION['valid_user']);
unset($_SESSION['valid_merchant']);
unset($_SESSION['name']);
session_destroy();

require_once('food_galaxy_fns.php');
do_html_header('You have logged out');
?>

<?php
do_html_footer();
?>
2 changes: 1 addition & 1 deletion merchant_food_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function update_food(){
<div class="form-group" id="success_message" style="display:none;">
<div class="col-sm-offset-2 col-sm-10">
<div class="alert alert-success">
<h3>Food Udpating Success!<a href=”#” onClick=”javascript:window.history.go(-1);">Click here to go back</a></h3>
<h3>Food Udpating Success!<a href="food_of_merchant.php?merchant_id=<?php session_start(); echo $_SESSION['valid_merchant'];?>">Click here to go back</a></h3>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 7b4473f

Please sign in to comment.