-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.php
More file actions
87 lines (76 loc) · 2.54 KB
/
User.php
File metadata and controls
87 lines (76 loc) · 2.54 KB
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
<?php
require_once("Database.php");
class User {
private $db;
public function __construct(){
$this->db = new Database();
}
// Now we want to check whether user with the same email address is available or not
public function checkUserAvail($email){
$uresult =mysqli_query($this->db->connection,"SELECT user_email FROM users WHERE user_email='$email'");
return $uresult;
}
public function checkNumRows($email){
if($this->checkUserAvail($email)){
$num=mysqli_num_rows($this->checkUserAvail($email));
return $num;
}
}
// Now we want to register the user when he fill the form.
public function registerUser($fname, $lname, $uname, $uemail, $upass){
$date = $this->db->getDate();
$regResult=mysqli_query(
$this->db->connection,
"INSERT INTO users(first_name,second_name,user_name,user_email, user_pass, user_created) VALUE('$fname','$lname','$uname','$uemail','$upass', '$date')"
);
if($regResult){
return $regResult;
} else {
return $this->db->mysqliError($this->db->connection);
}
}
public function loginUser($uEmail, $uPass){
$loginResult = mysqli_query(
$this->db->connection,
"SELECT id,first_name, second_name FROM users WHERE user_email='$uEmail' AND user_pass='$uPass'"
);
if($loginResult){
return $loginResult;
} else {
return $this->db->mysqliError($this->db->connection);
}
}
public function getProfile($uid){
$profileSection = mysqli_query(
$this->db->connection,
"SELECT * FROM users WHERE id='$uid'"
);
if($profileSection){
return $profileSection;
} else {
return $this->db->mysqliError($this->db->connection);
}
}
public function updateProfilePassword($id, $newPass){
$updateResult = mysqli_query(
$this->db->connection,
"UPDATE users SET user_pass='$newPass' WHERE id='$id'"
);
if($updateResult){
return $updateResult;
} else {
return $this->db->mysqliError($this->db->connection);
}
}
/*** starting the session ***/
public function get_session(){
if(isset($_SESSION['login'])){
return $_SESSION['login'];
}
}
public function logout() {
$_SESSION['login'] = FALSE;
session_destroy();
}
}
?>