@@ -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 | |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | - * @depends test_authRegister |
|
| 46 | - */ |
|
| 45 | + * @depends test_authRegister |
|
| 46 | + */ |
|
| 47 | 47 | |
| 48 | 48 | public function test_authLogin() |
| 49 | 49 | { |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | - * @depends test_authRegister |
|
| 71 | - */ |
|
| 70 | + * @depends test_authRegister |
|
| 71 | + */ |
|
| 72 | 72 | |
| 73 | 73 | public function test_authLoginEmptyValues() |
| 74 | 74 | { |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | - * @depends test_authRegister |
|
| 98 | - */ |
|
| 97 | + * @depends test_authRegister |
|
| 98 | + */ |
|
| 99 | 99 | |
| 100 | 100 | public function test_authLoginWrongEmail() |
| 101 | 101 | { |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | - * @depends test_authRegister |
|
| 121 | - */ |
|
| 120 | + * @depends test_authRegister |
|
| 121 | + */ |
|
| 122 | 122 | public function test_authLoginInvalidUsernameEmail() |
| 123 | 123 | { |
| 124 | 124 | $output = $this->obLogin->authLogin( |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | - * @depends test_authRegister |
|
| 143 | - */ |
|
| 142 | + * @depends test_authRegister |
|
| 143 | + */ |
|
| 144 | 144 | public function test_authLoginInvalidPassword() |
| 145 | 145 | { |
| 146 | 146 | $output = $this->obLogin->authLogin( |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
| 163 | - * @depends test_authLogin |
|
| 164 | - */ |
|
| 163 | + * @depends test_authLogin |
|
| 164 | + */ |
|
| 165 | 165 | public function test_EmptyDB() |
| 166 | 166 | { |
| 167 | 167 | $connect = mysqli_connect( |