@@ -11,96 +11,96 @@ |
||
| 11 | 11 | class Login |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - protected $flag; |
|
| 15 | - protected $error; |
|
| 16 | - protected $connect; |
|
| 14 | + protected $flag; |
|
| 15 | + protected $error; |
|
| 16 | + protected $connect; |
|
| 17 | 17 | |
| 18 | - public function __construct() |
|
| 19 | - { |
|
| 20 | - $this->flag = 0; |
|
| 21 | - $this->connect = mysqli_connect( |
|
| 18 | + public function __construct() |
|
| 19 | + { |
|
| 20 | + $this->flag = 0; |
|
| 21 | + $this->connect = mysqli_connect( |
|
| 22 | 22 | getenv('DB_HOST'), |
| 23 | 23 | getenv('DB_USER'), |
| 24 | 24 | getenv('DB_PASSWORD'), |
| 25 | 25 | getenv('DB_NAME') |
| 26 | 26 | ); |
| 27 | - $this->error = array(); |
|
| 28 | - } |
|
| 27 | + $this->error = array(); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function authLogin($data) |
|
| 31 | - { |
|
| 32 | - $data = $this->emptyValue($data); |
|
| 30 | + public function authLogin($data) |
|
| 31 | + { |
|
| 32 | + $data = $this->emptyValue($data); |
|
| 33 | 33 | |
| 34 | - $login = $data["login"]; |
|
| 35 | - $password = $data["passLogin"]; |
|
| 34 | + $login = $data["login"]; |
|
| 35 | + $password = $data["passLogin"]; |
|
| 36 | 36 | |
| 37 | - if (preg_match("/^.+[@]{1}.+$/", $login)) |
|
| 38 | - { |
|
| 39 | - if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
|
| 40 | - { |
|
| 41 | - $this->onError("login", " *Enter correct Email address"); |
|
| 42 | - } |
|
| 43 | - } |
|
| 37 | + if (preg_match("/^.+[@]{1}.+$/", $login)) |
|
| 38 | + { |
|
| 39 | + if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
|
| 40 | + { |
|
| 41 | + $this->onError("login", " *Enter correct Email address"); |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - if($this->flag == 0) |
|
| 46 | - { |
|
| 47 | - $password = md5($password); |
|
| 48 | - $query = "SELECT * FROM login WHERE email = '$login' or username = '$login'"; |
|
| 49 | - if ($result = $this->connect->query($query)) |
|
| 50 | - { |
|
| 51 | - if ($result->num_rows > 0) |
|
| 52 | - { |
|
| 53 | - $row = $result->fetch_assoc(); |
|
| 54 | - $loginID = $row['login_id']; |
|
| 55 | - $query = "SELECT id FROM register WHERE id = '$loginID' and password = '$password'"; |
|
| 56 | - if($result = $this->connect->query($query)) |
|
| 57 | - { |
|
| 58 | - if ($result->num_rows > 0) |
|
| 59 | - { |
|
| 60 | - Session::put('start', $loginID); |
|
| 61 | - return json_encode([ |
|
| 62 | - "location" => getenv('APP_URL')."/views/account.php" |
|
| 63 | - ]); |
|
| 64 | - } |
|
| 65 | - $this->onError("passLogin", " *Invalid password"); |
|
| 66 | - return json_encode($this->error); |
|
| 67 | - } |
|
| 68 | - return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); |
|
| 69 | - } |
|
| 70 | - $this->onError("login", " *Invalid username or email"); |
|
| 71 | - return json_encode($this->error); |
|
| 72 | - } |
|
| 73 | - return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); |
|
| 74 | - } |
|
| 75 | - else |
|
| 76 | - { |
|
| 77 | - return json_encode($this->error); |
|
| 78 | - } |
|
| 79 | - } |
|
| 45 | + if($this->flag == 0) |
|
| 46 | + { |
|
| 47 | + $password = md5($password); |
|
| 48 | + $query = "SELECT * FROM login WHERE email = '$login' or username = '$login'"; |
|
| 49 | + if ($result = $this->connect->query($query)) |
|
| 50 | + { |
|
| 51 | + if ($result->num_rows > 0) |
|
| 52 | + { |
|
| 53 | + $row = $result->fetch_assoc(); |
|
| 54 | + $loginID = $row['login_id']; |
|
| 55 | + $query = "SELECT id FROM register WHERE id = '$loginID' and password = '$password'"; |
|
| 56 | + if($result = $this->connect->query($query)) |
|
| 57 | + { |
|
| 58 | + if ($result->num_rows > 0) |
|
| 59 | + { |
|
| 60 | + Session::put('start', $loginID); |
|
| 61 | + return json_encode([ |
|
| 62 | + "location" => getenv('APP_URL')."/views/account.php" |
|
| 63 | + ]); |
|
| 64 | + } |
|
| 65 | + $this->onError("passLogin", " *Invalid password"); |
|
| 66 | + return json_encode($this->error); |
|
| 67 | + } |
|
| 68 | + return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); |
|
| 69 | + } |
|
| 70 | + $this->onError("login", " *Invalid username or email"); |
|
| 71 | + return json_encode($this->error); |
|
| 72 | + } |
|
| 73 | + return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); |
|
| 74 | + } |
|
| 75 | + else |
|
| 76 | + { |
|
| 77 | + return json_encode($this->error); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function onError($key, $value) |
|
| 82 | - { |
|
| 83 | - $this->flag = 1; |
|
| 84 | - $this->error = array_merge($this->error, [["key" => $key, "value" => $value]]); |
|
| 85 | - } |
|
| 81 | + public function onError($key, $value) |
|
| 82 | + { |
|
| 83 | + $this->flag = 1; |
|
| 84 | + $this->error = array_merge($this->error, [["key" => $key, "value" => $value]]); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - public function emptyValue($data) |
|
| 88 | - { |
|
| 89 | - $errorCode = array( |
|
| 90 | - "login" => " *Enter the login field", |
|
| 91 | - "passLogin" => " *Enter the password" |
|
| 92 | - ); |
|
| 87 | + public function emptyValue($data) |
|
| 88 | + { |
|
| 89 | + $errorCode = array( |
|
| 90 | + "login" => " *Enter the login field", |
|
| 91 | + "passLogin" => " *Enter the password" |
|
| 92 | + ); |
|
| 93 | 93 | |
| 94 | - foreach ($data as $key => $value) { |
|
| 95 | - $data[$key] = trim($data[$key]); |
|
| 96 | - $value = trim($value); |
|
| 97 | - if(empty($value)) |
|
| 98 | - { |
|
| 99 | - $this->onError($key, $errorCode[$key]); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - return $data; |
|
| 103 | - } |
|
| 94 | + foreach ($data as $key => $value) { |
|
| 95 | + $data[$key] = trim($data[$key]); |
|
| 96 | + $value = trim($value); |
|
| 97 | + if(empty($value)) |
|
| 98 | + { |
|
| 99 | + $this->onError($key, $errorCode[$key]); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + return $data; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | - * @depends test_authRegister |
|
| 55 | - * Testing for the login with correct credentials |
|
| 56 | - */ |
|
| 54 | + * @depends test_authRegister |
|
| 55 | + * Testing for the login with correct credentials |
|
| 56 | + */ |
|
| 57 | 57 | |
| 58 | 58 | public function test_authLogin() |
| 59 | 59 | { |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
| 80 | - * @depends test_authRegister |
|
| 81 | - * Testing for the login with empty credentials |
|
| 82 | - */ |
|
| 80 | + * @depends test_authRegister |
|
| 81 | + * Testing for the login with empty credentials |
|
| 82 | + */ |
|
| 83 | 83 | |
| 84 | 84 | public function test_authLoginEmptyValues() |
| 85 | 85 | { |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | - * @depends test_authRegister |
|
| 109 | - * Testing for the login with invalid or wrong email |
|
| 110 | - */ |
|
| 108 | + * @depends test_authRegister |
|
| 109 | + * Testing for the login with invalid or wrong email |
|
| 110 | + */ |
|
| 111 | 111 | |
| 112 | 112 | public function test_authLoginWrongEmail() |
| 113 | 113 | { |
@@ -129,9 +129,9 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | - * @depends test_authRegister |
|
| 133 | - * Testing for the login with invalid email credentials |
|
| 134 | - */ |
|
| 132 | + * @depends test_authRegister |
|
| 133 | + * Testing for the login with invalid email credentials |
|
| 134 | + */ |
|
| 135 | 135 | public function test_authLoginInvalidUsernameEmail() |
| 136 | 136 | { |
| 137 | 137 | $output = $this->obLogin->authLogin( |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | - * @depends test_authRegister |
|
| 156 | - * Testing for the login with invalid password credentials |
|
| 157 | - */ |
|
| 155 | + * @depends test_authRegister |
|
| 156 | + * Testing for the login with invalid password credentials |
|
| 157 | + */ |
|
| 158 | 158 | public function test_authLoginInvalidPassword() |
| 159 | 159 | { |
| 160 | 160 | $output = $this->obLogin->authLogin( |
@@ -174,9 +174,9 @@ discard block |
||
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | - * @depends test_authRegister |
|
| 178 | - * Testing for the Profile::class with valid login_id |
|
| 179 | - */ |
|
| 177 | + * @depends test_authRegister |
|
| 178 | + * Testing for the Profile::class with valid login_id |
|
| 179 | + */ |
|
| 180 | 180 | public function test_getProfile() |
| 181 | 181 | { |
| 182 | 182 | $output = Profile::getProfile(1); |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | - * @depends test_authRegister |
|
| 193 | - * Testing for the Profile::class with invalid login_id |
|
| 194 | - */ |
|
| 192 | + * @depends test_authRegister |
|
| 193 | + * Testing for the Profile::class with invalid login_id |
|
| 194 | + */ |
|
| 195 | 195 | public function test_getProfileInvalidID() |
| 196 | 196 | { |
| 197 | 197 | $output = Profile::getProfile(0); |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
| 202 | - * @depends test_authRegister |
|
| 203 | - * Testing for the User::class with valid login_id |
|
| 204 | - */ |
|
| 202 | + * @depends test_authRegister |
|
| 203 | + * Testing for the User::class with valid login_id |
|
| 204 | + */ |
|
| 205 | 205 | public function test_userDetails() |
| 206 | 206 | { |
| 207 | 207 | $expectedOutput = [ |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | - * @depends test_authRegister |
|
| 224 | - * Testing for the User::class with invalid data |
|
| 225 | - */ |
|
| 223 | + * @depends test_authRegister |
|
| 224 | + * Testing for the User::class with invalid data |
|
| 225 | + */ |
|
| 226 | 226 | public function test_userDetailsInvalidID() |
| 227 | 227 | { |
| 228 | 228 | $output = $this->obUser->userDetails(0, True); |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
| 233 | - * @depends test_authRegister |
|
| 234 | - * Testing for the Validate::class for email |
|
| 235 | - */ |
|
| 233 | + * @depends test_authRegister |
|
| 234 | + * Testing for the Validate::class for email |
|
| 235 | + */ |
|
| 236 | 236 | public function test_validateEmailInDb() |
| 237 | 237 | { |
| 238 | 238 | $output = $this->obValidate->validateEmailInDb('[email protected]'); |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | - * @depends test_authRegister |
|
| 244 | - * Testing for the Validate::class for username |
|
| 245 | - */ |
|
| 243 | + * @depends test_authRegister |
|
| 244 | + * Testing for the Validate::class for username |
|
| 245 | + */ |
|
| 246 | 246 | public function test_validateUsernameInDb() |
| 247 | 247 | { |
| 248 | 248 | $output = $this->obValidate->validateUsernameInDb('test'); |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
| 253 | - * @depends test_authRegister |
|
| 254 | - * Testing for the Validate::class for non-existing username |
|
| 255 | - */ |
|
| 253 | + * @depends test_authRegister |
|
| 254 | + * Testing for the Validate::class for non-existing username |
|
| 255 | + */ |
|
| 256 | 256 | public function test_validateUsernameInDbNot() |
| 257 | 257 | { |
| 258 | 258 | $output = $this->obValidate->validateUsernameInDb('abc'); |
@@ -260,9 +260,9 @@ discard block |
||
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
| 263 | - * @depends test_authRegister |
|
| 264 | - * Testing for the Validate::class for non-existing email |
|
| 265 | - */ |
|
| 263 | + * @depends test_authRegister |
|
| 264 | + * Testing for the Validate::class for non-existing email |
|
| 265 | + */ |
|
| 266 | 266 | public function test_validateEmailInDbNot() |
| 267 | 267 | { |
| 268 | 268 | $output = $this->obValidate->validateEmailInDb('[email protected]'); |
@@ -270,9 +270,9 @@ discard block |
||
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | - * @depends test_authRegister |
|
| 274 | - * Testing for the Online::class |
|
| 275 | - */ |
|
| 273 | + * @depends test_authRegister |
|
| 274 | + * Testing for the Online::class |
|
| 275 | + */ |
|
| 276 | 276 | public function test_Online() |
| 277 | 277 | { |
| 278 | 278 | Online::setOnlineStatus(1); |
@@ -287,9 +287,9 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | - * @depends test_Online |
|
| 291 | - * Empty the DB |
|
| 292 | - */ |
|
| 290 | + * @depends test_Online |
|
| 291 | + * Empty the DB |
|
| 292 | + */ |
|
| 293 | 293 | public function test_EmptyDB() |
| 294 | 294 | { |
| 295 | 295 | $connect = mysqli_connect( |