@@ -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 | } |
@@ -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,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 |
@@ -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 | { |
@@ -24,20 +24,20 @@ discard block |
||
24 | 24 | $login = trim($login); |
25 | 25 | $password = trim($password); |
26 | 26 | |
27 | - if(empty($login)) |
|
27 | + if (empty($login)) |
|
28 | 28 | { |
29 | 29 | $this->key = 1; |
30 | 30 | $this->error = array_merge($this->error, ["login" => " *Enter the login field"]); |
31 | 31 | } |
32 | 32 | elseif (preg_match("/^[@]{1}$/", $login)) |
33 | 33 | { |
34 | - if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
|
34 | + if (filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
|
35 | 35 | { |
36 | 36 | $this->key = 1; |
37 | 37 | $this->error = array_merge($this->error, ["login" => " *Enter correct Email address"]); |
38 | 38 | } |
39 | 39 | } |
40 | - if(empty($password)) { |
|
40 | + if (empty($password)) { |
|
41 | 41 | $this->key = 1; |
42 | 42 | $this->error = array_merge($this->error, ["password" => " *Enter the password"]); |
43 | 43 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | $pass = md5($password); |
47 | 47 | } |
48 | 48 | |
49 | - if($this->key == 0) |
|
49 | + if ($this->key == 0) |
|
50 | 50 | { |
51 | 51 | $query = "SELECT * FROM login WHERE email = '$login' or username = '$login'"; |
52 | 52 | if ($result = $this->connect->query($query)) |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $row = $result->fetch_assoc(); |
57 | 57 | $loginID = $row['login_id']; |
58 | 58 | $query = "SELECT id FROM register WHERE id = '$loginID' and password = '$pass'"; |
59 | - if($result = $this->connect->query($query)) |
|
59 | + if ($result = $this->connect->query($query)) |
|
60 | 60 | { |
61 | 61 | if ($result->num_rows > 0) |
62 | 62 | { |
@@ -28,8 +28,7 @@ discard block |
||
28 | 28 | { |
29 | 29 | $this->key = 1; |
30 | 30 | $this->error = array_merge($this->error, ["login" => " *Enter the login field"]); |
31 | - } |
|
32 | - elseif (preg_match("/^[@]{1}$/", $login)) |
|
31 | + } elseif (preg_match("/^[@]{1}$/", $login)) |
|
33 | 32 | { |
34 | 33 | if(filter_var($login, FILTER_VALIDATE_EMAIL) == false) |
35 | 34 | { |
@@ -40,8 +39,7 @@ discard block |
||
40 | 39 | if(empty($password)) { |
41 | 40 | $this->key = 1; |
42 | 41 | $this->error = array_merge($this->error, ["password" => " *Enter the password"]); |
43 | - } |
|
44 | - else |
|
42 | + } else |
|
45 | 43 | { |
46 | 44 | $pass = md5($password); |
47 | 45 | } |
@@ -64,23 +62,20 @@ discard block |
||
64 | 62 | return json_encode([ |
65 | 63 | "location" => URL."/account.php" |
66 | 64 | ]); |
67 | - } |
|
68 | - else |
|
65 | + } else |
|
69 | 66 | { |
70 | 67 | $this->error = array_merge($this->error, ["password" => " *Invalid password"]); |
71 | 68 | return json_encode($this->error); |
72 | 69 | } |
73 | 70 | } |
74 | - } |
|
75 | - else |
|
71 | + } else |
|
76 | 72 | { |
77 | 73 | $this->error = array_merge($this->error, ["login" => " *Invalid username or email"]); |
78 | 74 | return json_encode($this->error); |
79 | 75 | } |
80 | 76 | } |
81 | 77 | |
82 | - } |
|
83 | - else |
|
78 | + } else |
|
84 | 79 | { |
85 | 80 | return json_encode($this->error); |
86 | 81 | } |
@@ -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 | { |
@@ -32,45 +32,45 @@ discard block |
||
32 | 32 | $this->onError(["name" => " *Enter the name"]); |
33 | 33 | } |
34 | 34 | |
35 | - if(empty($email)) { |
|
35 | + if (empty($email)) { |
|
36 | 36 | $this->onError(["email" => " *Enter the email address"]); |
37 | 37 | } |
38 | - elseif(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
38 | + elseif (filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
39 | 39 | $this->onError(["email" => " *Enter correct Email address"]); |
40 | 40 | } |
41 | 41 | else |
42 | 42 | { |
43 | - if($this->obValidate->validateEmailInDb($email) === 1) |
|
43 | + if ($this->obValidate->validateEmailInDb($email) === 1) |
|
44 | 44 | { |
45 | 45 | |
46 | 46 | $this->onError(["email" => " *Email is already registered"]); |
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | - if(empty($username)) { |
|
50 | + if (empty($username)) { |
|
51 | 51 | $this->onError(["username" => " *Enter the username"]); |
52 | 52 | } |
53 | 53 | else |
54 | 54 | { |
55 | - if($this->obValidate->validateUsernameInDb($username) === 1) |
|
55 | + if ($this->obValidate->validateUsernameInDb($username) === 1) |
|
56 | 56 | { |
57 | 57 | |
58 | 58 | $this->onError(["username" => " *Username is already registered"]); |
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | - if(empty($password)) { |
|
62 | + if (empty($password)) { |
|
63 | 63 | $this->onError(["password" => " *Enter the password"]); |
64 | 64 | } |
65 | 65 | |
66 | - if(empty($mob)) { |
|
66 | + if (empty($mob)) { |
|
67 | 67 | $this->onError(["mob" => " *Enter the Mobile Number"]); |
68 | 68 | } |
69 | 69 | elseif (!preg_match("/^[0-9]{10}$/", $mob)) { |
70 | 70 | $this->onError(["mob" => " *Enter correct Mobile Number"]); |
71 | 71 | } |
72 | 72 | |
73 | - if($this->key == 1) |
|
73 | + if ($this->key == 1) |
|
74 | 74 | { |
75 | 75 | return json_encode($this->error); |
76 | 76 | } |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | $this->key = 0; |
80 | 80 | $pass = md5($password); |
81 | 81 | $query = "INSERT INTO register VALUES(null, '$email', '$username', '$pass')"; |
82 | - if(!$this->connect->query($query)) { |
|
82 | + if (!$this->connect->query($query)) { |
|
83 | 83 | $this->key = 1; |
84 | 84 | echo "You are not registered || Error in registration2"; |
85 | 85 | } |
86 | 86 | else |
87 | 87 | { |
88 | 88 | $query = "SELECT id FROM register WHERE email = '$email'"; |
89 | - if($result = $this->connect->query($query)) { |
|
89 | + if ($result = $this->connect->query($query)) { |
|
90 | 90 | $row = $result->fetch_assoc(); |
91 | 91 | $UserId = $row['id']; |
92 | 92 | |
93 | 93 | $query = "INSERT INTO login VALUES('$UserId', '$name', '$email', '$username', '$mob')"; |
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 registration1"; |
97 | 97 | } |
@@ -34,11 +34,9 @@ discard block |
||
34 | 34 | |
35 | 35 | if(empty($email)) { |
36 | 36 | $this->onError(["email" => " *Enter the email address"]); |
37 | - } |
|
38 | - elseif(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
37 | + } elseif(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
39 | 38 | $this->onError(["email" => " *Enter correct Email address"]); |
40 | - } |
|
41 | - else |
|
39 | + } else |
|
42 | 40 | { |
43 | 41 | if($this->obValidate->validateEmailInDb($email) === 1) |
44 | 42 | { |
@@ -49,8 +47,7 @@ discard block |
||
49 | 47 | |
50 | 48 | if(empty($username)) { |
51 | 49 | $this->onError(["username" => " *Enter the username"]); |
52 | - } |
|
53 | - else |
|
50 | + } else |
|
54 | 51 | { |
55 | 52 | if($this->obValidate->validateUsernameInDb($username) === 1) |
56 | 53 | { |
@@ -65,16 +62,14 @@ discard block |
||
65 | 62 | |
66 | 63 | if(empty($mob)) { |
67 | 64 | $this->onError(["mob" => " *Enter the Mobile Number"]); |
68 | - } |
|
69 | - elseif (!preg_match("/^[0-9]{10}$/", $mob)) { |
|
65 | + } elseif (!preg_match("/^[0-9]{10}$/", $mob)) { |
|
70 | 66 | $this->onError(["mob" => " *Enter correct Mobile Number"]); |
71 | 67 | } |
72 | 68 | |
73 | 69 | if($this->key == 1) |
74 | 70 | { |
75 | 71 | return json_encode($this->error); |
76 | - } |
|
77 | - else |
|
72 | + } else |
|
78 | 73 | { |
79 | 74 | $this->key = 0; |
80 | 75 | $pass = md5($password); |
@@ -82,8 +77,7 @@ discard block |
||
82 | 77 | if(!$this->connect->query($query)) { |
83 | 78 | $this->key = 1; |
84 | 79 | echo "You are not registered || Error in registration2"; |
85 | - } |
|
86 | - else |
|
80 | + } else |
|
87 | 81 | { |
88 | 82 | $query = "SELECT id FROM register WHERE email = '$email'"; |
89 | 83 | if($result = $this->connect->query($query)) { |
@@ -103,8 +97,7 @@ discard block |
||
103 | 97 | return json_encode([ |
104 | 98 | "location" => URL."/account.php" |
105 | 99 | ]); |
106 | - } |
|
107 | - else |
|
100 | + } else |
|
108 | 101 | { |
109 | 102 | return json_encode($this->error); |
110 | 103 | } |
@@ -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 | ?> |