@@ -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 |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require (dirname(__DIR__) . '/vendor/autoload.php'); |
|
3 | +require (dirname(__DIR__).'/vendor/autoload.php'); |
|
4 | 4 | use ChatApp\Register; |
5 | 5 | |
6 | -if(isset($_POST['q'])) |
|
6 | +if (isset($_POST['q'])) |
|
7 | 7 | { |
8 | 8 | $registerField = json_decode($_POST['q']); |
9 | 9 | $name = $registerField->name; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | $password = $registerField->password; |
14 | 14 | $obRegister = new Register(); |
15 | 15 | $result = $obRegister->authRegister($name, $email, $username, $password, $mob); |
16 | - if(isset($result)) |
|
16 | + if (isset($result)) |
|
17 | 17 | echo $result; |
18 | 18 | else |
19 | 19 | echo json_encode([]); |
@@ -13,9 +13,10 @@ |
||
13 | 13 | $password = $registerField->password; |
14 | 14 | $obRegister = new Register(); |
15 | 15 | $result = $obRegister->authRegister($name, $email, $username, $password, $mob); |
16 | - if(isset($result)) |
|
17 | - echo $result; |
|
18 | - else |
|
19 | - echo json_encode([]); |
|
20 | -} |
|
16 | + if(isset($result)) { |
|
17 | + echo $result; |
|
18 | + } else { |
|
19 | + echo json_encode([]); |
|
20 | + } |
|
21 | + } |
|
21 | 22 |
@@ -6,15 +6,15 @@ |
||
6 | 6 | class Session |
7 | 7 | { |
8 | 8 | |
9 | - public static function put($key, $value){ |
|
9 | + public static function put($key, $value) { |
|
10 | 10 | $_SESSION[$key] = $value; |
11 | 11 | } |
12 | 12 | |
13 | - public static function get($key){ |
|
13 | + public static function get($key) { |
|
14 | 14 | return (isset($_SESSION[$key]) ? $_SESSION[$key] : null); |
15 | 15 | } |
16 | 16 | |
17 | - public static function forget($key){ |
|
17 | + public static function forget($key) { |
|
18 | 18 | unset($_SESSION[$key]); |
19 | 19 | } |
20 | 20 | } |
@@ -6,6 +6,9 @@ |
||
6 | 6 | class Session |
7 | 7 | { |
8 | 8 | |
9 | + /** |
|
10 | + * @param string $key |
|
11 | + */ |
|
9 | 12 | public static function put($key, $value){ |
10 | 13 | $_SESSION[$key] = $value; |
11 | 14 | } |
@@ -11,26 +11,26 @@ discard block |
||
11 | 11 | $userId = Session::get('start'); |
12 | 12 | if($userId != null && $user == "account.php") |
13 | 13 | { |
14 | - $obUser = new User(); |
|
15 | - $row = $obUser->UserDetails($userId, True); |
|
14 | + $obUser = new User(); |
|
15 | + $row = $obUser->UserDetails($userId, True); |
|
16 | 16 | |
17 | - if($row != NULL) |
|
18 | - { |
|
19 | - $location = URL . "/account.php/". $row['username']; |
|
20 | - header("Location:".$location); |
|
21 | - } |
|
17 | + if($row != NULL) |
|
18 | + { |
|
19 | + $location = URL . "/account.php/". $row['username']; |
|
20 | + header("Location:".$location); |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | elseif ($user != "account.php") |
24 | 24 | { |
25 | - $obUser = new User(); |
|
26 | - $row = $obUser->UserDetails($user, False); |
|
27 | - if($row != NULL): |
|
28 | - $userId = $row['login_id']; |
|
29 | - $details = Profile::getProfile($userId); |
|
30 | - if($details != NULL) |
|
31 | - $row = array_merge($row, $details); |
|
32 | - else |
|
33 | - header("Location:".URL."/error.php"); |
|
25 | + $obUser = new User(); |
|
26 | + $row = $obUser->UserDetails($user, False); |
|
27 | + if($row != NULL): |
|
28 | + $userId = $row['login_id']; |
|
29 | + $details = Profile::getProfile($userId); |
|
30 | + if($details != NULL) |
|
31 | + $row = array_merge($row, $details); |
|
32 | + else |
|
33 | + header("Location:".URL."/error.php"); |
|
34 | 34 | ?> |
35 | 35 | |
36 | 36 | <!Doctype html> |
@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | <div class="brief"> |
66 | 66 | <h1 id="name">Name: <?php echo $row['name']; ?></h1><br> |
67 | 67 | <?php foreach ($row as $key => $value) { |
68 | - if($key =='username' && $value != null) |
|
69 | - echo '<p>Username: '.$row["username"] .'</p><br>'; |
|
70 | - if($key == 'email' && $value != null) |
|
71 | - echo '<p>Email Id: '.$row["email"] .'</p><br>'; |
|
72 | - if($key == 'status' && $value != null) |
|
73 | - echo '<p>Status: '.$row["status"] .'</p><br>'; |
|
74 | - if($key == 'education' && $value != null) |
|
75 | - echo '<p>Education: '.$row["education"] .'</p><br>'; |
|
76 | - if($key == 'gender' && $value != null) |
|
77 | - echo '<p>Gender: '.$row["gender"] .'</p><br>'; |
|
78 | - } |
|
79 | - ?> |
|
68 | + if($key =='username' && $value != null) |
|
69 | + echo '<p>Username: '.$row["username"] .'</p><br>'; |
|
70 | + if($key == 'email' && $value != null) |
|
71 | + echo '<p>Email Id: '.$row["email"] .'</p><br>'; |
|
72 | + if($key == 'status' && $value != null) |
|
73 | + echo '<p>Status: '.$row["status"] .'</p><br>'; |
|
74 | + if($key == 'education' && $value != null) |
|
75 | + echo '<p>Education: '.$row["education"] .'</p><br>'; |
|
76 | + if($key == 'gender' && $value != null) |
|
77 | + echo '<p>Gender: '.$row["gender"] .'</p><br>'; |
|
78 | + } |
|
79 | + ?> |
|
80 | 80 | </div> |
81 | 81 | <?php if(Session::get('start') == $row['login_id']): ?> |
82 | 82 | <div class="edit"> |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | </div> |
87 | 87 | |
88 | 88 | <?php |
89 | - if(Session::get('start') == $row['login_id']): |
|
90 | - ?> |
|
89 | + if(Session::get('start') == $row['login_id']): |
|
90 | + ?> |
|
91 | 91 | |
92 | 92 | <div class="boxx" id="profile"> |
93 | 93 | <form method="post" action="../profile_generate.php"> |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | </form> |
103 | 103 | </div> |
104 | 104 | <?php |
105 | - endif; |
|
106 | - ?> |
|
105 | + endif; |
|
106 | + ?> |
|
107 | 107 | </div> |
108 | 108 | |
109 | 109 | <div class="footer"> |
@@ -116,13 +116,13 @@ discard block |
||
116 | 116 | </body> |
117 | 117 | </html> |
118 | 118 | <?php |
119 | - else: |
|
120 | - header("Location:".URL."/error.php"); |
|
121 | - endif; |
|
119 | + else: |
|
120 | + header("Location:".URL."/error.php"); |
|
121 | + endif; |
|
122 | 122 | } |
123 | 123 | else |
124 | 124 | { |
125 | - header("Location: ".URL); |
|
125 | + header("Location: ".URL); |
|
126 | 126 | } |
127 | 127 | ?> |
128 | 128 |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once (__DIR__ . '/vendor/autoload.php'); |
|
4 | -require_once (__DIR__ . '/config/database.php'); |
|
3 | +require_once (__DIR__.'/vendor/autoload.php'); |
|
4 | +require_once (__DIR__.'/config/database.php'); |
|
5 | 5 | use ChatApp\User; |
6 | 6 | use ChatApp\Profile; |
7 | 7 | use ChatApp\Session; |
8 | 8 | |
9 | 9 | $user = explode("/", $_SERVER['REQUEST_URI']); |
10 | -$user = $user[count($user)-1]; |
|
10 | +$user = $user[count($user) - 1]; |
|
11 | 11 | $userId = Session::get('start'); |
12 | -if($userId != null && $user == "account.php") |
|
12 | +if ($userId != null && $user == "account.php") |
|
13 | 13 | { |
14 | 14 | $obUser = new User(); |
15 | 15 | $row = $obUser->UserDetails($userId, True); |
16 | 16 | |
17 | - if($row != NULL) |
|
17 | + if ($row != NULL) |
|
18 | 18 | { |
19 | - $location = URL . "/account.php/". $row['username']; |
|
19 | + $location = URL."/account.php/".$row['username']; |
|
20 | 20 | header("Location:".$location); |
21 | 21 | } |
22 | 22 | } |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | { |
25 | 25 | $obUser = new User(); |
26 | 26 | $row = $obUser->UserDetails($user, False); |
27 | - if($row != NULL): |
|
27 | + if ($row != NULL): |
|
28 | 28 | $userId = $row['login_id']; |
29 | 29 | $details = Profile::getProfile($userId); |
30 | - if($details != NULL) |
|
30 | + if ($details != NULL) |
|
31 | 31 | $row = array_merge($row, $details); |
32 | 32 | else |
33 | 33 | header("Location:".URL."/error.php"); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | <a id="brand" href="">OpenChat</a> |
46 | 46 | <ul class="nav-right"> |
47 | 47 | <li><a href="../index.php">About</a></li> |
48 | - <?php if(Session::get('start') != null): ?> |
|
48 | + <?php if (Session::get('start') != null): ?> |
|
49 | 49 | <li><a href="../message.php">Message</a></li> |
50 | 50 | <li><a href="../logout.php">Log out</a></li> |
51 | 51 | <?php else: ?> |
@@ -65,20 +65,20 @@ discard block |
||
65 | 65 | <div class="brief"> |
66 | 66 | <h1 id="name">Name: <?php echo $row['name']; ?></h1><br> |
67 | 67 | <?php foreach ($row as $key => $value) { |
68 | - if($key =='username' && $value != null) |
|
69 | - echo '<p>Username: '.$row["username"] .'</p><br>'; |
|
70 | - if($key == 'email' && $value != null) |
|
71 | - echo '<p>Email Id: '.$row["email"] .'</p><br>'; |
|
72 | - if($key == 'status' && $value != null) |
|
73 | - echo '<p>Status: '.$row["status"] .'</p><br>'; |
|
74 | - if($key == 'education' && $value != null) |
|
75 | - echo '<p>Education: '.$row["education"] .'</p><br>'; |
|
76 | - if($key == 'gender' && $value != null) |
|
77 | - echo '<p>Gender: '.$row["gender"] .'</p><br>'; |
|
68 | + if ($key == 'username' && $value != null) |
|
69 | + echo '<p>Username: '.$row["username"].'</p><br>'; |
|
70 | + if ($key == 'email' && $value != null) |
|
71 | + echo '<p>Email Id: '.$row["email"].'</p><br>'; |
|
72 | + if ($key == 'status' && $value != null) |
|
73 | + echo '<p>Status: '.$row["status"].'</p><br>'; |
|
74 | + if ($key == 'education' && $value != null) |
|
75 | + echo '<p>Education: '.$row["education"].'</p><br>'; |
|
76 | + if ($key == 'gender' && $value != null) |
|
77 | + echo '<p>Gender: '.$row["gender"].'</p><br>'; |
|
78 | 78 | } |
79 | 79 | ?> |
80 | 80 | </div> |
81 | - <?php if(Session::get('start') == $row['login_id']): ?> |
|
81 | + <?php if (Session::get('start') == $row['login_id']): ?> |
|
82 | 82 | <div class="edit"> |
83 | 83 | <a href="#">Edit Profile</a> |
84 | 84 | </div> |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | </div> |
87 | 87 | |
88 | 88 | <?php |
89 | - if(Session::get('start') == $row['login_id']): |
|
89 | + if (Session::get('start') == $row['login_id']): |
|
90 | 90 | ?> |
91 | 91 | |
92 | 92 | <div class="boxx" id="profile"> |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | <label>Education : </label> |
97 | 97 | <input type="text" name="education" id="education" value="<?php echo $row['education']; ?>"></input> |
98 | 98 | <label>Gender : </label><br> |
99 | - <input type="radio" name="gender" id="gender" value="Male" <?php echo ($row['gender']=='Male')?'checked':'' ?>> Male<br> |
|
100 | - <input type="radio" name="gender" id="gender" value="Female" <?php echo ($row['gender']=='Female')?'checked':'' ?>> Female<br> |
|
99 | + <input type="radio" name="gender" id="gender" value="Male" <?php echo ($row['gender'] == 'Male') ? 'checked' : '' ?>> Male<br> |
|
100 | + <input type="radio" name="gender" id="gender" value="Female" <?php echo ($row['gender'] == 'Female') ? 'checked' : '' ?>> Female<br> |
|
101 | 101 | <input type="submit" name="submit" value="Done" id="submit"> |
102 | 102 | </form> |
103 | 103 | </div> |
@@ -19,19 +19,19 @@ discard block |
||
19 | 19 | $location = URL . "/account.php/". $row['username']; |
20 | 20 | header("Location:".$location); |
21 | 21 | } |
22 | -} |
|
23 | -elseif ($user != "account.php") |
|
22 | +} elseif ($user != "account.php") |
|
24 | 23 | { |
25 | 24 | $obUser = new User(); |
26 | 25 | $row = $obUser->UserDetails($user, False); |
27 | 26 | if($row != NULL): |
28 | 27 | $userId = $row['login_id']; |
29 | 28 | $details = Profile::getProfile($userId); |
30 | - if($details != NULL) |
|
31 | - $row = array_merge($row, $details); |
|
32 | - else |
|
33 | - header("Location:".URL."/error.php"); |
|
34 | -?> |
|
29 | + if($details != NULL) { |
|
30 | + $row = array_merge($row, $details); |
|
31 | + } else { |
|
32 | + header("Location:".URL."/error.php"); |
|
33 | + } |
|
34 | + ?> |
|
35 | 35 | |
36 | 36 | <!Doctype html> |
37 | 37 | <html> |
@@ -48,10 +48,13 @@ discard block |
||
48 | 48 | <?php if(Session::get('start') != null): ?> |
49 | 49 | <li><a href="../message.php">Message</a></li> |
50 | 50 | <li><a href="../logout.php">Log out</a></li> |
51 | - <?php else: ?> |
|
51 | + <?php else { |
|
52 | + : ?> |
|
52 | 53 | <li><a href="../login.php">Login</a></li> |
53 | 54 | <li><a href="../register.php">Register</a></li> |
54 | - <?php endif; ?> |
|
55 | + <?php endif; |
|
56 | +} |
|
57 | +?> |
|
55 | 58 | </ul> |
56 | 59 | </div> |
57 | 60 | |
@@ -65,16 +68,21 @@ discard block |
||
65 | 68 | <div class="brief"> |
66 | 69 | <h1 id="name">Name: <?php echo $row['name']; ?></h1><br> |
67 | 70 | <?php foreach ($row as $key => $value) { |
68 | - if($key =='username' && $value != null) |
|
69 | - echo '<p>Username: '.$row["username"] .'</p><br>'; |
|
70 | - if($key == 'email' && $value != null) |
|
71 | - echo '<p>Email Id: '.$row["email"] .'</p><br>'; |
|
72 | - if($key == 'status' && $value != null) |
|
73 | - echo '<p>Status: '.$row["status"] .'</p><br>'; |
|
74 | - if($key == 'education' && $value != null) |
|
75 | - echo '<p>Education: '.$row["education"] .'</p><br>'; |
|
76 | - if($key == 'gender' && $value != null) |
|
77 | - echo '<p>Gender: '.$row["gender"] .'</p><br>'; |
|
71 | + if($key =='username' && $value != null) { |
|
72 | + echo '<p>Username: '.$row["username"] .'</p><br>'; |
|
73 | + } |
|
74 | + if($key == 'email' && $value != null) { |
|
75 | + echo '<p>Email Id: '.$row["email"] .'</p><br>'; |
|
76 | + } |
|
77 | + if($key == 'status' && $value != null) { |
|
78 | + echo '<p>Status: '.$row["status"] .'</p><br>'; |
|
79 | + } |
|
80 | + if($key == 'education' && $value != null) { |
|
81 | + echo '<p>Education: '.$row["education"] .'</p><br>'; |
|
82 | + } |
|
83 | + if($key == 'gender' && $value != null) { |
|
84 | + echo '<p>Gender: '.$row["gender"] .'</p><br>'; |
|
85 | + } |
|
78 | 86 | } |
79 | 87 | ?> |
80 | 88 | </div> |
@@ -116,11 +124,12 @@ discard block |
||
116 | 124 | </body> |
117 | 125 | </html> |
118 | 126 | <?php |
119 | - else: |
|
127 | + else { |
|
128 | + : |
|
120 | 129 | header("Location:".URL."/error.php"); |
130 | + } |
|
121 | 131 | endif; |
122 | -} |
|
123 | -else |
|
132 | +} else |
|
124 | 133 | { |
125 | 134 | header("Location: ".URL); |
126 | 135 | } |
@@ -9,29 +9,29 @@ |
||
9 | 9 | $data = ''; |
10 | 10 | if(isset($_POST['submit'])) |
11 | 11 | { |
12 | - $data = Profile::getProfile($userId); |
|
13 | - if($data != NULL): |
|
14 | - $status = get($_POST['status'], $data['status']); |
|
15 | - $edu = get($_POST['education'], $data['education']); |
|
16 | - $gender = get($_POST['gender'], $data['gender']); |
|
17 | - $query = "UPDATE profile set status='$status', education='$edu', gender='$gender' where login_id = '$userId'"; |
|
18 | - if($result = $connect->query($query)) |
|
19 | - { |
|
20 | - header('Location:'.URL.'/account.php'); |
|
21 | - } |
|
22 | - else |
|
23 | - { |
|
24 | - header("Location:".URL."/error.php"); |
|
25 | - } |
|
26 | - endif; |
|
12 | + $data = Profile::getProfile($userId); |
|
13 | + if($data != NULL): |
|
14 | + $status = get($_POST['status'], $data['status']); |
|
15 | + $edu = get($_POST['education'], $data['education']); |
|
16 | + $gender = get($_POST['gender'], $data['gender']); |
|
17 | + $query = "UPDATE profile set status='$status', education='$edu', gender='$gender' where login_id = '$userId'"; |
|
18 | + if($result = $connect->query($query)) |
|
19 | + { |
|
20 | + header('Location:'.URL.'/account.php'); |
|
21 | + } |
|
22 | + else |
|
23 | + { |
|
24 | + header("Location:".URL."/error.php"); |
|
25 | + } |
|
26 | + endif; |
|
27 | 27 | } |
28 | 28 | else |
29 | 29 | { |
30 | - header("Location:".URL."/error.php"); |
|
30 | + header("Location:".URL."/error.php"); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function get($value, $default) |
34 | 34 | { |
35 | - $value = trim($value); |
|
36 | - return (isset($value) ? $value : $default); |
|
35 | + $value = trim($value); |
|
36 | + return (isset($value) ? $value : $default); |
|
37 | 37 | } |
@@ -1,21 +1,21 @@ |
||
1 | 1 | <?php |
2 | -require_once (__DIR__ . '/config/database.php'); |
|
3 | -require_once (__DIR__ . '/vendor/autoload.php'); |
|
2 | +require_once (__DIR__.'/config/database.php'); |
|
3 | +require_once (__DIR__.'/vendor/autoload.php'); |
|
4 | 4 | use ChatApp\Session; |
5 | 5 | use ChatApp\Profile; |
6 | 6 | |
7 | 7 | $connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
8 | 8 | $userId = Session::get('start'); |
9 | 9 | $data = ''; |
10 | -if(isset($_POST['submit'])) |
|
10 | +if (isset($_POST['submit'])) |
|
11 | 11 | { |
12 | 12 | $data = Profile::getProfile($userId); |
13 | - if($data != NULL): |
|
13 | + if ($data != NULL): |
|
14 | 14 | $status = get($_POST['status'], $data['status']); |
15 | 15 | $edu = get($_POST['education'], $data['education']); |
16 | 16 | $gender = get($_POST['gender'], $data['gender']); |
17 | 17 | $query = "UPDATE profile set status='$status', education='$edu', gender='$gender' where login_id = '$userId'"; |
18 | - if($result = $connect->query($query)) |
|
18 | + if ($result = $connect->query($query)) |
|
19 | 19 | { |
20 | 20 | header('Location:'.URL.'/account.php'); |
21 | 21 | } |
@@ -18,14 +18,12 @@ |
||
18 | 18 | if($result = $connect->query($query)) |
19 | 19 | { |
20 | 20 | header('Location:'.URL.'/account.php'); |
21 | - } |
|
22 | - else |
|
21 | + } else |
|
23 | 22 | { |
24 | 23 | header("Location:".URL."/error.php"); |
25 | 24 | } |
26 | 25 | endif; |
27 | -} |
|
28 | -else |
|
26 | +} else |
|
29 | 27 | { |
30 | 28 | header("Location:".URL."/error.php"); |
31 | 29 | } |
@@ -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 | ?> |
@@ -2,7 +2,7 @@ discard block |
||
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 |
||
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 | } |
@@ -7,122 +7,122 @@ |
||
7 | 7 | |
8 | 8 | class Register |
9 | 9 | { |
10 | - protected $error; |
|
11 | - protected $key; |
|
12 | - protected $obValidate; |
|
13 | - protected $connect; |
|
10 | + protected $error; |
|
11 | + protected $key; |
|
12 | + protected $obValidate; |
|
13 | + protected $connect; |
|
14 | 14 | |
15 | - public function __construct() |
|
16 | - { |
|
17 | - $this->error = array(); |
|
18 | - $this->key = 0; |
|
19 | - $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
|
20 | - $this->obValidate = new Validate(); |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + $this->error = array(); |
|
18 | + $this->key = 0; |
|
19 | + $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
|
20 | + $this->obValidate = new Validate(); |
|
21 | 21 | |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - public function authRegister($name, $email, $username, $password, $mob) |
|
25 | - { |
|
26 | - $name = trim($name); |
|
27 | - $email = trim($email); |
|
28 | - $username = trim($username); |
|
29 | - $password = trim($password); |
|
30 | - $mob = trim($mob); |
|
31 | - $userId = ''; |
|
24 | + public function authRegister($name, $email, $username, $password, $mob) |
|
25 | + { |
|
26 | + $name = trim($name); |
|
27 | + $email = trim($email); |
|
28 | + $username = trim($username); |
|
29 | + $password = trim($password); |
|
30 | + $mob = trim($mob); |
|
31 | + $userId = ''; |
|
32 | 32 | |
33 | - if (empty($name)) { |
|
34 | - $this->onError(["name" => " *Enter the name"]); |
|
35 | - } |
|
33 | + if (empty($name)) { |
|
34 | + $this->onError(["name" => " *Enter the name"]); |
|
35 | + } |
|
36 | 36 | |
37 | - if(empty($email)) { |
|
38 | - $this->onError(["email" => " *Enter the email address"]); |
|
39 | - } |
|
40 | - elseif(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
41 | - $this->onError(["email" => " *Enter correct Email address"]); |
|
42 | - } |
|
43 | - else |
|
44 | - { |
|
45 | - if($this->obValidate->validateEmailInDb($email) === 1) |
|
46 | - { |
|
37 | + if(empty($email)) { |
|
38 | + $this->onError(["email" => " *Enter the email address"]); |
|
39 | + } |
|
40 | + elseif(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
41 | + $this->onError(["email" => " *Enter correct Email address"]); |
|
42 | + } |
|
43 | + else |
|
44 | + { |
|
45 | + if($this->obValidate->validateEmailInDb($email) === 1) |
|
46 | + { |
|
47 | 47 | |
48 | - $this->onError(["email" => " *Email is already registered"]); |
|
49 | - } |
|
50 | - } |
|
48 | + $this->onError(["email" => " *Email is already registered"]); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - if(empty($username)) { |
|
53 | - $this->onError(["username" => " *Enter the username"]); |
|
54 | - } |
|
55 | - else |
|
56 | - { |
|
57 | - if($this->obValidate->validateUsernameInDb($username) === 1) |
|
58 | - { |
|
52 | + if(empty($username)) { |
|
53 | + $this->onError(["username" => " *Enter the username"]); |
|
54 | + } |
|
55 | + else |
|
56 | + { |
|
57 | + if($this->obValidate->validateUsernameInDb($username) === 1) |
|
58 | + { |
|
59 | 59 | |
60 | - $this->onError(["username" => " *Username is already registered"]); |
|
61 | - } |
|
62 | - } |
|
60 | + $this->onError(["username" => " *Username is already registered"]); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - if(empty($password)) { |
|
65 | - $this->onError(["password" => " *Enter the password"]); |
|
66 | - } |
|
64 | + if(empty($password)) { |
|
65 | + $this->onError(["password" => " *Enter the password"]); |
|
66 | + } |
|
67 | 67 | |
68 | - if(empty($mob)) { |
|
69 | - $this->onError(["mob" => " *Enter the Mobile Number"]); |
|
70 | - } |
|
71 | - elseif (!preg_match("/^[0-9]{10}$/", $mob)) { |
|
72 | - $this->onError(["mob" => " *Enter correct Mobile Number"]); |
|
73 | - } |
|
68 | + if(empty($mob)) { |
|
69 | + $this->onError(["mob" => " *Enter the Mobile Number"]); |
|
70 | + } |
|
71 | + elseif (!preg_match("/^[0-9]{10}$/", $mob)) { |
|
72 | + $this->onError(["mob" => " *Enter correct Mobile Number"]); |
|
73 | + } |
|
74 | 74 | |
75 | - if($this->key == 1) |
|
76 | - { |
|
77 | - return json_encode($this->error); |
|
78 | - } |
|
79 | - else |
|
80 | - { |
|
81 | - $this->key = 0; |
|
82 | - $pass = md5($password); |
|
83 | - $query = "INSERT INTO register VALUES(null, '$email', '$username', '$pass')"; |
|
84 | - if(!$this->connect->query($query)) { |
|
85 | - $this->key = 1; |
|
86 | - echo "You are not registered || Error in registration1"; |
|
87 | - } |
|
88 | - else |
|
89 | - { |
|
90 | - $query = "SELECT id FROM register WHERE email = '$email'"; |
|
91 | - if($result = $this->connect->query($query)) { |
|
92 | - $row = $result->fetch_assoc(); |
|
93 | - $userId = $row['id']; |
|
75 | + if($this->key == 1) |
|
76 | + { |
|
77 | + return json_encode($this->error); |
|
78 | + } |
|
79 | + else |
|
80 | + { |
|
81 | + $this->key = 0; |
|
82 | + $pass = md5($password); |
|
83 | + $query = "INSERT INTO register VALUES(null, '$email', '$username', '$pass')"; |
|
84 | + if(!$this->connect->query($query)) { |
|
85 | + $this->key = 1; |
|
86 | + echo "You are not registered || Error in registration1"; |
|
87 | + } |
|
88 | + else |
|
89 | + { |
|
90 | + $query = "SELECT id FROM register WHERE email = '$email'"; |
|
91 | + if($result = $this->connect->query($query)) { |
|
92 | + $row = $result->fetch_assoc(); |
|
93 | + $userId = $row['id']; |
|
94 | 94 | |
95 | - $query = "INSERT INTO login VALUES('$userId', '$name', '$email', '$username', '$mob', 0)"; |
|
96 | - if(!$this->connect->query($query)) { |
|
97 | - $this->key = 1; |
|
98 | - echo "You are not registered || Error in registration2"; |
|
99 | - } |
|
100 | - else |
|
101 | - { |
|
102 | - $query = "INSERT INTO profile VALUES('$userId', 'Joined OpenChat', 'Joined OpenChat', '')"; |
|
103 | - if(!$this->connect->query($query)) { |
|
104 | - $this->key = 1; |
|
105 | - echo "You are not registered || Error in registration3"; |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - if ($this->key == 0) { |
|
112 | - Session::put('start', $userId); |
|
113 | - return json_encode([ |
|
114 | - "location" => URL."/account.php" |
|
115 | - ]); |
|
116 | - } |
|
117 | - else |
|
118 | - { |
|
119 | - return json_encode($this->error); |
|
120 | - } |
|
121 | - } |
|
95 | + $query = "INSERT INTO login VALUES('$userId', '$name', '$email', '$username', '$mob', 0)"; |
|
96 | + if(!$this->connect->query($query)) { |
|
97 | + $this->key = 1; |
|
98 | + echo "You are not registered || Error in registration2"; |
|
99 | + } |
|
100 | + else |
|
101 | + { |
|
102 | + $query = "INSERT INTO profile VALUES('$userId', 'Joined OpenChat', 'Joined OpenChat', '')"; |
|
103 | + if(!$this->connect->query($query)) { |
|
104 | + $this->key = 1; |
|
105 | + echo "You are not registered || Error in registration3"; |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + if ($this->key == 0) { |
|
112 | + Session::put('start', $userId); |
|
113 | + return json_encode([ |
|
114 | + "location" => URL."/account.php" |
|
115 | + ]); |
|
116 | + } |
|
117 | + else |
|
118 | + { |
|
119 | + return json_encode($this->error); |
|
120 | + } |
|
121 | + } |
|
122 | 122 | |
123 | - public function onError($value) |
|
124 | - { |
|
125 | - $this->key = 1; |
|
126 | - $this->error = array_merge($this->error, $value); |
|
127 | - } |
|
123 | + public function onError($value) |
|
124 | + { |
|
125 | + $this->key = 1; |
|
126 | + $this->error = array_merge($this->error, $value); |
|
127 | + } |
|
128 | 128 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace ChatApp; |
4 | 4 | use ChatApp\Validate; |
5 | 5 | use ChatApp\Session; |
6 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
6 | +require_once (dirname(__DIR__).'/config/database.php'); |
|
7 | 7 | |
8 | 8 | class Register |
9 | 9 | { |
@@ -34,45 +34,45 @@ discard block |
||
34 | 34 | $this->onError(["name" => " *Enter the name"]); |
35 | 35 | } |
36 | 36 | |
37 | - if(empty($email)) { |
|
37 | + if (empty($email)) { |
|
38 | 38 | $this->onError(["email" => " *Enter the email address"]); |
39 | 39 | } |
40 | - elseif(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
40 | + elseif (filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
41 | 41 | $this->onError(["email" => " *Enter correct Email address"]); |
42 | 42 | } |
43 | 43 | else |
44 | 44 | { |
45 | - if($this->obValidate->validateEmailInDb($email) === 1) |
|
45 | + if ($this->obValidate->validateEmailInDb($email) === 1) |
|
46 | 46 | { |
47 | 47 | |
48 | 48 | $this->onError(["email" => " *Email is already registered"]); |
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - if(empty($username)) { |
|
52 | + if (empty($username)) { |
|
53 | 53 | $this->onError(["username" => " *Enter the username"]); |
54 | 54 | } |
55 | 55 | else |
56 | 56 | { |
57 | - if($this->obValidate->validateUsernameInDb($username) === 1) |
|
57 | + if ($this->obValidate->validateUsernameInDb($username) === 1) |
|
58 | 58 | { |
59 | 59 | |
60 | 60 | $this->onError(["username" => " *Username is already registered"]); |
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - if(empty($password)) { |
|
64 | + if (empty($password)) { |
|
65 | 65 | $this->onError(["password" => " *Enter the password"]); |
66 | 66 | } |
67 | 67 | |
68 | - if(empty($mob)) { |
|
68 | + if (empty($mob)) { |
|
69 | 69 | $this->onError(["mob" => " *Enter the Mobile Number"]); |
70 | 70 | } |
71 | 71 | elseif (!preg_match("/^[0-9]{10}$/", $mob)) { |
72 | 72 | $this->onError(["mob" => " *Enter correct Mobile Number"]); |
73 | 73 | } |
74 | 74 | |
75 | - if($this->key == 1) |
|
75 | + if ($this->key == 1) |
|
76 | 76 | { |
77 | 77 | return json_encode($this->error); |
78 | 78 | } |
@@ -81,26 +81,26 @@ discard block |
||
81 | 81 | $this->key = 0; |
82 | 82 | $pass = md5($password); |
83 | 83 | $query = "INSERT INTO register VALUES(null, '$email', '$username', '$pass')"; |
84 | - if(!$this->connect->query($query)) { |
|
84 | + if (!$this->connect->query($query)) { |
|
85 | 85 | $this->key = 1; |
86 | 86 | echo "You are not registered || Error in registration1"; |
87 | 87 | } |
88 | 88 | else |
89 | 89 | { |
90 | 90 | $query = "SELECT id FROM register WHERE email = '$email'"; |
91 | - if($result = $this->connect->query($query)) { |
|
91 | + if ($result = $this->connect->query($query)) { |
|
92 | 92 | $row = $result->fetch_assoc(); |
93 | 93 | $userId = $row['id']; |
94 | 94 | |
95 | 95 | $query = "INSERT INTO login VALUES('$userId', '$name', '$email', '$username', '$mob', 0)"; |
96 | - if(!$this->connect->query($query)) { |
|
96 | + if (!$this->connect->query($query)) { |
|
97 | 97 | $this->key = 1; |
98 | 98 | echo "You are not registered || Error in registration2"; |
99 | 99 | } |
100 | 100 | else |
101 | 101 | { |
102 | 102 | $query = "INSERT INTO profile VALUES('$userId', 'Joined OpenChat', 'Joined OpenChat', '')"; |
103 | - if(!$this->connect->query($query)) { |
|
103 | + if (!$this->connect->query($query)) { |
|
104 | 104 | $this->key = 1; |
105 | 105 | echo "You are not registered || Error in registration3"; |
106 | 106 | } |
@@ -36,11 +36,9 @@ discard block |
||
36 | 36 | |
37 | 37 | if(empty($email)) { |
38 | 38 | $this->onError(["email" => " *Enter the email address"]); |
39 | - } |
|
40 | - elseif(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
39 | + } elseif(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
41 | 40 | $this->onError(["email" => " *Enter correct Email address"]); |
42 | - } |
|
43 | - else |
|
41 | + } else |
|
44 | 42 | { |
45 | 43 | if($this->obValidate->validateEmailInDb($email) === 1) |
46 | 44 | { |
@@ -51,8 +49,7 @@ discard block |
||
51 | 49 | |
52 | 50 | if(empty($username)) { |
53 | 51 | $this->onError(["username" => " *Enter the username"]); |
54 | - } |
|
55 | - else |
|
52 | + } else |
|
56 | 53 | { |
57 | 54 | if($this->obValidate->validateUsernameInDb($username) === 1) |
58 | 55 | { |
@@ -67,16 +64,14 @@ discard block |
||
67 | 64 | |
68 | 65 | if(empty($mob)) { |
69 | 66 | $this->onError(["mob" => " *Enter the Mobile Number"]); |
70 | - } |
|
71 | - elseif (!preg_match("/^[0-9]{10}$/", $mob)) { |
|
67 | + } elseif (!preg_match("/^[0-9]{10}$/", $mob)) { |
|
72 | 68 | $this->onError(["mob" => " *Enter correct Mobile Number"]); |
73 | 69 | } |
74 | 70 | |
75 | 71 | if($this->key == 1) |
76 | 72 | { |
77 | 73 | return json_encode($this->error); |
78 | - } |
|
79 | - else |
|
74 | + } else |
|
80 | 75 | { |
81 | 76 | $this->key = 0; |
82 | 77 | $pass = md5($password); |
@@ -84,8 +79,7 @@ discard block |
||
84 | 79 | if(!$this->connect->query($query)) { |
85 | 80 | $this->key = 1; |
86 | 81 | echo "You are not registered || Error in registration1"; |
87 | - } |
|
88 | - else |
|
82 | + } else |
|
89 | 83 | { |
90 | 84 | $query = "SELECT id FROM register WHERE email = '$email'"; |
91 | 85 | if($result = $this->connect->query($query)) { |
@@ -96,8 +90,7 @@ discard block |
||
96 | 90 | if(!$this->connect->query($query)) { |
97 | 91 | $this->key = 1; |
98 | 92 | echo "You are not registered || Error in registration2"; |
99 | - } |
|
100 | - else |
|
93 | + } else |
|
101 | 94 | { |
102 | 95 | $query = "INSERT INTO profile VALUES('$userId', 'Joined OpenChat', 'Joined OpenChat', '')"; |
103 | 96 | if(!$this->connect->query($query)) { |
@@ -113,8 +106,7 @@ discard block |
||
113 | 106 | return json_encode([ |
114 | 107 | "location" => URL."/account.php" |
115 | 108 | ]); |
116 | - } |
|
117 | - else |
|
109 | + } else |
|
118 | 110 | { |
119 | 111 | return json_encode($this->error); |
120 | 112 | } |
@@ -76,8 +76,8 @@ |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * @dataProvider ClassNameProvider |
|
80 | - */ |
|
79 | + * @dataProvider ClassNameProvider |
|
80 | + */ |
|
81 | 81 | public function testClassExists($className) |
82 | 82 | { |
83 | 83 | $this->assertTrue(class_exists($className)); |