-
Notifications
You must be signed in to change notification settings - Fork 3
/
User.php
319 lines (287 loc) · 11.9 KB
/
User.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
/**
* Created by PhpStorm.
* User: Tushar
* Date: 4/25/2017
* Time: 4:34 PM
*/
include 'database.php';
include_once 'Session.php';
class User
{
private $db;
/**
* Database Class
*/
public function __construct()
{
$this->db = new Database();
}
/**
* return Registration
*/
public function userRegistration($data)
{
$name = $data['name'];
$email = $data['email'];
$passWord = md5($data['password']);
$rePassWord = md5($data['rePassword']);
/*
* Checking Email
*/
$mailCheck = $this->MailCheck($email);
/*
* Filter for Registration
* information
* @return $dangerMsg
*/
if ((empty($name)) || (empty($email)) || (empty($passWord)))
{
if (empty($name))
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo " Name Should be field.";
echo "</div>";
//return $dangerMsg;
}
elseif (empty($email))
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo " E-mail Should be field.";
echo "</div>";
}
elseif(empty($passWord))
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo " Password Must be field.";
echo "</div>";
}
}
elseif (!empty($passWord))
{
if(strcasecmp($passWord, $rePassWord) != 0)
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo "Password Not Matched.";
echo "</div>";
}
if(strlen($passWord) <= 5)
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo " Password Must More Than 5 Character.";
echo "</div>";
}
}
if(!empty($email))
{
if (filter_var($email, FILTER_VALIDATE_EMAIL) == false)
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "pleas"; echo "</strong>"; echo " Enter a Valid E-mail";
echo "</div>";
}
}
if($mailCheck == true)
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry !"; echo "</strong>"; echo " E-mail Exist";
echo "</div>";
}
//return $dangerMsg;
$sql = "INSERT INTO info (name, email, pass) VALUES (:name,:email,:password)";
$query = $this->db->pdo->prepare($sql);
$query->bindValue(':name', $name);
$query->bindValue(':email', $email);
$query->bindValue(':password', $passWord);
$result = $query->execute();
if($result)
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-success'> "; echo "congratulation you have been registered successfully "; echo "</strong>";
echo "</div>";
}
else
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry !"; echo "</strong>"; echo " There have been some problem inserting values";
echo "</div>";
}
}//Function for Registration
/**
* return MailCheck
*/
public function MailCheck($email)
{
$sql = "SELECT email FROM info WHERE email = :email";
$query = $this->db->pdo->prepare($sql);
$query->bindValue(':email', $email);
$query->execute();
if($query->rowCount() > 0)
{
return (true);
}
else
{
return (false);
}
}
public function getLoginUser($email, $password)
{
$sql = "SELECT * FROM info WHERE email = :email AND pass = :password LIMIT 1";
$query = $this->db->pdo->prepare($sql);
$query->bindValue(':email', $email);
$query->bindValue(':password', $password);
$query->execute();
$result = $query->fetch(PDO::FETCH_OBJ);
return $result;
}
/**
* userLogin Function
* for login
*/
public function userLogin($data)
{
$logEmail = $data['email'];
$loginPass = md5($data['password']);
/*
* Checking Email
*/
$loginMailCheck = $this->MailCheck($logEmail);
if(empty($logEmail) || empty($loginPass))
{
if(empty($logEmail))
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo " E-mail Should be field.";
echo "</div>";
}
elseif (empty($loginPass))
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo " Password Should be field.";
echo "</div>";
}
}/*Checking if input is empty*/
if(!empty($logEmail))
{
if(filter_var($logEmail, FILTER_VALIDATE_EMAIL) == false)
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "pleas"; echo "</strong>"; echo " Enter a Valid E-mail";
echo "</div>";
}
if ($loginMailCheck == false)
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry !"; echo "</strong>"; echo " E-mail don't Exist";
echo "</div>";
}
}
$result = $this->getLoginUser($logEmail, $loginPass);
if($result)
{
Session::init();
Session::set("login", true);
Session::set("id", $result->id);
Session::set("name", $result->name);
Session::set("loginMessage", "<div class='alert alert-success'><strong class='text-capitalize text-success'> welcome ! </strong> You are loggedIn!!</div>");
header("Location: index.php");
}
/*else
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry !"; echo "</strong>"; echo " You are not Registered Yes!!";
echo "</div>";
}*/
}//userLogin function
public function getUserData()
{
$sql = "SELECT * FROM info ORDER BY id ASC";
$query = $this->db->pdo->prepare($sql);
$query->execute();
$result = $query->fetchAll();
return $result;
}//User Data Function
public function getUserDataById($userId)
{
$sql = "SELECT * FROM info WHERE id = :id LIMIT 1";
$query = $this->db->pdo->prepare($sql);
$query->bindValue(':id', $userId);
$query->execute();
$result = $query->fetch(PDO::FETCH_OBJ);
return $result;
}//Function for getting User Data By Id
public function updateUser($id, $data)
{
$name = $data['name'];
$email = $data['email'];
$passWord = md5($data['password']);
/*
* Filter for Registration
* information
* @return Danger Message
*/
if ((empty($name)) || (empty($email)) /*|| (empty($passWord))*/)
{
if (empty($name))
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo " Name Should be field.";
echo "</div>";
//return $dangerMsg;
}
elseif (empty($email))
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo " E-mail Should be field.";
echo "</div>";
}
/*
elseif(empty($passWord))
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo " Password Must be field.";
echo "</div>";
}
*/
}
elseif (!empty($passWord))
{
if(strlen($passWord) <= 5)
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry!"; echo "</strong>"; echo " Password Must More Than 5 Character.";
echo "</div>";
}
}
if(!empty($email))
{
if (filter_var($email, FILTER_VALIDATE_EMAIL) == false)
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "pleas"; echo "</strong>"; echo " Enter a Valid E-mail";
echo "</div>";
}
}
$sql = "UPDATE info SET name = :name ,email = :email , pass = :pass WHERE id = :id";
$query = $this->db->pdo->prepare($sql);
$query->bindValue(':name', $name);
$query->bindValue(':email', $email);
$query->bindValue(':pass', $passWord);
$query->bindValue(':id', $id);
$result = $query->execute();
if($result)
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-success'> "; echo "congratulation your information have been updated successfully "; echo "</strong>";
echo "</div>";
}
else
{
echo "<div class='alert alert-danger'>";
echo "<strong class='text-capitalize text-danger'> "; echo "sorry !"; echo "</strong>"; echo " There have been some problem inserting values";
echo "</div>";
}
}//Function for update uset data
}//Main Class
?>