@@ -26,6 +26,9 @@ discard block |
||
26 | 26 | echo "New connection! ({$conn->resourceId})\n"; |
27 | 27 | } |
28 | 28 | |
29 | + /** |
|
30 | + * @param ConnectionInterface $conn |
|
31 | + */ |
|
29 | 32 | public function setID($conn) |
30 | 33 | { |
31 | 34 | session_id($conn->WebSocket->request->getCookies()['PHPSESSID']); |
@@ -126,30 +129,47 @@ discard block |
||
126 | 129 | return $obSidebar->LoadSideBar($data); |
127 | 130 | } |
128 | 131 | |
132 | + /** |
|
133 | + * @param string $data |
|
134 | + * @param boolean $para |
|
135 | + */ |
|
129 | 136 | public function onConversation($data, $para, $sessionId) |
130 | 137 | { |
131 | 138 | $obConversation = new Conversation($sessionId); |
132 | 139 | return $obConversation->ConversationLoad($data, $para); |
133 | 140 | } |
134 | 141 | |
142 | + /** |
|
143 | + * @param string $data |
|
144 | + * @param boolean $para |
|
145 | + */ |
|
135 | 146 | public function onReceiver($data, $para, $sessionId) |
136 | 147 | { |
137 | 148 | $obReceiver = new Receiver($sessionId); |
138 | 149 | return $obReceiver->ReceiverLoad($data, True); |
139 | 150 | } |
140 | 151 | |
152 | + /** |
|
153 | + * @param string $data |
|
154 | + */ |
|
141 | 155 | public function onSearch($data, $sessionId) |
142 | 156 | { |
143 | 157 | $obSearch = new Search($sessionId); |
144 | 158 | return $obSearch->SearchItem(json_decode($data)); |
145 | 159 | } |
146 | 160 | |
161 | + /** |
|
162 | + * @param string $data |
|
163 | + */ |
|
147 | 164 | public function onCompose($data, $sessionId) |
148 | 165 | { |
149 | 166 | $obCompose = new Compose($sessionId); |
150 | 167 | return $obCompose->SelectUser(json_decode($data)); |
151 | 168 | } |
152 | 169 | |
170 | + /** |
|
171 | + * @param string $data |
|
172 | + */ |
|
153 | 173 | public function onReply($data, $sessionId) |
154 | 174 | { |
155 | 175 | $obReply = new Reply($sessionId); |
@@ -90,6 +90,11 @@ |
||
90 | 90 | $this->connect->close(); |
91 | 91 | } |
92 | 92 | |
93 | + /** |
|
94 | + * @param string $identifier |
|
95 | + * @param string $reply |
|
96 | + * @param string $time |
|
97 | + */ |
|
93 | 98 | function UpdateMessages($query, $identifier, $reply, $id, $time) |
94 | 99 | { |
95 | 100 | if($result = $this->connect->query($query)) |
@@ -8,16 +8,16 @@ |
||
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(); |
20 | 20 | |
21 | 21 | |
22 | 22 | |
23 | - ?> |
|
24 | 23 | \ No newline at end of file |
24 | + ?> |
|
25 | 25 | \ No newline at end of file |
@@ -5,36 +5,36 @@ |
||
5 | 5 | $login_id=$_SESSION['start']; |
6 | 6 | if(isset($_POST['submit'])) |
7 | 7 | { |
8 | - $query="SELECT * from profile where login_id='$login_id'"; |
|
9 | - if($result=$connect->query($query)) |
|
10 | - { |
|
11 | - if($result->num_rows>0) |
|
12 | - { |
|
13 | - $row=$result->fetch_assoc(); |
|
14 | - } |
|
15 | - } |
|
16 | - if(trim($_POST['status'])) |
|
17 | - $status=$_POST['status']; |
|
18 | - else |
|
19 | - $status=$row['status']; |
|
20 | - if(trim($_POST['education'])) |
|
21 | - $edu=$_POST['education']; |
|
22 | - else |
|
23 | - $edu=$row['education']; |
|
24 | - if(isset($_POST['gender'])) |
|
25 | - $gender=$_POST['gender']; |
|
26 | - else |
|
27 | - $gender=$row['gender']; |
|
8 | + $query="SELECT * from profile where login_id='$login_id'"; |
|
9 | + if($result=$connect->query($query)) |
|
10 | + { |
|
11 | + if($result->num_rows>0) |
|
12 | + { |
|
13 | + $row=$result->fetch_assoc(); |
|
14 | + } |
|
15 | + } |
|
16 | + if(trim($_POST['status'])) |
|
17 | + $status=$_POST['status']; |
|
18 | + else |
|
19 | + $status=$row['status']; |
|
20 | + if(trim($_POST['education'])) |
|
21 | + $edu=$_POST['education']; |
|
22 | + else |
|
23 | + $edu=$row['education']; |
|
24 | + if(isset($_POST['gender'])) |
|
25 | + $gender=$_POST['gender']; |
|
26 | + else |
|
27 | + $gender=$row['gender']; |
|
28 | 28 | |
29 | - $query="UPDATE profile set status='$status', education='$edu', gender='$gender' where login_id='$login_id'"; |
|
30 | - if($result=$connect->query($query)) |
|
31 | - { |
|
32 | - header('Location: account.php'); |
|
33 | - } |
|
34 | - else |
|
35 | - { |
|
36 | - die("error"); |
|
37 | - } |
|
29 | + $query="UPDATE profile set status='$status', education='$edu', gender='$gender' where login_id='$login_id'"; |
|
30 | + if($result=$connect->query($query)) |
|
31 | + { |
|
32 | + header('Location: account.php'); |
|
33 | + } |
|
34 | + else |
|
35 | + { |
|
36 | + die("error"); |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | ?> |
41 | 41 | \ No newline at end of file |
@@ -33,6 +33,9 @@ discard block |
||
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
36 | + /** |
|
37 | + * @param string $email |
|
38 | + */ |
|
36 | 39 | function validate_email_in_db($email) |
37 | 40 | { |
38 | 41 | $query="SELECT login_id FROM login WHERE email='$email'"; |
@@ -46,6 +49,9 @@ discard block |
||
46 | 49 | } |
47 | 50 | } |
48 | 51 | |
52 | + /** |
|
53 | + * @param string $username |
|
54 | + */ |
|
49 | 55 | function validate_username_in_db($username) |
50 | 56 | { |
51 | 57 | $query="SELECT login_id FROM login WHERE username='$username'"; |
@@ -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 | } |
@@ -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 | ?> |
@@ -12,26 +12,26 @@ discard block |
||
12 | 12 | $userId = $session->get('start'); |
13 | 13 | if($userId != null and $user == "account.php") |
14 | 14 | { |
15 | - $obUser = new User(); |
|
16 | - $row = $obUser->UserDetails($userId, True); |
|
15 | + $obUser = new User(); |
|
16 | + $row = $obUser->UserDetails($userId, True); |
|
17 | 17 | |
18 | - if($row != NULL) |
|
19 | - { |
|
20 | - $location = URL . "/account.php/". $row['username']; |
|
21 | - header("Location:".$location); |
|
22 | - } |
|
18 | + if($row != NULL) |
|
19 | + { |
|
20 | + $location = URL . "/account.php/". $row['username']; |
|
21 | + header("Location:".$location); |
|
22 | + } |
|
23 | 23 | } |
24 | 24 | elseif ($user != "account.php") |
25 | 25 | { |
26 | - $obUser = new User(); |
|
27 | - $row = $obUser->UserDetails($user, False); |
|
28 | - if($row != NULL): |
|
29 | - $userId = $row['login_id']; |
|
30 | - $details = Profile::getProfile($userId); |
|
31 | - if($details != NULL) |
|
32 | - $row = array_merge($row, $details); |
|
33 | - else |
|
34 | - header("Location:".URL."/error.php"); |
|
26 | + $obUser = new User(); |
|
27 | + $row = $obUser->UserDetails($user, False); |
|
28 | + if($row != NULL): |
|
29 | + $userId = $row['login_id']; |
|
30 | + $details = Profile::getProfile($userId); |
|
31 | + if($details != NULL) |
|
32 | + $row = array_merge($row, $details); |
|
33 | + else |
|
34 | + header("Location:".URL."/error.php"); |
|
35 | 35 | ?> |
36 | 36 | |
37 | 37 | <!Doctype html> |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | <div class="brief"> |
67 | 67 | <h1 id="name">Name: <?php echo $row['name']; ?></h1><br> |
68 | 68 | <?php foreach ($row as $key => $value) { |
69 | - if($key =='username' and $value != null) |
|
70 | - echo '<p>Username: '.$row["username"] .'</p><br>'; |
|
71 | - if($key == 'email' and $value != null) |
|
72 | - echo '<p>Email Id: '.$row["email"] .'</p><br>'; |
|
73 | - if($key == 'status' and $value != null) |
|
74 | - echo '<p>Status: '.$row["status"] .'</p><br>'; |
|
75 | - if($key == 'education' and $value != null) |
|
76 | - echo '<p>Education: '.$row["education"] .'</p><br>'; |
|
77 | - if($key == 'gender' and $value != null) |
|
78 | - echo '<p>Gender: '.$row["gender"] .'</p><br>'; |
|
79 | - } |
|
80 | - ?> |
|
69 | + if($key =='username' and $value != null) |
|
70 | + echo '<p>Username: '.$row["username"] .'</p><br>'; |
|
71 | + if($key == 'email' and $value != null) |
|
72 | + echo '<p>Email Id: '.$row["email"] .'</p><br>'; |
|
73 | + if($key == 'status' and $value != null) |
|
74 | + echo '<p>Status: '.$row["status"] .'</p><br>'; |
|
75 | + if($key == 'education' and $value != null) |
|
76 | + echo '<p>Education: '.$row["education"] .'</p><br>'; |
|
77 | + if($key == 'gender' and $value != null) |
|
78 | + echo '<p>Gender: '.$row["gender"] .'</p><br>'; |
|
79 | + } |
|
80 | + ?> |
|
81 | 81 | </div> |
82 | 82 | <?php if($session->get('start') == $row['login_id']): ?> |
83 | 83 | <div class="edit"> |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | </div> |
88 | 88 | |
89 | 89 | <?php |
90 | - if($session->get('start') == $row['login_id']): |
|
91 | - ?> |
|
90 | + if($session->get('start') == $row['login_id']): |
|
91 | + ?> |
|
92 | 92 | |
93 | 93 | <div class="boxx" id="profile"> |
94 | 94 | <form method="post" action="../profile_generate.php"> |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | </form> |
104 | 104 | </div> |
105 | 105 | <?php |
106 | - endif; |
|
107 | - ?> |
|
106 | + endif; |
|
107 | + ?> |
|
108 | 108 | </div> |
109 | 109 | |
110 | 110 | <div class="footer"> |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | </body> |
118 | 118 | </html> |
119 | 119 | <?php |
120 | - else: |
|
121 | - header("Location:".URL."/error.php"); |
|
122 | - endif; |
|
120 | + else: |
|
121 | + header("Location:".URL."/error.php"); |
|
122 | + endif; |
|
123 | 123 | } |
124 | 124 | else |
125 | 125 | { |
126 | - header("Location: ".URL); |
|
126 | + header("Location: ".URL); |
|
127 | 127 | } |
128 | 128 | ?> |
129 | 129 |
@@ -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 | ?> |
@@ -7,85 +7,85 @@ |
||
7 | 7 | class Login |
8 | 8 | { |
9 | 9 | |
10 | - protected $key; |
|
11 | - protected $error; |
|
12 | - protected $connect; |
|
13 | - protected $session; |
|
10 | + protected $key; |
|
11 | + protected $error; |
|
12 | + protected $connect; |
|
13 | + protected $session; |
|
14 | 14 | |
15 | - public function __construct() |
|
16 | - { |
|
17 | - $this->key = 0; |
|
18 | - $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
|
19 | - $this->error = array(); |
|
20 | - $this->session = new Session(); |
|
21 | - } |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + $this->key = 0; |
|
18 | + $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
|
19 | + $this->error = array(); |
|
20 | + $this->session = new Session(); |
|
21 | + } |
|
22 | 22 | |
23 | - public function authLogin($login, $password) |
|
24 | - { |
|
23 | + public function authLogin($login, $password) |
|
24 | + { |
|
25 | 25 | |
26 | - $login = trim($login); |
|
27 | - $password = trim($password); |
|
26 | + $login = trim($login); |
|
27 | + $password = trim($password); |
|
28 | 28 | |
29 | - if(empty($login)) |
|
30 | - { |
|
31 | - $this->key = 1; |
|
32 | - $this->error = array_merge($this->error, ["login" => " *Enter the login field"]); |
|
33 | - } |
|
34 | - elseif (preg_match("/^[@]{1}$/", $login)) |
|
35 | - { |
|
36 | - if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
|
37 | - { |
|
38 | - $this->key = 1; |
|
39 | - $this->error = array_merge($this->error, ["login" => " *Enter correct Email address"]); |
|
40 | - } |
|
41 | - } |
|
42 | - if(empty($password)) { |
|
43 | - $this->key = 1; |
|
44 | - $this->error = array_merge($this->error, ["password" => " *Enter the password"]); |
|
45 | - } |
|
46 | - else |
|
47 | - { |
|
48 | - $password = md5($password); |
|
49 | - } |
|
29 | + if(empty($login)) |
|
30 | + { |
|
31 | + $this->key = 1; |
|
32 | + $this->error = array_merge($this->error, ["login" => " *Enter the login field"]); |
|
33 | + } |
|
34 | + elseif (preg_match("/^[@]{1}$/", $login)) |
|
35 | + { |
|
36 | + if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
|
37 | + { |
|
38 | + $this->key = 1; |
|
39 | + $this->error = array_merge($this->error, ["login" => " *Enter correct Email address"]); |
|
40 | + } |
|
41 | + } |
|
42 | + if(empty($password)) { |
|
43 | + $this->key = 1; |
|
44 | + $this->error = array_merge($this->error, ["password" => " *Enter the password"]); |
|
45 | + } |
|
46 | + else |
|
47 | + { |
|
48 | + $password = md5($password); |
|
49 | + } |
|
50 | 50 | |
51 | - if($this->key == 0) |
|
52 | - { |
|
53 | - $query = "SELECT * FROM login WHERE email = '$login' or username = '$login'"; |
|
54 | - if ($result = $this->connect->query($query)) |
|
55 | - { |
|
56 | - if ($result->num_rows > 0) |
|
57 | - { |
|
58 | - $row = $result->fetch_assoc(); |
|
59 | - $loginID = $row['login_id']; |
|
60 | - $query = "SELECT id FROM register WHERE id = '$loginID' and password = '$password'"; |
|
61 | - if($result = $this->connect->query($query)) |
|
62 | - { |
|
63 | - if ($result->num_rows > 0) |
|
64 | - { |
|
65 | - $this->session->put('start', $loginID); |
|
66 | - return json_encode([ |
|
67 | - "location" => URL."/account.php" |
|
68 | - ]); |
|
69 | - } |
|
70 | - else |
|
71 | - { |
|
72 | - $this->error = array_merge($this->error, ["password" => " *Invalid password"]); |
|
73 | - return json_encode($this->error); |
|
74 | - } |
|
75 | - } |
|
76 | - } |
|
77 | - else |
|
78 | - { |
|
79 | - $this->error = array_merge($this->error, ["login" => " *Invalid username or email"]); |
|
80 | - return json_encode($this->error); |
|
81 | - } |
|
82 | - } |
|
51 | + if($this->key == 0) |
|
52 | + { |
|
53 | + $query = "SELECT * FROM login WHERE email = '$login' or username = '$login'"; |
|
54 | + if ($result = $this->connect->query($query)) |
|
55 | + { |
|
56 | + if ($result->num_rows > 0) |
|
57 | + { |
|
58 | + $row = $result->fetch_assoc(); |
|
59 | + $loginID = $row['login_id']; |
|
60 | + $query = "SELECT id FROM register WHERE id = '$loginID' and password = '$password'"; |
|
61 | + if($result = $this->connect->query($query)) |
|
62 | + { |
|
63 | + if ($result->num_rows > 0) |
|
64 | + { |
|
65 | + $this->session->put('start', $loginID); |
|
66 | + return json_encode([ |
|
67 | + "location" => URL."/account.php" |
|
68 | + ]); |
|
69 | + } |
|
70 | + else |
|
71 | + { |
|
72 | + $this->error = array_merge($this->error, ["password" => " *Invalid password"]); |
|
73 | + return json_encode($this->error); |
|
74 | + } |
|
75 | + } |
|
76 | + } |
|
77 | + else |
|
78 | + { |
|
79 | + $this->error = array_merge($this->error, ["login" => " *Invalid username or email"]); |
|
80 | + return json_encode($this->error); |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - } |
|
85 | - else |
|
86 | - { |
|
87 | - return json_encode($this->error); |
|
88 | - } |
|
89 | - $this->connect->close(); |
|
90 | - } |
|
84 | + } |
|
85 | + else |
|
86 | + { |
|
87 | + return json_encode($this->error); |
|
88 | + } |
|
89 | + $this->connect->close(); |
|
90 | + } |
|
91 | 91 | } |