@@ -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 | } |
@@ -5,15 +5,15 @@ |
||
5 | 5 | |
6 | 6 | class Session{ |
7 | 7 | |
8 | - public static function put($key, $value){ |
|
9 | - $_SESSION[$key] = $value; |
|
10 | - } |
|
8 | + public static function put($key, $value){ |
|
9 | + $_SESSION[$key] = $value; |
|
10 | + } |
|
11 | 11 | |
12 | - public static function get($key){ |
|
13 | - return (isset($_SESSION[$key]) ? $_SESSION[$key] : null); |
|
14 | - } |
|
12 | + public static function get($key){ |
|
13 | + return (isset($_SESSION[$key]) ? $_SESSION[$key] : null); |
|
14 | + } |
|
15 | 15 | |
16 | - public static function forget($key){ |
|
17 | - unset($_SESSION[$key]); |
|
18 | - } |
|
16 | + public static function forget($key){ |
|
17 | + unset($_SESSION[$key]); |
|
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'); |
@@ -8,8 +8,7 @@ |
||
8 | 8 | { |
9 | 9 | Session::forget('start'); |
10 | 10 | header('Location: index.php'); |
11 | -} |
|
12 | -else |
|
11 | +} else |
|
13 | 12 | { |
14 | 13 | echo "Please Login"; |
15 | 14 | } |
@@ -8,15 +8,15 @@ |
||
8 | 8 | |
9 | 9 | function URL() |
10 | 10 | { |
11 | - $http = "http://"; |
|
12 | - @$host = $_SERVER['SERVER_NAME']; |
|
13 | - @$port = $_SERVER['SERVER_PORT']; |
|
14 | - $fol = ""; |
|
15 | - if(@$_SERVER['SERVER_ADDR']!=NULL) |
|
16 | - { |
|
17 | - $fol = "/".explode('/', $_SERVER['PHP_SELF'])[1]; |
|
18 | - } |
|
19 | - $url = $http.$host.":".$port.$fol; |
|
20 | - return $url; |
|
11 | + $http = "http://"; |
|
12 | + @$host = $_SERVER['SERVER_NAME']; |
|
13 | + @$port = $_SERVER['SERVER_PORT']; |
|
14 | + $fol = ""; |
|
15 | + if(@$_SERVER['SERVER_ADDR']!=NULL) |
|
16 | + { |
|
17 | + $fol = "/".explode('/', $_SERVER['PHP_SELF'])[1]; |
|
18 | + } |
|
19 | + $url = $http.$host.":".$port.$fol; |
|
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', 'account'); |
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 | } |
@@ -2,7 +2,7 @@ |
||
2 | 2 | session_start(); |
3 | 3 | if(isset($_SESSION['start'])) |
4 | 4 | { |
5 | - header("Location: account.php"); |
|
5 | + header("Location: account.php"); |
|
6 | 6 | } |
7 | 7 | ?> |
8 | 8 | <!Doctype html> |
@@ -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([]); |
@@ -11,8 +11,9 @@ |
||
11 | 11 | $password = $loginField->password; |
12 | 12 | $obLogin = new Login(); |
13 | 13 | $result = $obLogin->authLogin($login, $password); |
14 | - if(isset($result)) |
|
15 | - echo $result; |
|
16 | - else |
|
17 | - echo json_encode([]); |
|
18 | -} |
|
19 | 14 | \ No newline at end of file |
15 | + if(isset($result)) { |
|
16 | + echo $result; |
|
17 | + } else { |
|
18 | + echo json_encode([]); |
|
19 | + } |
|
20 | + } |
|
20 | 21 | \ No newline at end of file |
@@ -10,10 +10,10 @@ |
||
10 | 10 | $login = $loginField->login; |
11 | 11 | $password = $loginField->password; |
12 | 12 | $obLogin = new Login(); |
13 | - $data = array( |
|
14 | - 'login' => $login, |
|
15 | - 'passLogin' => $password |
|
16 | - ); |
|
13 | + $data = array( |
|
14 | + 'login' => $login, |
|
15 | + 'passLogin' => $password |
|
16 | + ); |
|
17 | 17 | $result = $obLogin->authLogin($data); |
18 | 18 | if(isset($result)) |
19 | 19 | echo $result; |
@@ -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 | { |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | { |
19 | 19 | if ($result->num_rows > 0) { |
20 | 20 | return 1; |
21 | + } else { |
|
22 | + return 0; |
|
21 | 23 | } |
22 | - else |
|
23 | - return 0; |
|
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | if ($result = $this->connect->query($query)) { |
31 | 31 | if ($result->num_rows > 0) { |
32 | 32 | return 1; |
33 | + } else { |
|
34 | + return 0; |
|
33 | 35 | } |
34 | - else |
|
35 | - return 0; |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | } |
@@ -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([]); |
@@ -12,9 +12,10 @@ |
||
12 | 12 | $password = $loginField->password; |
13 | 13 | $obLogin = new Login(); |
14 | 14 | $result = $obLogin->authLogin($login, $password); |
15 | - if(isset($result)) |
|
16 | - echo $result; |
|
17 | - else |
|
18 | - echo json_encode([]); |
|
19 | -} |
|
15 | + if(isset($result)) { |
|
16 | + echo $result; |
|
17 | + } else { |
|
18 | + echo json_encode([]); |
|
19 | + } |
|
20 | + } |
|
20 | 21 | ?> |
@@ -71,6 +71,9 @@ |
||
71 | 71 | $this->connect->close(); |
72 | 72 | } |
73 | 73 | |
74 | + /** |
|
75 | + * @param string $value |
|
76 | + */ |
|
74 | 77 | public function onError($key, $value) |
75 | 78 | { |
76 | 79 | $this->flag = 1; |
@@ -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 | } |
@@ -63,8 +63,7 @@ |
||
63 | 63 | return json_encode($this->error); |
64 | 64 | } |
65 | 65 | return json_encode(["Error" => "You are not registered, ".$this->connect->error ]); |
66 | - } |
|
67 | - else |
|
66 | + } else |
|
68 | 67 | { |
69 | 68 | return json_encode($this->error); |
70 | 69 | } |
@@ -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 | } |
@@ -33,8 +33,7 @@ |
||
33 | 33 | if(filter_var($email, FILTER_VALIDATE_EMAIL) == false) |
34 | 34 | { |
35 | 35 | $this->onError("email", " *Enter correct Email address"); |
36 | - } |
|
37 | - else if($this->obValidate->validateEmailInDb($email) === 1) |
|
36 | + } else if($this->obValidate->validateEmailInDb($email) === 1) |
|
38 | 37 | { |
39 | 38 | $this->onError("email", " *Email is already registered"); |
40 | 39 | } |