Completed
Push — master ( 0dfdea...ca2f25 )
by Ankit
02:37
created
cmd.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
 use Ratchet\WebSocket\WsServer;
8 8
 use ChatApp\Chat;
9 9
 
10
-$server =IoServer::factory(
10
+$server = IoServer::factory(
11 11
 	new HttpServer(
12 12
 		new WsServer(
13 13
 			new Chat()
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -8,12 +8,12 @@
 block discarded – undo
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();
Please login to merge, or discard this patch.
message.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 session_start();
3
-if(isset($_SESSION['start']) and empty($_GET['user']))
3
+if (isset($_SESSION['start']) and empty($_GET['user']))
4 4
 {
5 5
 ?>
6 6
 <!DOCTYPE html>
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
 <?php
132 132
 }
133
-else{
133
+else {
134 134
 	header('Location:http://www.localhost/openchat/login.php');
135 135
 }
136 136
 ?>
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -129,8 +129,7 @@
 block discarded – undo
129 129
 </html>
130 130
 
131 131
 <?php
132
-}
133
-else{
132
+} else{
134 133
 	header('Location:http://www.localhost/openchat/login.php');
135 134
 }
136 135
 ?>
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -131,6 +131,6 @@
 block discarded – undo
131 131
 <?php
132 132
 }
133 133
 else{
134
-	header('Location:http://localhost/openchat');
134
+    header('Location:http://localhost/openchat');
135 135
 }
136 136
 ?>
Please login to merge, or discard this patch.
src/Validate.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -33,6 +33,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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'";
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -4,35 +4,35 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace ChatApp;
3
-require_once (dirname(__DIR__) . '/config/database.php');
3
+require_once (dirname(__DIR__).'/config/database.php');
4 4
 
5 5
 class Validate
6 6
 {
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 		{
41 41
 			if ($result->num_rows>0) {
42 42
 				return 1;
43
+			} else {
44
+							return 0;
43 45
 			}
44
-			else
45
-				return 0;
46 46
 		}
47 47
 	}
48 48
 
@@ -52,9 +52,9 @@  discard block
 block discarded – undo
52 52
 		if ($result=$this->connect->query($query)) {
53 53
 			if ($result->num_rows>0) {
54 54
 				return 1;
55
+			} else {
56
+							return 0;
55 57
 			}
56
-			else
57
-				return 0;
58 58
 			
59 59
 		}
60 60
 	}
Please login to merge, or discard this patch.
config/database.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
18 18
     }
19 19
     $url = $http.$host.":".$port.$fol;
20 20
     return $url;
21
-  }
21
+    }
22 22
 ?>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
   // Define database connection constants
3 3
   define('DB_HOST', 'localhost');
4 4
   define('DB_USER', 'root');
5
-  define('DB_PASSWORD','');
5
+  define('DB_PASSWORD', '');
6 6
   define('DB_NAME', 'openchat');
7 7
   define('URL', URL());
8 8
 
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     $host = $_SERVER['SERVER_NAME'];
13 13
     $port = $_SERVER['SERVER_PORT'];
14 14
     $fol = "";
15
-    if(@$_SERVER['SERVER_ADDR']!=NULL)
15
+    if (@$_SERVER['SERVER_ADDR'] != NULL)
16 16
     {
17 17
         $fol = "/".explode('/', $_SERVER['PHP_SELF'])[1];
18 18
     }
Please login to merge, or discard this patch.
index.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 session_start();
3
-if(isset($_SESSION['start']))
3
+if (isset($_SESSION['start']))
4 4
 {
5 5
     header("Location: account.php");
6 6
 }
Please login to merge, or discard this patch.
src/Login.php 3 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace ChatApp;
4 4
 use ChatApp\Session;
5
-require_once (dirname(__DIR__) . '/config/database.php');
5
+require_once (dirname(__DIR__).'/config/database.php');
6 6
 
7 7
 class Login
8 8
 {
@@ -26,20 +26,20 @@  discard block
 block discarded – undo
26 26
 		$login = trim($login);
27 27
 		$password = trim($password);
28 28
 
29
-		if(empty($login))
29
+		if (empty($login))
30 30
 		{
31 31
 			$this->key = 1;
32 32
 			$this->error = array_merge($this->error, ["login" => " *Enter the login field"]);
33 33
 		}
34 34
 		elseif (preg_match("/^[@]{1}$/", $login))
35 35
 		{
36
-			if(filter_var($login, FILTER_VALIDATE_EMAIL) == false)
36
+			if (filter_var($login, FILTER_VALIDATE_EMAIL) == false)
37 37
 			{
38 38
 			$this->key = 1;
39 39
 			$this->error = array_merge($this->error, ["login" => " *Enter correct Email address"]);
40 40
 			}
41 41
 		}
42
-		if(empty($password)) {
42
+		if (empty($password)) {
43 43
 			$this->key = 1;
44 44
 			$this->error = array_merge($this->error, ["password" => " *Enter the password"]);
45 45
 		}
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 			$password = md5($password);
49 49
 		}
50 50
 
51
-		if($this->key == 0)
51
+		if ($this->key == 0)
52 52
 		{
53 53
 			$query = "SELECT * FROM login WHERE email = '$login' or username = '$login'";
54 54
 			if ($result = $this->connect->query($query))
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 					$row = $result->fetch_assoc();
59 59
 					$loginID = $row['login_id'];
60 60
 					$query = "SELECT id FROM register WHERE id = '$loginID' and password = '$password'";
61
-					if($result = $this->connect->query($query))
61
+					if ($result = $this->connect->query($query))
62 62
 					{
63 63
 						if ($result->num_rows > 0)
64 64
 						{
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
 		{
31 31
 			$this->key = 1;
32 32
 			$this->error = array_merge($this->error, ["login" => " *Enter the login field"]);
33
-		}
34
-		elseif (preg_match("/^[@]{1}$/", $login))
33
+		} elseif (preg_match("/^[@]{1}$/", $login))
35 34
 		{
36 35
 			if(filter_var($login, FILTER_VALIDATE_EMAIL) == false)
37 36
 			{
@@ -42,8 +41,7 @@  discard block
 block discarded – undo
42 41
 		if(empty($password)) {
43 42
 			$this->key = 1;
44 43
 			$this->error = array_merge($this->error, ["password" => " *Enter the password"]);
45
-		}
46
-		else
44
+		} else
47 45
 		{
48 46
 			$password = md5($password);
49 47
 		}
@@ -66,23 +64,20 @@  discard block
 block discarded – undo
66 64
 							return json_encode([
67 65
 								"location" => URL."/account.php"
68 66
 							]);
69
-						}
70
-						else
67
+						} else
71 68
 						{
72 69
 							$this->error = array_merge($this->error, ["password" => " *Invalid password"]);
73 70
 							return json_encode($this->error);
74 71
 						}
75 72
 					}
76
-				}
77
-				else
73
+				} else
78 74
 				{
79 75
 					$this->error = array_merge($this->error, ["login" => " *Invalid username or email"]);
80 76
 					return json_encode($this->error);
81 77
 				}
82 78
 			}
83 79
 
84
-		}
85
-		else
80
+		} else
86 81
 		{
87 82
 			return json_encode($this->error);
88 83
 		}
Please login to merge, or discard this patch.
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -7,83 +7,83 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Online.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 namespace ChatApp;
4
-require_once (dirname(__DIR__) . '/config/database.php');
4
+require_once (dirname(__DIR__).'/config/database.php');
5 5
 
6 6
 /**
7 7
 * For checking online status
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     {
14 14
         $connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
15 15
         $query = "Update login set login_status = 1 where login_id = '$userId'";
16
-        if(!$connect->query($query));
16
+        if (!$connect->query($query));
17 17
             echo $connect->error;
18 18
         $connect->close();
19 19
     }
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     {
23 23
         $connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
24 24
         $query = "Update login set login_status = 0 where login_id = '$userId'";
25
-        if(!$connect->query($query));
25
+        if (!$connect->query($query));
26 26
             echo $connect->error;
27 27
         $connect->close();
28 28
     }
Please login to merge, or discard this patch.
src/Profile.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 namespace ChatApp;
4
-require_once (dirname(__DIR__) . '/config/database.php');
4
+require_once (dirname(__DIR__).'/config/database.php');
5 5
 
6 6
 /**
7 7
 * For retreiving User Profile
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
         $connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
15 15
         $query = "SELECT * from profile where login_id = '$userId'";
16 16
         $result = $connect->query($query);
17
-        if($result->num_rows > 0)                   // if true
17
+        if ($result->num_rows > 0)                   // if true
18 18
         {
19 19
             $details = $result->fetch_assoc();
20 20
             return $details;
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,12 +14,13 @@
 block discarded – undo
14 14
         $connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
15 15
         $query = "SELECT * from profile where login_id = '$userId'";
16 16
         $result = $connect->query($query);
17
-        if($result->num_rows > 0)                   // if true
17
+        if($result->num_rows > 0) {
18
+            // if true
18 19
         {
19 20
             $details = $result->fetch_assoc();
20
-            return $details;
21 21
         }
22
-        else
22
+            return $details;
23
+        } else
23 24
         {
24 25
             return NULL;
25 26
         }
Please login to merge, or discard this patch.
logout.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require (__DIR__ . '/vendor/autoload.php');
3
+require (__DIR__.'/vendor/autoload.php');
4 4
 use ChatApp\Session;
5 5
 
6
-if(Session::get('start') != null)
6
+if (Session::get('start') != null)
7 7
 {
8 8
     Session::forget('start');
9 9
     header('Location: index.php');
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@
 block discarded – undo
12 12
         header('Location: ../../index.php');
13 13
     }
14 14
 
15
-}
16
-else
15
+} else
17 16
 {
18 17
 	echo "Please Login";
19 18
 }
Please login to merge, or discard this patch.