@@ -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 | } |
@@ -5,16 +5,16 @@ |
||
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 | } |
20 | 20 | ?> |
21 | 21 | \ No newline at end of file |
@@ -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 | } |
@@ -11,6 +11,9 @@ discard block |
||
11 | 11 | $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
12 | 12 | } |
13 | 13 | |
14 | + /** |
|
15 | + * @param string $email |
|
16 | + */ |
|
14 | 17 | function validateEmailInDb($email) |
15 | 18 | { |
16 | 19 | $query = "SELECT login_id FROM login WHERE email = '$email'"; |
@@ -24,6 +27,9 @@ discard block |
||
24 | 27 | } |
25 | 28 | } |
26 | 29 | |
30 | + /** |
|
31 | + * @param string $username |
|
32 | + */ |
|
27 | 33 | function validateUsernameInDb($username) |
28 | 34 | { |
29 | 35 | $query = "SELECT login_id FROM login WHERE username = '$username'"; |
@@ -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,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,11 +1,11 @@ discard block |
||
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\Register; |
6 | 6 | @session_start(); |
7 | 7 | |
8 | -if(isset($_POST['q'])) |
|
8 | +if (isset($_POST['q'])) |
|
9 | 9 | { |
10 | 10 | $registerField = json_decode($_POST['q']); |
11 | 11 | $name = $registerField->name; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | $password = $registerField->password; |
16 | 16 | $obRegister = new Register(); |
17 | 17 | $result = $obRegister->authRegister($name, $email, $username, $password, $mob); |
18 | - if(isset($result)) |
|
18 | + if (isset($result)) |
|
19 | 19 | echo $result; |
20 | 20 | else |
21 | 21 | echo json_encode([]); |
@@ -15,9 +15,10 @@ |
||
15 | 15 | $password = $registerField->password; |
16 | 16 | $obRegister = new Register(); |
17 | 17 | $result = $obRegister->authRegister($name, $email, $username, $password, $mob); |
18 | - if(isset($result)) |
|
19 | - echo $result; |
|
20 | - else |
|
21 | - echo json_encode([]); |
|
22 | -} |
|
18 | + if(isset($result)) { |
|
19 | + echo $result; |
|
20 | + } else { |
|
21 | + echo json_encode([]); |
|
22 | + } |
|
23 | + } |
|
23 | 24 | ?> |
@@ -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 | ?> |
@@ -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 | { |
@@ -38,42 +38,42 @@ discard block |
||
38 | 38 | $this->error = array_merge($this->error, ["name" => " *Enter the name"]); |
39 | 39 | } |
40 | 40 | |
41 | - if(empty($this->email)) { |
|
41 | + if (empty($this->email)) { |
|
42 | 42 | $this->key = 1; |
43 | 43 | $this->error = array_merge($this->error, ["email" => " *Enter the email address"]); |
44 | 44 | } |
45 | - elseif(filter_var($this->email, FILTER_VALIDATE_EMAIL) == false) { |
|
45 | + elseif (filter_var($this->email, FILTER_VALIDATE_EMAIL) == false) { |
|
46 | 46 | $this->key = 1; |
47 | 47 | $this->error = array_merge($this->error, ["email" => " *Enter correct Email address"]); |
48 | 48 | } |
49 | 49 | else |
50 | 50 | { |
51 | - if($this->obValidate->validateEmailInDb($this->email)) |
|
51 | + if ($this->obValidate->validateEmailInDb($this->email)) |
|
52 | 52 | { |
53 | 53 | $this->key = 1; |
54 | 54 | $this->error = array_merge($this->error, ["email" => " *Email is already registered"]); |
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - if(empty($this->username)) { |
|
58 | + if (empty($this->username)) { |
|
59 | 59 | $this->key = 1; |
60 | 60 | $this->error = array_merge($this->error, ["username" => " *Enter the username"]); |
61 | 61 | } |
62 | 62 | else |
63 | 63 | { |
64 | - if($this->obValidate->validateUsernameInDb($this->username)) |
|
64 | + if ($this->obValidate->validateUsernameInDb($this->username)) |
|
65 | 65 | { |
66 | 66 | $this->key = 1; |
67 | 67 | $this->error = array_merge($this->error, ["username" => " *Username is already registered"]); |
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | - if(empty($this->password)) { |
|
71 | + if (empty($this->password)) { |
|
72 | 72 | $this->key = 1; |
73 | 73 | $this->error = array_merge($this->error, ["password" => " *Enter the password"]); |
74 | 74 | } |
75 | 75 | |
76 | - if(empty($this->mob)) { |
|
76 | + if (empty($this->mob)) { |
|
77 | 77 | $this->key = 1; |
78 | 78 | $this->error = array_merge($this->error, ["mob" => " *Enter the Mobile Number"]); |
79 | 79 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $this->error = array_merge($this->error, ["mob" => " *Enter correct Mobile Number"]); |
83 | 83 | } |
84 | 84 | |
85 | - if($this->key == 1) |
|
85 | + if ($this->key == 1) |
|
86 | 86 | { |
87 | 87 | return json_encode($this->error); |
88 | 88 | } |
@@ -91,19 +91,19 @@ discard block |
||
91 | 91 | $this->key = 0; |
92 | 92 | $pass = md5($this->password); |
93 | 93 | $query = "INSERT INTO register VALUES(null, '$this->email', '$this->username', '$pass')"; |
94 | - if(!$this->connect->query($query)) { |
|
94 | + if (!$this->connect->query($query)) { |
|
95 | 95 | $this->key = 1; |
96 | 96 | echo "You are not registered || Error in registration2"; |
97 | 97 | } |
98 | 98 | else |
99 | 99 | { |
100 | 100 | $query = "SELECT id FROM register WHERE email = '$this->email'"; |
101 | - if($result = $this->connect->query($query)) { |
|
101 | + if ($result = $this->connect->query($query)) { |
|
102 | 102 | $row = $result->fetch_assoc(); |
103 | 103 | $UserId = $row['id']; |
104 | 104 | |
105 | 105 | $query = "INSERT INTO login VALUES('$UserId', '$this->name', '$this->email', '$this->username', '$this->mob')"; |
106 | - if(!$this->connect->query($query)) { |
|
106 | + if (!$this->connect->query($query)) { |
|
107 | 107 | $this->key = 1; |
108 | 108 | echo "You are not registered || Error in registration1"; |
109 | 109 | } |
@@ -41,12 +41,10 @@ discard block |
||
41 | 41 | if(empty($this->email)) { |
42 | 42 | $this->key = 1; |
43 | 43 | $this->error = array_merge($this->error, ["email" => " *Enter the email address"]); |
44 | - } |
|
45 | - elseif(filter_var($this->email, FILTER_VALIDATE_EMAIL) == false) { |
|
44 | + } elseif(filter_var($this->email, FILTER_VALIDATE_EMAIL) == false) { |
|
46 | 45 | $this->key = 1; |
47 | 46 | $this->error = array_merge($this->error, ["email" => " *Enter correct Email address"]); |
48 | - } |
|
49 | - else |
|
47 | + } else |
|
50 | 48 | { |
51 | 49 | if($this->obValidate->validateEmailInDb($this->email)) |
52 | 50 | { |
@@ -58,8 +56,7 @@ discard block |
||
58 | 56 | if(empty($this->username)) { |
59 | 57 | $this->key = 1; |
60 | 58 | $this->error = array_merge($this->error, ["username" => " *Enter the username"]); |
61 | - } |
|
62 | - else |
|
59 | + } else |
|
63 | 60 | { |
64 | 61 | if($this->obValidate->validateUsernameInDb($this->username)) |
65 | 62 | { |
@@ -76,8 +73,7 @@ discard block |
||
76 | 73 | if(empty($this->mob)) { |
77 | 74 | $this->key = 1; |
78 | 75 | $this->error = array_merge($this->error, ["mob" => " *Enter the Mobile Number"]); |
79 | - } |
|
80 | - elseif (!preg_match("/^[0-9]{10}$/", $this->mob)) { |
|
76 | + } elseif (!preg_match("/^[0-9]{10}$/", $this->mob)) { |
|
81 | 77 | $this->key = 1; |
82 | 78 | $this->error = array_merge($this->error, ["mob" => " *Enter correct Mobile Number"]); |
83 | 79 | } |
@@ -85,8 +81,7 @@ discard block |
||
85 | 81 | if($this->key == 1) |
86 | 82 | { |
87 | 83 | return json_encode($this->error); |
88 | - } |
|
89 | - else |
|
84 | + } else |
|
90 | 85 | { |
91 | 86 | $this->key = 0; |
92 | 87 | $pass = md5($this->password); |
@@ -94,8 +89,7 @@ discard block |
||
94 | 89 | if(!$this->connect->query($query)) { |
95 | 90 | $this->key = 1; |
96 | 91 | echo "You are not registered || Error in registration2"; |
97 | - } |
|
98 | - else |
|
92 | + } else |
|
99 | 93 | { |
100 | 94 | $query = "SELECT id FROM register WHERE email = '$this->email'"; |
101 | 95 | if($result = $this->connect->query($query)) { |
@@ -115,8 +109,7 @@ discard block |
||
115 | 109 | return json_encode([ |
116 | 110 | "location" => URL."/account.php" |
117 | 111 | ]); |
118 | - } |
|
119 | - else |
|
112 | + } else |
|
120 | 113 | { |
121 | 114 | return json_encode($this->error); |
122 | 115 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace AnkitJain\RegistrationModule; |
3 | 3 | use AnkitJain\RegistrationModule\Session; |
4 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
4 | +require_once (dirname(__DIR__).'/config/database.php'); |
|
5 | 5 | |
6 | 6 | class Login |
7 | 7 | { |
@@ -25,20 +25,20 @@ discard block |
||
25 | 25 | $this->login = trim($login); |
26 | 26 | $this->password = trim($password); |
27 | 27 | |
28 | - if(empty($this->login)) |
|
28 | + if (empty($this->login)) |
|
29 | 29 | { |
30 | 30 | $this->key = 1; |
31 | 31 | $this->error = array_merge($this->error, ["login" => " *Enter the login field"]); |
32 | 32 | } |
33 | 33 | elseif (preg_match("/^[@]{1}$/", $this->login)) |
34 | 34 | { |
35 | - if(filter_var($this->email, FILTER_VALIDATE_EMAIL) == false) |
|
35 | + if (filter_var($this->email, FILTER_VALIDATE_EMAIL) == false) |
|
36 | 36 | { |
37 | 37 | $this->key = 1; |
38 | 38 | $this->error = array_merge($this->error, ["login" => " *Enter correct Email address"]); |
39 | 39 | } |
40 | 40 | } |
41 | - if(empty($this->password)) { |
|
41 | + if (empty($this->password)) { |
|
42 | 42 | $this->key = 1; |
43 | 43 | $this->error = array_merge($this->error, ["password" => " *Enter the password"]); |
44 | 44 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $pass = md5($this->password); |
48 | 48 | } |
49 | 49 | |
50 | - if($this->key == 0) |
|
50 | + if ($this->key == 0) |
|
51 | 51 | { |
52 | 52 | $query = "SELECT * FROM login WHERE email = '$this->login' or username = '$this->login'"; |
53 | 53 | if ($result = $this->connect->query($query)) |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $row = $result->fetch_assoc(); |
58 | 58 | $loginID = $row['login_id']; |
59 | 59 | $query = "SELECT id FROM register WHERE id = '$loginID' and password = '$pass'"; |
60 | - if($result = $this->connect->query($query)) |
|
60 | + if ($result = $this->connect->query($query)) |
|
61 | 61 | { |
62 | 62 | if ($result->num_rows > 0) |
63 | 63 | { |
@@ -29,8 +29,7 @@ discard block |
||
29 | 29 | { |
30 | 30 | $this->key = 1; |
31 | 31 | $this->error = array_merge($this->error, ["login" => " *Enter the login field"]); |
32 | - } |
|
33 | - elseif (preg_match("/^[@]{1}$/", $this->login)) |
|
32 | + } elseif (preg_match("/^[@]{1}$/", $this->login)) |
|
34 | 33 | { |
35 | 34 | if(filter_var($this->email, FILTER_VALIDATE_EMAIL) == false) |
36 | 35 | { |
@@ -41,8 +40,7 @@ discard block |
||
41 | 40 | if(empty($this->password)) { |
42 | 41 | $this->key = 1; |
43 | 42 | $this->error = array_merge($this->error, ["password" => " *Enter the password"]); |
44 | - } |
|
45 | - else |
|
43 | + } else |
|
46 | 44 | { |
47 | 45 | $pass = md5($this->password); |
48 | 46 | } |
@@ -65,23 +63,20 @@ discard block |
||
65 | 63 | return json_encode([ |
66 | 64 | "location" => URL."/account.php" |
67 | 65 | ]); |
68 | - } |
|
69 | - else |
|
66 | + } else |
|
70 | 67 | { |
71 | 68 | $this->error = array_merge($this->error, ["password" => " *Invalid password"]); |
72 | 69 | return json_encode($this->error); |
73 | 70 | } |
74 | 71 | } |
75 | - } |
|
76 | - else |
|
72 | + } else |
|
77 | 73 | { |
78 | 74 | $this->error = array_merge($this->error, ["login" => " *Invalid username or email"]); |
79 | 75 | return json_encode($this->error); |
80 | 76 | } |
81 | 77 | } |
82 | 78 | |
83 | - } |
|
84 | - else |
|
79 | + } else |
|
85 | 80 | { |
86 | 81 | return json_encode($this->error); |
87 | 82 | } |