@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | - // Define database connection constants |
|
3 | - define('DB_HOST', 'localhost'); |
|
4 | - define('DB_USER', 'root'); |
|
5 | - define('DB_PASSWORD',''); |
|
6 | - define('DB_NAME', 'openchat'); |
|
7 | - define('URL', URL()); |
|
2 | + // Define database connection constants |
|
3 | + define('DB_HOST', 'localhost'); |
|
4 | + define('DB_USER', 'root'); |
|
5 | + define('DB_PASSWORD',''); |
|
6 | + define('DB_NAME', 'openchat'); |
|
7 | + define('URL', URL()); |
|
8 | 8 | |
9 | - function URL() |
|
10 | - { |
|
9 | + function URL() |
|
10 | + { |
|
11 | 11 | $http = "http://"; |
12 | 12 | $host = $_SERVER['SERVER_NAME']; |
13 | 13 | $port = $_SERVER['SERVER_PORT']; |
@@ -18,5 +18,5 @@ discard block |
||
18 | 18 | } |
19 | 19 | $url = $http.$host.":".$port.$fol; |
20 | 20 | return $url; |
21 | - } |
|
21 | + } |
|
22 | 22 | ?> |
@@ -131,6 +131,6 @@ |
||
131 | 131 | <?php |
132 | 132 | } |
133 | 133 | else{ |
134 | - header('Location:http://localhost/openchat'); |
|
134 | + header('Location:http://localhost/openchat'); |
|
135 | 135 | } |
136 | 136 | ?> |
@@ -4,35 +4,35 @@ |
||
4 | 4 | |
5 | 5 | class Validate |
6 | 6 | { |
7 | - protected $connect; |
|
7 | + protected $connect; |
|
8 | 8 | |
9 | - public function __construct() |
|
10 | - { |
|
11 | - $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
|
12 | - } |
|
9 | + public function __construct() |
|
10 | + { |
|
11 | + $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
|
12 | + } |
|
13 | 13 | |
14 | - public function validateEmailInDb($email) |
|
15 | - { |
|
16 | - $query = "SELECT login_id FROM login WHERE email = '$email'"; |
|
17 | - if ($result = $this->connect->query($query)) |
|
18 | - { |
|
19 | - if ($result->num_rows > 0) { |
|
20 | - return 1; |
|
21 | - } |
|
22 | - else |
|
23 | - return 0; |
|
24 | - } |
|
25 | - } |
|
14 | + public function validateEmailInDb($email) |
|
15 | + { |
|
16 | + $query = "SELECT login_id FROM login WHERE email = '$email'"; |
|
17 | + if ($result = $this->connect->query($query)) |
|
18 | + { |
|
19 | + if ($result->num_rows > 0) { |
|
20 | + return 1; |
|
21 | + } |
|
22 | + else |
|
23 | + return 0; |
|
24 | + } |
|
25 | + } |
|
26 | 26 | |
27 | - function validateUsernameInDb($username) |
|
28 | - { |
|
29 | - $query = "SELECT login_id FROM login WHERE username = '$username'"; |
|
30 | - if ($result = $this->connect->query($query)) { |
|
31 | - if ($result->num_rows > 0) { |
|
32 | - return 1; |
|
33 | - } |
|
34 | - else |
|
35 | - return 0; |
|
36 | - } |
|
37 | - } |
|
27 | + function validateUsernameInDb($username) |
|
28 | + { |
|
29 | + $query = "SELECT login_id FROM login WHERE username = '$username'"; |
|
30 | + if ($result = $this->connect->query($query)) { |
|
31 | + if ($result->num_rows > 0) { |
|
32 | + return 1; |
|
33 | + } |
|
34 | + else |
|
35 | + return 0; |
|
36 | + } |
|
37 | + } |
|
38 | 38 | } |
@@ -5,13 +5,13 @@ |
||
5 | 5 | |
6 | 6 | if(isset($_POST['q'])) |
7 | 7 | { |
8 | - $loginField = json_decode($_POST['q']); |
|
9 | - $login = $loginField->login; |
|
10 | - $password = $loginField->password; |
|
11 | - $obLogin = new Login(); |
|
12 | - $result = $obLogin->authLogin($login, $password); |
|
13 | - if(isset($result)) |
|
14 | - echo $result; |
|
15 | - else |
|
16 | - echo json_encode([]); |
|
8 | + $loginField = json_decode($_POST['q']); |
|
9 | + $login = $loginField->login; |
|
10 | + $password = $loginField->password; |
|
11 | + $obLogin = new Login(); |
|
12 | + $result = $obLogin->authLogin($login, $password); |
|
13 | + if(isset($result)) |
|
14 | + echo $result; |
|
15 | + else |
|
16 | + echo json_encode([]); |
|
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -5,17 +5,17 @@ |
||
5 | 5 | |
6 | 6 | if(isset($_POST['q'])) |
7 | 7 | { |
8 | - $registerField = json_decode($_POST['q']); |
|
9 | - $name = $registerField->name; |
|
10 | - $email = $registerField->email; |
|
11 | - $username = $registerField->username; |
|
12 | - $mob = $registerField->mob; |
|
13 | - $password = $registerField->password; |
|
14 | - $obRegister = new Register(); |
|
15 | - $result = $obRegister->authRegister($name, $email, $username, $password, $mob); |
|
16 | - if(isset($result)) |
|
17 | - echo $result; |
|
18 | - else |
|
19 | - echo json_encode([]); |
|
8 | + $registerField = json_decode($_POST['q']); |
|
9 | + $name = $registerField->name; |
|
10 | + $email = $registerField->email; |
|
11 | + $username = $registerField->username; |
|
12 | + $mob = $registerField->mob; |
|
13 | + $password = $registerField->password; |
|
14 | + $obRegister = new Register(); |
|
15 | + $result = $obRegister->authRegister($name, $email, $username, $password, $mob); |
|
16 | + if(isset($result)) |
|
17 | + echo $result; |
|
18 | + else |
|
19 | + echo json_encode([]); |
|
20 | 20 | } |
21 | 21 |
@@ -7,83 +7,83 @@ |
||
7 | 7 | class Login |
8 | 8 | { |
9 | 9 | |
10 | - protected $key; |
|
11 | - protected $error; |
|
12 | - protected $connect; |
|
10 | + protected $key; |
|
11 | + protected $error; |
|
12 | + protected $connect; |
|
13 | 13 | |
14 | - public function __construct() |
|
15 | - { |
|
16 | - $this->key = 0; |
|
17 | - $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
|
18 | - $this->error = array(); |
|
19 | - } |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + $this->key = 0; |
|
17 | + $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
|
18 | + $this->error = array(); |
|
19 | + } |
|
20 | 20 | |
21 | - public function authLogin($login, $password) |
|
22 | - { |
|
21 | + public function authLogin($login, $password) |
|
22 | + { |
|
23 | 23 | |
24 | - $login = trim($login); |
|
25 | - $password = trim($password); |
|
24 | + $login = trim($login); |
|
25 | + $password = trim($password); |
|
26 | 26 | |
27 | - if(empty($login)) |
|
28 | - { |
|
29 | - $this->key = 1; |
|
30 | - $this->error = array_merge($this->error, ["login" => " *Enter the login field"]); |
|
31 | - } |
|
32 | - elseif (preg_match("/^[@]{1}$/", $login)) |
|
33 | - { |
|
34 | - if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
|
35 | - { |
|
36 | - $this->key = 1; |
|
37 | - $this->error = array_merge($this->error, ["login" => " *Enter correct Email address"]); |
|
38 | - } |
|
39 | - } |
|
40 | - if(empty($password)) { |
|
41 | - $this->key = 1; |
|
42 | - $this->error = array_merge($this->error, ["password" => " *Enter the password"]); |
|
43 | - } |
|
44 | - else |
|
45 | - { |
|
46 | - $password = md5($password); |
|
47 | - } |
|
27 | + if(empty($login)) |
|
28 | + { |
|
29 | + $this->key = 1; |
|
30 | + $this->error = array_merge($this->error, ["login" => " *Enter the login field"]); |
|
31 | + } |
|
32 | + elseif (preg_match("/^[@]{1}$/", $login)) |
|
33 | + { |
|
34 | + if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
|
35 | + { |
|
36 | + $this->key = 1; |
|
37 | + $this->error = array_merge($this->error, ["login" => " *Enter correct Email address"]); |
|
38 | + } |
|
39 | + } |
|
40 | + if(empty($password)) { |
|
41 | + $this->key = 1; |
|
42 | + $this->error = array_merge($this->error, ["password" => " *Enter the password"]); |
|
43 | + } |
|
44 | + else |
|
45 | + { |
|
46 | + $password = md5($password); |
|
47 | + } |
|
48 | 48 | |
49 | - if($this->key == 0) |
|
50 | - { |
|
51 | - $query = "SELECT * FROM login WHERE email = '$login' or username = '$login'"; |
|
52 | - if ($result = $this->connect->query($query)) |
|
53 | - { |
|
54 | - if ($result->num_rows > 0) |
|
55 | - { |
|
56 | - $row = $result->fetch_assoc(); |
|
57 | - $loginID = $row['login_id']; |
|
58 | - $query = "SELECT id FROM register WHERE id = '$loginID' and password = '$password'"; |
|
59 | - if($result = $this->connect->query($query)) |
|
60 | - { |
|
61 | - if ($result->num_rows > 0) |
|
62 | - { |
|
63 | - Session::put('start', $loginID); |
|
64 | - return json_encode([ |
|
65 | - "location" => URL."/account.php" |
|
66 | - ]); |
|
67 | - } |
|
68 | - else |
|
69 | - { |
|
70 | - $this->error = array_merge($this->error, ["password" => " *Invalid password"]); |
|
71 | - return json_encode($this->error); |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
75 | - else |
|
76 | - { |
|
77 | - $this->error = array_merge($this->error, ["login" => " *Invalid username or email"]); |
|
78 | - return json_encode($this->error); |
|
79 | - } |
|
80 | - } |
|
49 | + if($this->key == 0) |
|
50 | + { |
|
51 | + $query = "SELECT * FROM login WHERE email = '$login' or username = '$login'"; |
|
52 | + if ($result = $this->connect->query($query)) |
|
53 | + { |
|
54 | + if ($result->num_rows > 0) |
|
55 | + { |
|
56 | + $row = $result->fetch_assoc(); |
|
57 | + $loginID = $row['login_id']; |
|
58 | + $query = "SELECT id FROM register WHERE id = '$loginID' and password = '$password'"; |
|
59 | + if($result = $this->connect->query($query)) |
|
60 | + { |
|
61 | + if ($result->num_rows > 0) |
|
62 | + { |
|
63 | + Session::put('start', $loginID); |
|
64 | + return json_encode([ |
|
65 | + "location" => URL."/account.php" |
|
66 | + ]); |
|
67 | + } |
|
68 | + else |
|
69 | + { |
|
70 | + $this->error = array_merge($this->error, ["password" => " *Invalid password"]); |
|
71 | + return json_encode($this->error); |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | + else |
|
76 | + { |
|
77 | + $this->error = array_merge($this->error, ["login" => " *Invalid username or email"]); |
|
78 | + return json_encode($this->error); |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - } |
|
83 | - else |
|
84 | - { |
|
85 | - return json_encode($this->error); |
|
86 | - } |
|
87 | - $this->connect->close(); |
|
88 | - } |
|
82 | + } |
|
83 | + else |
|
84 | + { |
|
85 | + return json_encode($this->error); |
|
86 | + } |
|
87 | + $this->connect->close(); |
|
88 | + } |
|
89 | 89 | } |
@@ -8,12 +8,12 @@ |
||
8 | 8 | use ChatApp\Chat; |
9 | 9 | |
10 | 10 | $server =IoServer::factory( |
11 | - new HttpServer( |
|
12 | - new WsServer( |
|
13 | - new Chat() |
|
14 | - ) |
|
15 | - ) |
|
16 | - , |
|
17 | - 8080 |
|
18 | - ); |
|
11 | + new HttpServer( |
|
12 | + new WsServer( |
|
13 | + new Chat() |
|
14 | + ) |
|
15 | + ) |
|
16 | + , |
|
17 | + 8080 |
|
18 | + ); |
|
19 | 19 | $server->run(); |
@@ -11,26 +11,26 @@ discard block |
||
11 | 11 | $userId = Session::get('start'); |
12 | 12 | if($userId != null && $user == "account.php") |
13 | 13 | { |
14 | - $obUser = new User(); |
|
15 | - $row = $obUser->UserDetails($userId, True); |
|
14 | + $obUser = new User(); |
|
15 | + $row = $obUser->UserDetails($userId, True); |
|
16 | 16 | |
17 | - if($row != NULL) |
|
18 | - { |
|
19 | - $location = URL . "/account.php/". $row['username']; |
|
20 | - header("Location:".$location); |
|
21 | - } |
|
17 | + if($row != NULL) |
|
18 | + { |
|
19 | + $location = URL . "/account.php/". $row['username']; |
|
20 | + header("Location:".$location); |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | elseif ($user != "account.php") |
24 | 24 | { |
25 | - $obUser = new User(); |
|
26 | - $row = $obUser->UserDetails($user, False); |
|
27 | - if($row != NULL): |
|
28 | - $userId = $row['login_id']; |
|
29 | - $details = Profile::getProfile($userId); |
|
30 | - if($details != NULL) |
|
31 | - $row = array_merge($row, $details); |
|
32 | - else |
|
33 | - header("Location:".URL."/error.php"); |
|
25 | + $obUser = new User(); |
|
26 | + $row = $obUser->UserDetails($user, False); |
|
27 | + if($row != NULL): |
|
28 | + $userId = $row['login_id']; |
|
29 | + $details = Profile::getProfile($userId); |
|
30 | + if($details != NULL) |
|
31 | + $row = array_merge($row, $details); |
|
32 | + else |
|
33 | + header("Location:".URL."/error.php"); |
|
34 | 34 | ?> |
35 | 35 | |
36 | 36 | <!Doctype html> |
@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | <div class="brief"> |
66 | 66 | <h1 id="name">Name: <?php echo $row['name']; ?></h1><br> |
67 | 67 | <?php foreach ($row as $key => $value) { |
68 | - if($key =='username' && $value != null) |
|
69 | - echo '<p>Username: '.$row["username"] .'</p><br>'; |
|
70 | - if($key == 'email' && $value != null) |
|
71 | - echo '<p>Email Id: '.$row["email"] .'</p><br>'; |
|
72 | - if($key == 'status' && $value != null) |
|
73 | - echo '<p>Status: '.$row["status"] .'</p><br>'; |
|
74 | - if($key == 'education' && $value != null) |
|
75 | - echo '<p>Education: '.$row["education"] .'</p><br>'; |
|
76 | - if($key == 'gender' && $value != null) |
|
77 | - echo '<p>Gender: '.$row["gender"] .'</p><br>'; |
|
78 | - } |
|
79 | - ?> |
|
68 | + if($key =='username' && $value != null) |
|
69 | + echo '<p>Username: '.$row["username"] .'</p><br>'; |
|
70 | + if($key == 'email' && $value != null) |
|
71 | + echo '<p>Email Id: '.$row["email"] .'</p><br>'; |
|
72 | + if($key == 'status' && $value != null) |
|
73 | + echo '<p>Status: '.$row["status"] .'</p><br>'; |
|
74 | + if($key == 'education' && $value != null) |
|
75 | + echo '<p>Education: '.$row["education"] .'</p><br>'; |
|
76 | + if($key == 'gender' && $value != null) |
|
77 | + echo '<p>Gender: '.$row["gender"] .'</p><br>'; |
|
78 | + } |
|
79 | + ?> |
|
80 | 80 | </div> |
81 | 81 | <?php if(Session::get('start') == $row['login_id']): ?> |
82 | 82 | <div class="edit"> |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | </div> |
87 | 87 | |
88 | 88 | <?php |
89 | - if(Session::get('start') == $row['login_id']): |
|
90 | - ?> |
|
89 | + if(Session::get('start') == $row['login_id']): |
|
90 | + ?> |
|
91 | 91 | |
92 | 92 | <div class="boxx" id="profile"> |
93 | 93 | <form method="post" action="../profile_generate.php"> |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | </form> |
103 | 103 | </div> |
104 | 104 | <?php |
105 | - endif; |
|
106 | - ?> |
|
105 | + endif; |
|
106 | + ?> |
|
107 | 107 | </div> |
108 | 108 | |
109 | 109 | <div class="footer"> |
@@ -116,13 +116,13 @@ discard block |
||
116 | 116 | </body> |
117 | 117 | </html> |
118 | 118 | <?php |
119 | - else: |
|
120 | - header("Location:".URL."/error.php"); |
|
121 | - endif; |
|
119 | + else: |
|
120 | + header("Location:".URL."/error.php"); |
|
121 | + endif; |
|
122 | 122 | } |
123 | 123 | else |
124 | 124 | { |
125 | - header("Location: ".URL); |
|
125 | + header("Location: ".URL); |
|
126 | 126 | } |
127 | 127 | ?> |
128 | 128 |
@@ -9,29 +9,29 @@ |
||
9 | 9 | $data = ''; |
10 | 10 | if(isset($_POST['submit'])) |
11 | 11 | { |
12 | - $data = Profile::getProfile($userId); |
|
13 | - if($data != NULL): |
|
14 | - $status = get($_POST['status'], $data['status']); |
|
15 | - $edu = get($_POST['education'], $data['education']); |
|
16 | - $gender = get($_POST['gender'], $data['gender']); |
|
17 | - $query = "UPDATE profile set status='$status', education='$edu', gender='$gender' where login_id = '$userId'"; |
|
18 | - if($result = $connect->query($query)) |
|
19 | - { |
|
20 | - header('Location:'.URL.'/account.php'); |
|
21 | - } |
|
22 | - else |
|
23 | - { |
|
24 | - header("Location:".URL."/error.php"); |
|
25 | - } |
|
26 | - endif; |
|
12 | + $data = Profile::getProfile($userId); |
|
13 | + if($data != NULL): |
|
14 | + $status = get($_POST['status'], $data['status']); |
|
15 | + $edu = get($_POST['education'], $data['education']); |
|
16 | + $gender = get($_POST['gender'], $data['gender']); |
|
17 | + $query = "UPDATE profile set status='$status', education='$edu', gender='$gender' where login_id = '$userId'"; |
|
18 | + if($result = $connect->query($query)) |
|
19 | + { |
|
20 | + header('Location:'.URL.'/account.php'); |
|
21 | + } |
|
22 | + else |
|
23 | + { |
|
24 | + header("Location:".URL."/error.php"); |
|
25 | + } |
|
26 | + endif; |
|
27 | 27 | } |
28 | 28 | else |
29 | 29 | { |
30 | - header("Location:".URL."/error.php"); |
|
30 | + header("Location:".URL."/error.php"); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function get($value, $default) |
34 | 34 | { |
35 | - $value = trim($value); |
|
36 | - return (isset($value) ? $value : $default); |
|
35 | + $value = trim($value); |
|
36 | + return (isset($value) ? $value : $default); |
|
37 | 37 | } |