@@ -5,6 +5,9 @@ |
||
| 5 | 5 | |
| 6 | 6 | class Session{ |
| 7 | 7 | |
| 8 | + /** |
|
| 9 | + * @param string $key |
|
| 10 | + */ |
|
| 8 | 11 | public static function put($key, $value){ |
| 9 | 12 | $_SESSION[$key] = $value; |
| 10 | 13 | } |
@@ -3,17 +3,17 @@ |
||
| 3 | 3 | namespace AnkitJain\RegistrationModule; |
| 4 | 4 | @session_start(); |
| 5 | 5 | |
| 6 | -class Session{ |
|
| 6 | +class Session { |
|
| 7 | 7 | |
| 8 | - public static function put($key, $value){ |
|
| 8 | + public static function put($key, $value) { |
|
| 9 | 9 | $_SESSION[$key] = $value; |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | - public static function get($key){ |
|
| 12 | + public static function get($key) { |
|
| 13 | 13 | return (isset($_SESSION[$key]) ? $_SESSION[$key] : null); |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - public static function forget($key){ |
|
| 16 | + public static function forget($key) { |
|
| 17 | 17 | unset($_SESSION[$key]); |
| 18 | 18 | } |
| 19 | 19 | } |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace AnkitJain\RegistrationModule; |
| 4 | -require (dirname(__DIR__) . '/registration-module/vendor/autoload.php'); |
|
| 4 | +require (dirname(__DIR__).'/registration-module/vendor/autoload.php'); |
|
| 5 | 5 | use AnkitJain\RegistrationModule\Session; |
| 6 | 6 | |
| 7 | -if(Session::get('start') != null) |
|
| 7 | +if (Session::get('start') != null) |
|
| 8 | 8 | { |
| 9 | 9 | Session::forget('start'); |
| 10 | 10 | header('Location: index.php'); |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | session_start(); |
| 3 | -if(isset($_SESSION['start'])) |
|
| 3 | +if (isset($_SESSION['start'])) |
|
| 4 | 4 | { |
| 5 | 5 | header("Location: account.php"); |
| 6 | 6 | } |
@@ -1,18 +1,18 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace AnkitJain\RegistrationModule; |
| 4 | -require (dirname(__DIR__) . '/vendor/autoload.php'); |
|
| 4 | +require (dirname(__DIR__).'/vendor/autoload.php'); |
|
| 5 | 5 | use AnkitJain\RegistrationModule\Login; |
| 6 | 6 | @session_start(); |
| 7 | 7 | |
| 8 | -if(isset($_POST['q'])) |
|
| 8 | +if (isset($_POST['q'])) |
|
| 9 | 9 | { |
| 10 | 10 | $loginField = json_decode($_POST['q']); |
| 11 | 11 | $login = $loginField->login; |
| 12 | 12 | $password = $loginField->password; |
| 13 | 13 | $obLogin = new Login(); |
| 14 | 14 | $result = $obLogin->authLogin($login, $password); |
| 15 | - if(isset($result)) |
|
| 15 | + if (isset($result)) |
|
| 16 | 16 | echo $result; |
| 17 | 17 | else |
| 18 | 18 | echo json_encode([]); |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace AnkitJain\RegistrationModule; |
| 3 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
| 3 | +require_once (dirname(__DIR__).'/config/database.php'); |
|
| 4 | 4 | |
| 5 | 5 | class Validate |
| 6 | 6 | { |
@@ -1,18 +1,18 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace AnkitJain\RegistrationModule; |
| 4 | -require (dirname(__DIR__) . '/vendor/autoload.php'); |
|
| 4 | +require (dirname(__DIR__).'/vendor/autoload.php'); |
|
| 5 | 5 | use AnkitJain\RegistrationModule\Login; |
| 6 | 6 | @session_start(); |
| 7 | 7 | |
| 8 | -if(isset($_POST['q'])) |
|
| 8 | +if (isset($_POST['q'])) |
|
| 9 | 9 | { |
| 10 | 10 | $loginField = json_decode($_POST['q']); |
| 11 | 11 | $login = $loginField->login; |
| 12 | 12 | $password = $loginField->password; |
| 13 | 13 | $obLogin = new Login(); |
| 14 | 14 | $result = $obLogin->authLogin($login, $password); |
| 15 | - if(isset($result)) |
|
| 15 | + if (isset($result)) |
|
| 16 | 16 | echo $result; |
| 17 | 17 | else |
| 18 | 18 | echo json_encode([]); |
@@ -79,6 +79,9 @@ |
||
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | + /** |
|
| 83 | + * @param string $value |
|
| 84 | + */ |
|
| 82 | 85 | public function onError($key, $value) |
| 83 | 86 | { |
| 84 | 87 | $this->flag = 1; |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | namespace AnkitJain\RegistrationModule; |
| 4 | 4 | use AnkitJain\RegistrationModule\Validate; |
| 5 | 5 | use AnkitJain\RegistrationModule\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 | { |
@@ -30,16 +30,16 @@ discard block |
||
| 30 | 30 | $password = $data["passRegister"]; |
| 31 | 31 | $userId = ''; |
| 32 | 32 | |
| 33 | - if(filter_var($email, FILTER_VALIDATE_EMAIL) == false) |
|
| 33 | + if (filter_var($email, FILTER_VALIDATE_EMAIL) == false) |
|
| 34 | 34 | { |
| 35 | 35 | $this->onError("email", " *Enter correct Email address"); |
| 36 | 36 | } |
| 37 | - else if($this->obValidate->validateEmailInDb($email) === 1) |
|
| 37 | + else if ($this->obValidate->validateEmailInDb($email) === 1) |
|
| 38 | 38 | { |
| 39 | 39 | $this->onError("email", " *Email is already registered"); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - if($this->obValidate->validateUsernameInDb($username) === 1) |
|
| 42 | + if ($this->obValidate->validateUsernameInDb($username) === 1) |
|
| 43 | 43 | { |
| 44 | 44 | $this->onError("username", " *Username is already registered"); |
| 45 | 45 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $this->onError("mob", " *Enter correct Mobile Number"); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if($this->flag == 1) |
|
| 51 | + if ($this->flag == 1) |
|
| 52 | 52 | { |
| 53 | 53 | return json_encode($this->error); |
| 54 | 54 | } |
@@ -56,20 +56,20 @@ discard block |
||
| 56 | 56 | $password = md5($password); |
| 57 | 57 | |
| 58 | 58 | $query = "INSERT INTO register VALUES(null, '$email', '$username', '$password')"; |
| 59 | - if(!$this->connect->query($query)) |
|
| 59 | + if (!$this->connect->query($query)) |
|
| 60 | 60 | { |
| 61 | - return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); |
|
| 61 | + return json_encode(["Error" => "You are not registered, ".$this->connect->error]); |
|
| 62 | 62 | } |
| 63 | 63 | $query = "SELECT id FROM register WHERE email = '$email'"; |
| 64 | - if($result = $this->connect->query($query)) |
|
| 64 | + if ($result = $this->connect->query($query)) |
|
| 65 | 65 | { |
| 66 | 66 | $row = $result->fetch_assoc(); |
| 67 | 67 | $userId = $row['id']; |
| 68 | 68 | $query = "INSERT INTO login VALUES('$userId', '$name', '$email', '$username', '$mob')"; |
| 69 | 69 | |
| 70 | - if(!$this->connect->query($query)) |
|
| 70 | + if (!$this->connect->query($query)) |
|
| 71 | 71 | { |
| 72 | - return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); |
|
| 72 | + return json_encode(["Error" => "You are not registered, ".$this->connect->error]); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | Session::put('start', $userId); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | foreach ($data as $key => $value) { |
| 99 | 99 | $data[$key] = trim($data[$key]); |
| 100 | 100 | $value = trim($value); |
| 101 | - if(empty($value)) |
|
| 101 | + if (empty($value)) |
|
| 102 | 102 | { |
| 103 | 103 | $this->onError($key, $errorCode[$key]); |
| 104 | 104 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace AnkitJain\RegistrationModule; |
| 4 | 4 | use AnkitJain\RegistrationModule\Session; |
| 5 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
| 5 | +require_once (dirname(__DIR__).'/config/database.php'); |
|
| 6 | 6 | |
| 7 | 7 | class Login |
| 8 | 8 | { |
@@ -28,13 +28,13 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | if (preg_match("/^[@]{1}$/", $login)) |
| 30 | 30 | { |
| 31 | - if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
|
| 31 | + if (filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
|
| 32 | 32 | { |
| 33 | 33 | $this->onError("login", " *Enter correct Email address"); |
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if($this->flag == 0) |
|
| 37 | + if ($this->flag == 0) |
|
| 38 | 38 | { |
| 39 | 39 | $password = md5($password); |
| 40 | 40 | $query = "SELECT * FROM login WHERE email = '$login' or username = '$login'"; |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | $row = $result->fetch_assoc(); |
| 46 | 46 | $loginID = $row['login_id']; |
| 47 | 47 | $query = "SELECT id FROM register WHERE id = '$loginID' and password = '$password'"; |
| 48 | - if($result = $this->connect->query($query)) |
|
| 48 | + if ($result = $this->connect->query($query)) |
|
| 49 | 49 | { |
| 50 | 50 | if ($result->num_rows > 0) |
| 51 | 51 | { |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | $this->onError("passLogin", " *Invalid password"); |
| 58 | 58 | return json_encode($this->error); |
| 59 | 59 | } |
| 60 | - return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); |
|
| 60 | + return json_encode(["Error" => "You are not registered, ".$this->connect->error]); |
|
| 61 | 61 | } |
| 62 | 62 | $this->onError("login", " *Invalid username or email"); |
| 63 | 63 | return json_encode($this->error); |
| 64 | 64 | } |
| 65 | - return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); |
|
| 65 | + return json_encode(["Error" => "You are not registered, ".$this->connect->error]); |
|
| 66 | 66 | } |
| 67 | 67 | else |
| 68 | 68 | { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | foreach ($data as $key => $value) { |
| 88 | 88 | $data[$key] = trim($data[$key]); |
| 89 | 89 | $value = trim($value); |
| 90 | - if(empty($value)) |
|
| 90 | + if (empty($value)) |
|
| 91 | 91 | { |
| 92 | 92 | $this->onError($key, $errorCode[$key]); |
| 93 | 93 | } |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | // Define database connection constants |
| 3 | 3 | define('DB_HOST', '127.0.0.1'); |
| 4 | 4 | define('DB_USER', 'root'); |
| 5 | - define('DB_PASSWORD',''); |
|
| 5 | + define('DB_PASSWORD', ''); |
|
| 6 | 6 | define('DB_NAME', 'account'); |
| 7 | 7 | define('URL', 'http://127.0.0.1/openchat'); |
| 8 | 8 | |