@@ -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)) |
@@ -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 | ?> |
@@ -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 | ?> |
@@ -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 | } |