1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Validate Class Doc Comment |
4
|
|
|
* |
5
|
|
|
* PHP version 5 |
6
|
|
|
* |
7
|
|
|
* @category PHP |
8
|
|
|
* @package Registration-Module |
9
|
|
|
* @author Ankit Jain <[email protected]> |
10
|
|
|
* @license The MIT License (MIT) |
11
|
|
|
* @link https://github.com/ankitjain28may/registration-module |
12
|
|
|
*/ |
13
|
|
|
namespace AnkitJain\RegistrationModule; |
14
|
|
|
require_once dirname(__DIR__) . '/config/database.php'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* For validation the Email and Username in DB. |
18
|
|
|
* |
19
|
|
|
* @category PHP |
20
|
|
|
* @package Registration-Module |
21
|
|
|
* @author Ankit Jain <[email protected]> |
22
|
|
|
* @license The MIT License (MIT) |
23
|
|
|
* @link https://github.com/ankitjain28may/registration-module |
24
|
|
|
*/ |
25
|
|
|
class Validate |
26
|
|
|
{ |
27
|
|
|
/* |
28
|
|
|
|-------------------------------------------------------------------------- |
29
|
|
|
| Validate Class |
30
|
|
|
|-------------------------------------------------------------------------- |
31
|
|
|
| |
32
|
|
|
| For validation the Email and Username in DB. |
33
|
|
|
| |
34
|
|
|
*/ |
35
|
|
|
|
36
|
|
|
protected $connect; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create a new controller instance. |
40
|
|
|
* |
41
|
|
|
* @return void |
|
|
|
|
42
|
|
|
*/ |
43
|
|
|
public function __construct() |
44
|
|
|
{ |
45
|
|
|
$this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* For checking whether the credentials are empty or not |
50
|
|
|
* |
51
|
|
|
* @param string $email Contains the email for checking |
52
|
|
|
* |
53
|
|
|
* @return 0 | 1 |
|
|
|
|
54
|
|
|
*/ |
55
|
|
View Code Duplication |
public function validateEmailInDb($email) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$query = "SELECT login_id FROM login WHERE email = '$email'"; |
58
|
|
|
if ($result = $this->connect->query($query)) { |
59
|
|
|
if ($result->num_rows > 0) { |
60
|
|
|
return 1; |
61
|
|
|
} |
62
|
|
|
return 0; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* For checking whether the credentials are empty or not |
68
|
|
|
* |
69
|
|
|
* @param string $username Contains the username for checking |
70
|
|
|
* |
71
|
|
|
* @return 0 | 1 |
|
|
|
|
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public function validateUsernameInDb($username) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$query = "SELECT login_id FROM login WHERE username = '$username'"; |
76
|
|
|
if ($result = $this->connect->query($query)) { |
77
|
|
|
if ($result->num_rows > 0) { |
78
|
|
|
return 1; |
79
|
|
|
} |
80
|
|
|
return 0; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.