/
enter.php
168 lines (166 loc) · 7.74 KB
/
enter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<html>
<head>
<?php include 'reqs.php';?>
<link rel="stylesheet" href="form.css">
<title>Grocery Store</title>
<script src="form.js"></script>
</head>
<body>
<?php
session_set_cookie_params(3600,"/");
if(isset($_SESSION["username"])){
header("Location: index.php");
}
?>
<?php include 'navbar.php';?>
<div class="cont_principal">
<div class="cont_centrar">
<div class="cont_login">
<form action="enter.php" method="POST">
<div class="cont_tabs_login">
<ul class='ul_tabs'>
<li class="active"><a href="#" onclick="sign_in()">SIGN IN</a>
<span class="linea_bajo_nom"></span>
</li>
<li><a href="#" onclick="sign_up()">SIGN UP</a><span class="linea_bajo_nom"></span>
</li>
</ul>
</div>
<div class="cont_text_inputs">
<input type="text" class="input_form_sign d_block active_inp" placeholder="Username*" name="uname" />
<input type="text" class="input_form_sign d_block" placeholder="First Name*" name="fname" />
<input type="text" class="input_form_sign d_block" placeholder="Last Name" name="lname" />
<input type="text" class="input_form_sign d_block" placeholder="Email*" name="email" />
<input type="text" class="input_form_sign d_block" placeholder="Mobile Number" name="mno" />
<input type="password" class="input_form_sign d_block active_inp" placeholder="Password*" name="pass" />
<input type="password" class="input_form_sign d_block" placeholder="Confirm Password*" name="conf_pass" />
<input type="hidden" name="act" id="act" value="login"/>
</div>
<div class="cont_btn">
<button class="btn_sign">SIGN IN</button>
</div>
</form>
</div>
</div>
</div>
<?php
if($_SERVER["REQUEST_METHOD"] == 'POST')
{
require_once 'config.php';
$username = $password = $confirm_password = $email = $first_name = $last_name = $mobile_no = NULL;
if($_POST["act"] == "signup")
{
echo "<script>sign_up()</script>";
$username = mysql_real_escape_string(trim($_POST["uname"]));
$first_name = mysql_real_escape_string(trim($_POST["fname"]));
$last_name = mysql_real_escape_string(trim($_POST["lname"]));
$email = mysql_real_escape_string(trim($_POST["email"]));
$password = trim($_POST["pass"]);
$confirm_password = trim($_POST["conf_pass"]);
$mobile_no = mysql_real_escape_string(trim($_POST["mno"]));
if($username == "")
{
echo "<script>alert('Username cannot be left empty!')</script>";
die();
}
if($first_name == "")
{
echo "<script>alert('First Name cannot be left empty!')</script>";
die();
}
if($email == "")
{
echo "<script>alert('Email cannot be left empty!')</script>";
die();
}
if($password == "")
{
echo "<script>alert('Password cannot be left empty!')</script>";
die();
}
$password = password_hash($password,PASSWORD_DEFAULT);
if($confirm_password == "")
{
echo "<script>alert('Confirm Password cannot be left empty!')</script>";
die();
}
if(!password_verify($confirm_password,$password))
{
echo "<script>alert('Passwords do not match!')</script>";
die();
}
if($last_name == "")
{
$last_name = NULL;
}
if($mobile_no == "")
{
$mobile_no = NULL;
}
$check = "SELECT * from USER where user_id='$username'";
if(mysqli_num_rows(mysqli_query($conn,$check)) != 0)
{
echo "<script>alert('Username is already taken!')</script>";
die();
}
$check = "SELECT * from USER where email_id='$email'";
if(mysqli_num_rows(mysqli_query($conn,$check)) != 0)
{
echo "<script>alert('User with that Email ID already exists!')</script>";
die();
}
$query = "INSERT INTO USER VALUES('$username','$email','$password','$first_name','$last_name','$mobile_no')";
$out = mysqli_query($conn,$query);
if(!$out)
{
echo "<script>alert('$conn->error')</script>";
die();
}
$return = $_SESSION['ploc'];
$_SESSION['username'] = $username;
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email'] = $email;
$_SESSION['mobile'] = $mobile_no;
echo "<script>window.location = '$return';</script>";
}
else if($_POST["act"] == "login")
{
$username = mysql_real_escape_string(trim($_POST["uname"]));
$password = trim($_POST["pass"]);
if($username == "")
{
echo "<script>alert('Username cannot be left empty!')</script>";
die();
}
if($password == "")
{
echo "<script>alert('Password cannot be left empty!')</script>";
die();
}
$check = "SELECT * from USER where user_id='$username' LIMIT 1";
$out = mysqli_query($conn,$check);
if(mysqli_num_rows($out) == 0)
{
echo "<script>alert('Invalid username or Password!')</script>";
die();
}
$out = mysqli_query($conn,$check);
$out = mysqli_fetch_assoc($out);
if(!password_verify($password,$out["password"]))
{
echo "<script>alert('Invalid username or Password!')</script>";
die();
}
$return = $_SESSION['ploc'];
$_SESSION['username'] = $username;
$_SESSION['first_name'] = $out['first_name'];
$_SESSION['last_name'] = $out['last_name'];
$_SESSION['email'] = $out['email_id'];
$_SESSION['mobile'] = $out['mobile_no'];
echo "<script>window.location = '$return';</script>";
}
}
?>
</body>
</html>