Test Setup Failed
Push — master ( 027aaa...a87e27 )
by Ankit
02:41
created
src/Models/message.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 
9 9
 class Message extends Model
10 10
 {
11
-    protected $table='message';
11
+    protected $table = 'message';
12 12
 
13 13
     protected $fillable = ['identifier_message_number', 'message', 'sent_by', 'time'];
14 14
 }
Please login to merge, or discard this patch.
src/User.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 
4 4
 namespace ChatApp;
5
-require_once (dirname(__DIR__) . '/database.php');
5
+require_once (dirname(__DIR__).'/database.php');
6 6
 
7 7
 /**
8 8
 * For retreiving User Information
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
 
22 22
     function UserDetails($id, $para)
23 23
     {
24
-        if($para == True)
24
+        if ($para == True)
25 25
             $this->query = "SELECT * from login where login_id = '$id'";
26 26
         else
27 27
             $this->query = "SELECT * from login where username = '$id'";
28 28
         $this->result = $this->connect->query($this->query);
29
-        if($this->result->num_rows > 0)                   // if true
29
+        if ($this->result->num_rows > 0)                   // if true
30 30
         {
31 31
             $this->details = $this->result->fetch_assoc();
32 32
             return $this->details;
Please login to merge, or discard this patch.
Braces   +9 added lines, -7 removed lines patch added patch discarded remove patch
@@ -21,17 +21,19 @@
 block discarded – undo
21 21
 
22 22
     function UserDetails($id, $para)
23 23
     {
24
-        if($para == True)
25
-            $this->query = "SELECT * from login where login_id = '$id'";
26
-        else
27
-            $this->query = "SELECT * from login where username = '$id'";
24
+        if($para == True) {
25
+                    $this->query = "SELECT * from login where login_id = '$id'";
26
+        } else {
27
+                    $this->query = "SELECT * from login where username = '$id'";
28
+        }
28 29
         $this->result = $this->connect->query($this->query);
29
-        if($this->result->num_rows > 0)                   // if true
30
+        if($this->result->num_rows > 0) {
31
+            // if true
30 32
         {
31 33
             $this->details = $this->result->fetch_assoc();
32
-            return $this->details;
33 34
         }
34
-        else
35
+            return $this->details;
36
+        } else
35 37
         {
36 38
             return NULL;
37 39
         }
Please login to merge, or discard this patch.
src/Conversation.php 2 patches
Spacing   +12 added lines, -12 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__) . '/database.php');
4
+require_once (dirname(__DIR__).'/database.php');
5 5
 use ChatApp\Time;
6 6
 use ChatApp\User;
7 7
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
     {
31 31
 
32 32
         $flag = 1;
33
-        if(isset($_SESSION['start']) && isset($msg))
33
+        if (isset($_SESSION['start']) && isset($msg))
34 34
         {
35 35
             $add_load = 0;
36 36
             $id = $_SESSION['start'];
@@ -40,25 +40,25 @@  discard block
 block discarded – undo
40 40
 
41 41
             $fetch = $this->obUser->UserDetails($username, $para);
42 42
 
43
-            if($fetch != NULL)
43
+            if ($fetch != NULL)
44 44
             {
45 45
                 $login_id = (int)$fetch['login_id'];
46 46
 
47 47
                 // Unique Identifier
48
-                if($login_id > $id)
48
+                if ($login_id > $id)
49 49
                     $identifier = $id.':'.$login_id;
50 50
                 else
51 51
                     $identifier = $login_id.':'.$id;
52 52
 
53 53
                 $query = "SELECT total_messages from total_message where identifier = '$identifier'";
54
-                if($result = $this->connect->query($query))
54
+                if ($result = $this->connect->query($query))
55 55
                 {
56
-                    if($result->num_rows > 0)
56
+                    if ($result->num_rows > 0)
57 57
                     {
58 58
                         $total = $result->fetch_assoc();
59 59
                         $total = $total['total_messages'];
60
-                        if($total - $load > 0)
61
-                            if($total - $load > 10)
60
+                        if ($total - $load > 0)
61
+                            if ($total - $load > 10)
62 62
                                 $add_load = $load + 10;
63 63
                             else
64 64
                                 $add_load = $total;
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
                 }
67 67
 
68 68
                 $query = "SELECT message, time, sent_by FROM messages WHERE identifier_message_number = '$identifier' ORDER BY id DESC limit ".$load;
69
-                if($result = $this->connect->query($query))
69
+                if ($result = $this->connect->query($query))
70 70
                 {
71
-                    if($result->num_rows > 0)
71
+                    if ($result->num_rows > 0)
72 72
                     {
73
-                        while($row = $result->fetch_assoc())
73
+                        while ($row = $result->fetch_assoc())
74 74
                         {
75 75
                             $row['time'] = $this->obTime->TimeConversion($row['time']);
76
-                            $row = array_merge($row,['start' => $id]);
76
+                            $row = array_merge($row, ['start' => $id]);
77 77
                             $this->array = array_merge($this->array, [$row]);
78 78
                         }
79 79
 
Please login to merge, or discard this patch.
Braces   +14 added lines, -16 removed lines patch added patch discarded remove patch
@@ -45,10 +45,11 @@  discard block
 block discarded – undo
45 45
                 $login_id = (int)$fetch['login_id'];
46 46
 
47 47
                 // Unique Identifier
48
-                if($login_id > $id)
49
-                    $identifier = $id.':'.$login_id;
50
-                else
51
-                    $identifier = $login_id.':'.$id;
48
+                if($login_id > $id) {
49
+                                    $identifier = $id.':'.$login_id;
50
+                } else {
51
+                                    $identifier = $login_id.':'.$id;
52
+                }
52 53
 
53 54
                 $query = "SELECT total_messages from total_message where identifier = '$identifier'";
54 55
                 if($result = $this->connect->query($query))
@@ -57,11 +58,12 @@  discard block
 block discarded – undo
57 58
                     {
58 59
                         $total = $result->fetch_assoc();
59 60
                         $total = $total['total_messages'];
60
-                        if($total - $load > 0)
61
-                            if($total - $load > 10)
61
+                        if($total - $load > 0) {
62
+                                                    if($total - $load > 10)
62 63
                                 $add_load = $load + 10;
63
-                            else
64
-                                $add_load = $total;
64
+                        } else {
65
+                                                            $add_load = $total;
66
+                            }
65 67
                     }
66 68
                 }
67 69
 
@@ -79,23 +81,19 @@  discard block
 block discarded – undo
79 81
 
80 82
                         $this->array = array_merge([['name' => $fetch['name'], 'username' => $fetch['username'], 'id' => $fetch['login_id'], 'load' => $add_load, 'type' => 1]], $this->array);
81 83
                         return json_encode($this->array);
82
-                    }
83
-                    else
84
+                    } else
84 85
                     {
85 86
                         return json_encode([['name' => $fetch['name'], 'username' => $fetch['username'], 'id' => $fetch['login_id'], 'type' => 0]]);
86 87
                     }
87
-                }
88
-                else
88
+                } else
89 89
                 {
90 90
                     echo "Query Failed";
91 91
                 }
92
-            }
93
-            else
92
+            } else
94 93
             {
95 94
                 echo "Query Failed";
96 95
             }
97
-        }
98
-        else
96
+        } else
99 97
         {
100 98
             header('Location:../login.php');
101 99
         }
Please login to merge, or discard this patch.
src/Search.php 2 patches
Spacing   +9 added lines, -9 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__) . '/database.php');
4
+require_once (dirname(__DIR__).'/database.php');
5 5
 use ChatApp\Time;
6 6
 
7 7
 /**
@@ -28,24 +28,24 @@  discard block
 block discarded – undo
28 28
     {
29 29
         $suggestion = $suggestion->value;
30 30
         $flag = 0;
31
-        if(isset($_SESSION['start']) && isset($suggestion))
31
+        if (isset($_SESSION['start']) && isset($suggestion))
32 32
         {
33 33
             $id = $_SESSION['start'];
34 34
             $suggestion = trim($suggestion);
35
-            if($suggestion != "")
35
+            if ($suggestion != "")
36 36
             {
37 37
                 $query = "SELECT * FROM login where login_id != '$id' and name like '$suggestion%' ORDER BY name ASC";
38
-                if($result = $this->connect->query($query))
38
+                if ($result = $this->connect->query($query))
39 39
                 {
40
-                    if($result->num_rows > 0)
40
+                    if ($result->num_rows > 0)
41 41
                     {
42
-                        while($row = $result->fetch_assoc())
42
+                        while ($row = $result->fetch_assoc())
43 43
                         {
44 44
                             $check_id = $row["login_id"];
45 45
                             $query = "SELECT * from total_message where (user1 = '$check_id' and user2 = '$id') or (user2 = '$check_id' and user1 = '$id')";
46
-                            if($result1 = $this->connect->query($query))
46
+                            if ($result1 = $this->connect->query($query))
47 47
                             {
48
-                                if($result1->num_rows > 0)
48
+                                if ($result1->num_rows > 0)
49 49
                                 {
50 50
                                     $fetch = $result1->fetch_assoc();
51 51
                                     $fetch['time'] = $this->obTime->TimeConversion($fetch['time']);
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
                         }
58 58
                     }
59 59
                 }
60
-                if($flag != 0)
60
+                if ($flag != 0)
61 61
                 {
62 62
                     $this->array = array_merge([], ["Search" => $this->array]);
63 63
                     return json_encode($this->array);
Please login to merge, or discard this patch.
Braces   +4 added lines, -6 removed lines patch added patch discarded remove patch
@@ -61,16 +61,14 @@
 block discarded – undo
61 61
                 {
62 62
                     $this->array = array_merge([], ["Search" => $this->array]);
63 63
                     return json_encode($this->array);
64
+                } else {
65
+                                    return json_encode(["Search" => "Not Found"]);
64 66
                 }
65
-                else
66
-                    return json_encode(["Search" => "Not Found"]);
67
-            }
68
-            else
67
+            } else
69 68
             {
70 69
                 return json_encode(["Search" => "Not Found"]);
71 70
             }
72
-        }
73
-        else
71
+        } else
74 72
         {
75 73
             return json_encode(["Search" => "Not Found"]);
76 74
         }
Please login to merge, or discard this patch.
cmd.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@
 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();
20 20
 
21 21
 
22 22
 
23
- ?>
24 23
\ No newline at end of file
24
+    ?>
25 25
\ No newline at end of file
Please login to merge, or discard this patch.
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.
message.php 3 patches
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://www.localhost/openchat/login.php');
134
+    header('Location:http://www.localhost/openchat/login.php');
135 135
 }
136 136
 ?>
Please login to merge, or discard this patch.
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.
registration-module/ajax/validate_register.php 3 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -3,17 +3,17 @@
 block discarded – undo
3 3
 require_once '../source/class.register.php';
4 4
 if(isset($_POST['q']))
5 5
 {
6
-	$register_field=json_decode($_POST['q']);
7
-	$name=$register_field->name;
8
-	$email=$register_field->email;
9
-	$username=$register_field->username;
10
-	$mob=$register_field->mob;
11
-	$password=$register_field->password;
12
-	$ob = new register();
13
-	$result=$ob->_register($name,$email,$username,$password,$mob);
14
-	if(isset($result))
15
-		echo $result;
16
-	else
17
-		echo json_encode([]);
6
+    $register_field=json_decode($_POST['q']);
7
+    $name=$register_field->name;
8
+    $email=$register_field->email;
9
+    $username=$register_field->username;
10
+    $mob=$register_field->mob;
11
+    $password=$register_field->password;
12
+    $ob = new register();
13
+    $result=$ob->_register($name,$email,$username,$password,$mob);
14
+    if(isset($result))
15
+        echo $result;
16
+    else
17
+        echo json_encode([]);
18 18
 }
19 19
 ?>
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@
 block discarded – undo
1 1
 <?php
2 2
 session_start();
3 3
 require_once '../source/class.register.php';
4
-if(isset($_POST['q']))
4
+if (isset($_POST['q']))
5 5
 {
6
-	$register_field=json_decode($_POST['q']);
7
-	$name=$register_field->name;
8
-	$email=$register_field->email;
9
-	$username=$register_field->username;
10
-	$mob=$register_field->mob;
11
-	$password=$register_field->password;
6
+	$register_field = json_decode($_POST['q']);
7
+	$name = $register_field->name;
8
+	$email = $register_field->email;
9
+	$username = $register_field->username;
10
+	$mob = $register_field->mob;
11
+	$password = $register_field->password;
12 12
 	$ob = new register();
13
-	$result=$ob->_register($name,$email,$username,$password,$mob);
14
-	if(isset($result))
13
+	$result = $ob->_register($name, $email, $username, $password, $mob);
14
+	if (isset($result))
15 15
 		echo $result;
16 16
 	else
17 17
 		echo json_encode([]);
Please login to merge, or discard this patch.
Braces   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,9 +8,10 @@
 block discarded – undo
8 8
 	$password=$login_field->password;
9 9
 	$ob = new login();
10 10
 	$result=$ob->_login($login,$password);
11
-	if(isset($result))
12
-		echo $result;
13
-	else
14
-		echo json_encode([]);
15
-}
11
+	if(isset($result)) {
12
+			echo $result;
13
+	} else {
14
+			echo json_encode([]);
15
+	}
16
+	}
16 17
 ?>
17 18
\ No newline at end of file
Please login to merge, or discard this patch.
registration-module/ajax/validate_login.php 3 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -3,14 +3,14 @@
 block discarded – undo
3 3
 require_once '../source/class.login.php';
4 4
 if(isset($_POST['q']))
5 5
 {
6
-	$login_field=json_decode($_POST['q']);
7
-	$login=$login_field->login;
8
-	$password=$login_field->password;
9
-	$ob = new login();
10
-	$result=$ob->_login($login,$password);
11
-	if(isset($result))
12
-		echo $result;
13
-	else
14
-		echo json_encode([]);
6
+    $login_field=json_decode($_POST['q']);
7
+    $login=$login_field->login;
8
+    $password=$login_field->password;
9
+    $ob = new login();
10
+    $result=$ob->_login($login,$password);
11
+    if(isset($result))
12
+        echo $result;
13
+    else
14
+        echo json_encode([]);
15 15
 }
16 16
 ?>
17 17
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@
 block discarded – undo
1 1
 <?php
2 2
 session_start();
3 3
 require_once '../source/class.login.php';
4
-if(isset($_POST['q']))
4
+if (isset($_POST['q']))
5 5
 {
6
-	$login_field=json_decode($_POST['q']);
7
-	$login=$login_field->login;
8
-	$password=$login_field->password;
6
+	$login_field = json_decode($_POST['q']);
7
+	$login = $login_field->login;
8
+	$password = $login_field->password;
9 9
 	$ob = new login();
10
-	$result=$ob->_login($login,$password);
11
-	if(isset($result))
10
+	$result = $ob->_login($login, $password);
11
+	if (isset($result))
12 12
 		echo $result;
13 13
 	else
14 14
 		echo json_encode([]);
Please login to merge, or discard this patch.
Braces   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,9 +8,10 @@
 block discarded – undo
8 8
 	$password=$login_field->password;
9 9
 	$ob = new login();
10 10
 	$result=$ob->_login($login,$password);
11
-	if(isset($result))
12
-		echo $result;
13
-	else
14
-		echo json_encode([]);
15
-}
11
+	if(isset($result)) {
12
+			echo $result;
13
+	} else {
14
+			echo json_encode([]);
15
+	}
16
+	}
16 17
 ?>
17 18
\ No newline at end of file
Please login to merge, or discard this patch.
registration-module/source/class.register.php 3 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -5,36 +5,36 @@  discard block
 block discarded – undo
5 5
 
6 6
 class register
7 7
 {
8
-	private $array_error;
9
-	private $name;
10
-	private $email;
11
-	private $username;
12
-	private $password;
13
-	private $mob;
14
-	private $key;
15
-	private $ob;
16
-	private $connect;
17
-
18
-	function __construct()
19
-	{
20
-		$this->array_error=array();
21
-		$this->key=0;
22
-		$this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
23
-		$this->ob=new validate();
24
-
25
-
26
-		$query="CREATE TABLE IF NOT EXISTS register (
8
+    private $array_error;
9
+    private $name;
10
+    private $email;
11
+    private $username;
12
+    private $password;
13
+    private $mob;
14
+    private $key;
15
+    private $ob;
16
+    private $connect;
17
+
18
+    function __construct()
19
+    {
20
+        $this->array_error=array();
21
+        $this->key=0;
22
+        $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
23
+        $this->ob=new validate();
24
+
25
+
26
+        $query="CREATE TABLE IF NOT EXISTS register (
27 27
 			id int primary key auto_increment unique not null,
28 28
 			email varchar(255) unique not null,
29 29
 			username varchar(255) unique not null,
30 30
 			password varchar(255) not null
31 31
 			) ENGINE=INNODB;";
32 32
 
33
-		if (!$this->connect->query($query)) {
34
-			echo "Table is not created || Query failed";
35
-		}
33
+        if (!$this->connect->query($query)) {
34
+            echo "Table is not created || Query failed";
35
+        }
36 36
 
37
-			$query="CREATE TABLE IF NOT EXISTS login (
37
+            $query="CREATE TABLE IF NOT EXISTS login (
38 38
 			login_id int primary key not null,
39 39
 			name varchar(255) not null,
40 40
 			email varchar(255) unique not null,
@@ -44,121 +44,121 @@  discard block
 block discarded – undo
44 44
 			FOREIGN KEY (login_id) REFERENCES register(id)
45 45
 			) ENGINE=INNODB;";
46 46
 
47
-		if (!$this->connect->query($query)) {
48
-			echo "Table is not created || Query failed";
49
-		}
47
+        if (!$this->connect->query($query)) {
48
+            echo "Table is not created || Query failed";
49
+        }
50 50
 
51
-		$query="CREATE TABLE IF NOT EXISTS profile (
51
+        $query="CREATE TABLE IF NOT EXISTS profile (
52 52
 		login_id int primary key not null unique,
53 53
 		status text,
54 54
 		education text,
55 55
 		gender varchar(10)
56 56
 		) ENGINE=INNODB;";
57 57
 
58
-		if (!$this->connect->query($query)) {
59
-			echo "Table is not created || Query failed";
60
-		}
61
-
62
-	}
63
-
64
-	function _register($name,$email,$username,$password,$mob)
65
-	{
66
-		$this->name=trim($name);
67
-		$this->email=trim($email);
68
-		$this->username=trim($username);
69
-		$this->password=trim($password);
70
-		$this->mob=trim($mob);
71
-		if (empty($this->name)) {
72
-			$this->key=1;
73
-			$this->array_error=array_merge($this->array_error,["name"=>"Enter the name"]);
74
-		}
75
-
76
-		if(empty($this->email)) {
77
-			$this->key=1;
78
-			$this->array_error=array_merge($this->array_error,["email"=>"Enter the email address"]);
79
-		}
80
-		elseif(filter_var($this->email,FILTER_VALIDATE_EMAIL)== false) {
81
-			$this->key=1;
82
-			$this->array_error=array_merge($this->array_error,["email"=>"Enter correct Email address"]);
83
-		}
84
-		else
85
-		{
86
-			if($this->ob->validate_email_in_db($this->email))
87
-			{
88
-				$this->key=1;
89
-				$this->array_error=array_merge($this->array_error,["email"=>"Email is already registered"]);
90
-			}
91
-		}
92
-
93
-		if(empty($this->username)) {
94
-			$this->key=1;
95
-			$this->array_error=array_merge($this->array_error,["username"=>"Enter the username"]);
96
-		}
97
-		else
98
-		{
99
-			if($this->ob->validate_username_in_db($this->username))
100
-			{
101
-				$this->key=1;
102
-				$this->array_error=array_merge($this->array_error,["username"=>"Username is already registered"]);
103
-			}
104
-		}
105
-
106
-		if(empty($this->password)) {
107
-			$this->key=1;
108
-			$this->array_error=array_merge($this->array_error,["password"=>"Enter the password"]);
109
-		}
110
-
111
-		if(empty($this->mob)) {
112
-			$this->key=1;
113
-			$this->array_error=array_merge($this->array_error,["mob"=>"Enter the Mobile Number"]);
114
-		}
115
-		elseif (!preg_match("/^[0-9]{10}$/",$this->mob)) {
116
-			$this->key=1;
117
-			$this->array_error=array_merge($this->array_error,["mob"=>"Enter correct Mobile Number"]);
118
-		}
119
-
120
-		if($this->key==1)
121
-		{
122
-			return json_encode($this->array_error);
123
-		}
124
-		else
125
-		{
126
-			$this->key=0;
127
-			$pass=md5($this->password);
128
-			$query="INSERT INTO register VALUES(null,'$this->email','$this->username','$pass')";
129
-			if(!$this->connect->query($query)) {
130
-				$this->key=1;
131
-				echo "You are not registered || Error in registration2";
132
-			}
133
-			else
134
-			{
135
-				$query="SELECT id FROM register WHERE email='$this->email'";
136
-				if($result=$this->connect->query($query)) {
137
-					$row=$result->fetch_assoc();
138
-					$id=$row['id'];
139
-
140
-					$query="INSERT INTO login VALUES('$id','$this->name','$this->email','$this->username','$this->mob','1')";
141
-					if(!$this->connect->query($query)) {
142
-						$this->key=1;
143
-						echo "You are not registered || Error in registration1";
144
-					}
145
-					$join="Joined OpenChat";
146
-					$query="INSERT INTO profile VALUES('$id','$join','$join','')";
147
-					if(!$this->connect->query($query)) {
148
-						$this->key=1;
149
-						echo "You are not updated || Error in profile";
150
-					}
151
-				}
152
-			}
153
-		}
154
-		if ($this->key==0) {
155
-			$_SESSION['start']=$id;
156
-			return json_encode(["location"=>"http://localhost/openchat/account.php"]);
157
-		}
158
-		else
159
-		{
160
-			return json_encode($this->array_error);
161
-		}
162
-	}
58
+        if (!$this->connect->query($query)) {
59
+            echo "Table is not created || Query failed";
60
+        }
61
+
62
+    }
63
+
64
+    function _register($name,$email,$username,$password,$mob)
65
+    {
66
+        $this->name=trim($name);
67
+        $this->email=trim($email);
68
+        $this->username=trim($username);
69
+        $this->password=trim($password);
70
+        $this->mob=trim($mob);
71
+        if (empty($this->name)) {
72
+            $this->key=1;
73
+            $this->array_error=array_merge($this->array_error,["name"=>"Enter the name"]);
74
+        }
75
+
76
+        if(empty($this->email)) {
77
+            $this->key=1;
78
+            $this->array_error=array_merge($this->array_error,["email"=>"Enter the email address"]);
79
+        }
80
+        elseif(filter_var($this->email,FILTER_VALIDATE_EMAIL)== false) {
81
+            $this->key=1;
82
+            $this->array_error=array_merge($this->array_error,["email"=>"Enter correct Email address"]);
83
+        }
84
+        else
85
+        {
86
+            if($this->ob->validate_email_in_db($this->email))
87
+            {
88
+                $this->key=1;
89
+                $this->array_error=array_merge($this->array_error,["email"=>"Email is already registered"]);
90
+            }
91
+        }
92
+
93
+        if(empty($this->username)) {
94
+            $this->key=1;
95
+            $this->array_error=array_merge($this->array_error,["username"=>"Enter the username"]);
96
+        }
97
+        else
98
+        {
99
+            if($this->ob->validate_username_in_db($this->username))
100
+            {
101
+                $this->key=1;
102
+                $this->array_error=array_merge($this->array_error,["username"=>"Username is already registered"]);
103
+            }
104
+        }
105
+
106
+        if(empty($this->password)) {
107
+            $this->key=1;
108
+            $this->array_error=array_merge($this->array_error,["password"=>"Enter the password"]);
109
+        }
110
+
111
+        if(empty($this->mob)) {
112
+            $this->key=1;
113
+            $this->array_error=array_merge($this->array_error,["mob"=>"Enter the Mobile Number"]);
114
+        }
115
+        elseif (!preg_match("/^[0-9]{10}$/",$this->mob)) {
116
+            $this->key=1;
117
+            $this->array_error=array_merge($this->array_error,["mob"=>"Enter correct Mobile Number"]);
118
+        }
119
+
120
+        if($this->key==1)
121
+        {
122
+            return json_encode($this->array_error);
123
+        }
124
+        else
125
+        {
126
+            $this->key=0;
127
+            $pass=md5($this->password);
128
+            $query="INSERT INTO register VALUES(null,'$this->email','$this->username','$pass')";
129
+            if(!$this->connect->query($query)) {
130
+                $this->key=1;
131
+                echo "You are not registered || Error in registration2";
132
+            }
133
+            else
134
+            {
135
+                $query="SELECT id FROM register WHERE email='$this->email'";
136
+                if($result=$this->connect->query($query)) {
137
+                    $row=$result->fetch_assoc();
138
+                    $id=$row['id'];
139
+
140
+                    $query="INSERT INTO login VALUES('$id','$this->name','$this->email','$this->username','$this->mob','1')";
141
+                    if(!$this->connect->query($query)) {
142
+                        $this->key=1;
143
+                        echo "You are not registered || Error in registration1";
144
+                    }
145
+                    $join="Joined OpenChat";
146
+                    $query="INSERT INTO profile VALUES('$id','$join','$join','')";
147
+                    if(!$this->connect->query($query)) {
148
+                        $this->key=1;
149
+                        echo "You are not updated || Error in profile";
150
+                    }
151
+                }
152
+            }
153
+        }
154
+        if ($this->key==0) {
155
+            $_SESSION['start']=$id;
156
+            return json_encode(["location"=>"http://localhost/openchat/account.php"]);
157
+        }
158
+        else
159
+        {
160
+            return json_encode($this->array_error);
161
+        }
162
+    }
163 163
 }
164 164
 ?>
165 165
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
 
18 18
 	function __construct()
19 19
 	{
20
-		$this->array_error=array();
21
-		$this->key=0;
20
+		$this->array_error = array();
21
+		$this->key = 0;
22 22
 		$this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
23
-		$this->ob=new validate();
23
+		$this->ob = new validate();
24 24
 
25 25
 
26
-		$query="CREATE TABLE IF NOT EXISTS register (
26
+		$query = "CREATE TABLE IF NOT EXISTS register (
27 27
 			id int primary key auto_increment unique not null,
28 28
 			email varchar(255) unique not null,
29 29
 			username varchar(255) unique not null,
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 			echo "Table is not created || Query failed";
35 35
 		}
36 36
 
37
-			$query="CREATE TABLE IF NOT EXISTS login (
37
+			$query = "CREATE TABLE IF NOT EXISTS login (
38 38
 			login_id int primary key not null,
39 39
 			name varchar(255) not null,
40 40
 			email varchar(255) unique not null,
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 			echo "Table is not created || Query failed";
49 49
 		}
50 50
 
51
-		$query="CREATE TABLE IF NOT EXISTS profile (
51
+		$query = "CREATE TABLE IF NOT EXISTS profile (
52 52
 		login_id int primary key not null unique,
53 53
 		status text,
54 54
 		education text,
@@ -61,98 +61,98 @@  discard block
 block discarded – undo
61 61
 
62 62
 	}
63 63
 
64
-	function _register($name,$email,$username,$password,$mob)
64
+	function _register($name, $email, $username, $password, $mob)
65 65
 	{
66
-		$this->name=trim($name);
67
-		$this->email=trim($email);
68
-		$this->username=trim($username);
69
-		$this->password=trim($password);
70
-		$this->mob=trim($mob);
66
+		$this->name = trim($name);
67
+		$this->email = trim($email);
68
+		$this->username = trim($username);
69
+		$this->password = trim($password);
70
+		$this->mob = trim($mob);
71 71
 		if (empty($this->name)) {
72
-			$this->key=1;
73
-			$this->array_error=array_merge($this->array_error,["name"=>"Enter the name"]);
72
+			$this->key = 1;
73
+			$this->array_error = array_merge($this->array_error, ["name"=>"Enter the name"]);
74 74
 		}
75 75
 
76
-		if(empty($this->email)) {
77
-			$this->key=1;
78
-			$this->array_error=array_merge($this->array_error,["email"=>"Enter the email address"]);
76
+		if (empty($this->email)) {
77
+			$this->key = 1;
78
+			$this->array_error = array_merge($this->array_error, ["email"=>"Enter the email address"]);
79 79
 		}
80
-		elseif(filter_var($this->email,FILTER_VALIDATE_EMAIL)== false) {
81
-			$this->key=1;
82
-			$this->array_error=array_merge($this->array_error,["email"=>"Enter correct Email address"]);
80
+		elseif (filter_var($this->email, FILTER_VALIDATE_EMAIL) == false) {
81
+			$this->key = 1;
82
+			$this->array_error = array_merge($this->array_error, ["email"=>"Enter correct Email address"]);
83 83
 		}
84 84
 		else
85 85
 		{
86
-			if($this->ob->validate_email_in_db($this->email))
86
+			if ($this->ob->validate_email_in_db($this->email))
87 87
 			{
88
-				$this->key=1;
89
-				$this->array_error=array_merge($this->array_error,["email"=>"Email is already registered"]);
88
+				$this->key = 1;
89
+				$this->array_error = array_merge($this->array_error, ["email"=>"Email is already registered"]);
90 90
 			}
91 91
 		}
92 92
 
93
-		if(empty($this->username)) {
94
-			$this->key=1;
95
-			$this->array_error=array_merge($this->array_error,["username"=>"Enter the username"]);
93
+		if (empty($this->username)) {
94
+			$this->key = 1;
95
+			$this->array_error = array_merge($this->array_error, ["username"=>"Enter the username"]);
96 96
 		}
97 97
 		else
98 98
 		{
99
-			if($this->ob->validate_username_in_db($this->username))
99
+			if ($this->ob->validate_username_in_db($this->username))
100 100
 			{
101
-				$this->key=1;
102
-				$this->array_error=array_merge($this->array_error,["username"=>"Username is already registered"]);
101
+				$this->key = 1;
102
+				$this->array_error = array_merge($this->array_error, ["username"=>"Username is already registered"]);
103 103
 			}
104 104
 		}
105 105
 
106
-		if(empty($this->password)) {
107
-			$this->key=1;
108
-			$this->array_error=array_merge($this->array_error,["password"=>"Enter the password"]);
106
+		if (empty($this->password)) {
107
+			$this->key = 1;
108
+			$this->array_error = array_merge($this->array_error, ["password"=>"Enter the password"]);
109 109
 		}
110 110
 
111
-		if(empty($this->mob)) {
112
-			$this->key=1;
113
-			$this->array_error=array_merge($this->array_error,["mob"=>"Enter the Mobile Number"]);
111
+		if (empty($this->mob)) {
112
+			$this->key = 1;
113
+			$this->array_error = array_merge($this->array_error, ["mob"=>"Enter the Mobile Number"]);
114 114
 		}
115
-		elseif (!preg_match("/^[0-9]{10}$/",$this->mob)) {
116
-			$this->key=1;
117
-			$this->array_error=array_merge($this->array_error,["mob"=>"Enter correct Mobile Number"]);
115
+		elseif (!preg_match("/^[0-9]{10}$/", $this->mob)) {
116
+			$this->key = 1;
117
+			$this->array_error = array_merge($this->array_error, ["mob"=>"Enter correct Mobile Number"]);
118 118
 		}
119 119
 
120
-		if($this->key==1)
120
+		if ($this->key == 1)
121 121
 		{
122 122
 			return json_encode($this->array_error);
123 123
 		}
124 124
 		else
125 125
 		{
126
-			$this->key=0;
127
-			$pass=md5($this->password);
128
-			$query="INSERT INTO register VALUES(null,'$this->email','$this->username','$pass')";
129
-			if(!$this->connect->query($query)) {
130
-				$this->key=1;
126
+			$this->key = 0;
127
+			$pass = md5($this->password);
128
+			$query = "INSERT INTO register VALUES(null,'$this->email','$this->username','$pass')";
129
+			if (!$this->connect->query($query)) {
130
+				$this->key = 1;
131 131
 				echo "You are not registered || Error in registration2";
132 132
 			}
133 133
 			else
134 134
 			{
135
-				$query="SELECT id FROM register WHERE email='$this->email'";
136
-				if($result=$this->connect->query($query)) {
137
-					$row=$result->fetch_assoc();
138
-					$id=$row['id'];
139
-
140
-					$query="INSERT INTO login VALUES('$id','$this->name','$this->email','$this->username','$this->mob','1')";
141
-					if(!$this->connect->query($query)) {
142
-						$this->key=1;
135
+				$query = "SELECT id FROM register WHERE email='$this->email'";
136
+				if ($result = $this->connect->query($query)) {
137
+					$row = $result->fetch_assoc();
138
+					$id = $row['id'];
139
+
140
+					$query = "INSERT INTO login VALUES('$id','$this->name','$this->email','$this->username','$this->mob','1')";
141
+					if (!$this->connect->query($query)) {
142
+						$this->key = 1;
143 143
 						echo "You are not registered || Error in registration1";
144 144
 					}
145
-					$join="Joined OpenChat";
146
-					$query="INSERT INTO profile VALUES('$id','$join','$join','')";
147
-					if(!$this->connect->query($query)) {
148
-						$this->key=1;
145
+					$join = "Joined OpenChat";
146
+					$query = "INSERT INTO profile VALUES('$id','$join','$join','')";
147
+					if (!$this->connect->query($query)) {
148
+						$this->key = 1;
149 149
 						echo "You are not updated || Error in profile";
150 150
 					}
151 151
 				}
152 152
 			}
153 153
 		}
154
-		if ($this->key==0) {
155
-			$_SESSION['start']=$id;
154
+		if ($this->key == 0) {
155
+			$_SESSION['start'] = $id;
156 156
 			return json_encode(["location"=>"http://localhost/openchat/account.php"]);
157 157
 		}
158 158
 		else
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -76,12 +76,10 @@  discard block
 block discarded – undo
76 76
 		if(empty($this->email)) {
77 77
 			$this->key=1;
78 78
 			$this->array_error=array_merge($this->array_error,["email"=>"Enter the email address"]);
79
-		}
80
-		elseif(filter_var($this->email,FILTER_VALIDATE_EMAIL)== false) {
79
+		} elseif(filter_var($this->email,FILTER_VALIDATE_EMAIL)== false) {
81 80
 			$this->key=1;
82 81
 			$this->array_error=array_merge($this->array_error,["email"=>"Enter correct Email address"]);
83
-		}
84
-		else
82
+		} else
85 83
 		{
86 84
 			if($this->ob->validate_email_in_db($this->email))
87 85
 			{
@@ -93,8 +91,7 @@  discard block
 block discarded – undo
93 91
 		if(empty($this->username)) {
94 92
 			$this->key=1;
95 93
 			$this->array_error=array_merge($this->array_error,["username"=>"Enter the username"]);
96
-		}
97
-		else
94
+		} else
98 95
 		{
99 96
 			if($this->ob->validate_username_in_db($this->username))
100 97
 			{
@@ -111,8 +108,7 @@  discard block
 block discarded – undo
111 108
 		if(empty($this->mob)) {
112 109
 			$this->key=1;
113 110
 			$this->array_error=array_merge($this->array_error,["mob"=>"Enter the Mobile Number"]);
114
-		}
115
-		elseif (!preg_match("/^[0-9]{10}$/",$this->mob)) {
111
+		} elseif (!preg_match("/^[0-9]{10}$/",$this->mob)) {
116 112
 			$this->key=1;
117 113
 			$this->array_error=array_merge($this->array_error,["mob"=>"Enter correct Mobile Number"]);
118 114
 		}
@@ -120,8 +116,7 @@  discard block
 block discarded – undo
120 116
 		if($this->key==1)
121 117
 		{
122 118
 			return json_encode($this->array_error);
123
-		}
124
-		else
119
+		} else
125 120
 		{
126 121
 			$this->key=0;
127 122
 			$pass=md5($this->password);
@@ -129,8 +124,7 @@  discard block
 block discarded – undo
129 124
 			if(!$this->connect->query($query)) {
130 125
 				$this->key=1;
131 126
 				echo "You are not registered || Error in registration2";
132
-			}
133
-			else
127
+			} else
134 128
 			{
135 129
 				$query="SELECT id FROM register WHERE email='$this->email'";
136 130
 				if($result=$this->connect->query($query)) {
@@ -154,8 +148,7 @@  discard block
 block discarded – undo
154 148
 		if ($this->key==0) {
155 149
 			$_SESSION['start']=$id;
156 150
 			return json_encode(["location"=>"http://localhost/openchat/account.php"]);
157
-		}
158
-		else
151
+		} else
159 152
 		{
160 153
 			return json_encode($this->array_error);
161 154
 		}
Please login to merge, or discard this patch.