Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTORING/IMPROVEMENT] 1-minimal deep rewrite #98

Closed
wants to merge 33 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
366eaec
Update Registration.php
nyamsprod Jun 30, 2013
41c4947
Update Registration.php
nyamsprod Jun 30, 2013
a5abd2e
Update Registration.php
nyamsprod Jun 30, 2013
fe42bc0
Update Registration.php
nyamsprod Jun 30, 2013
51a7210
Update db.php
nyamsprod Jun 30, 2013
9bbf08c
Update Registration.php
nyamsprod Jun 30, 2013
11be254
typo fix
nyamsprod Jun 30, 2013
5302c6f
Update Registration.php
nyamsprod Jun 30, 2013
0c45054
Update Registration.php
nyamsprod Jun 30, 2013
cdd481c
Registration is extended from Auth.php
nyamsprod Jul 1, 2013
9216378
Login/php extends Auth.php
nyamsprod Jul 1, 2013
2f6b2f3
Create Auth.php
nyamsprod Jul 1, 2013
04b8800
Added function to validate submitted data
nyamsprod Jul 1, 2013
4009d4e
Added PHPDocs comments
nyamsprod Jul 1, 2013
7189e45
Adding check to see if the session is not corrupted
nyamsprod Jul 1, 2013
ba8166f
Added Methods and PHPDocs comments
nyamsprod Jul 1, 2013
fe524eb
Update Login.php
nyamsprod Jul 1, 2013
35c41db
Update Registration.php
nyamsprod Jul 1, 2013
6fa71f8
Update Registration.php
nyamsprod Jul 1, 2013
cbff6b8
Update Auth.php
nyamsprod Jul 1, 2013
f3c8693
Update Registration.php
nyamsprod Jul 1, 2013
54abd4e
Update Registration.php
nyamsprod Jul 1, 2013
4d67fc1
Change method visibility
nyamsprod Jul 1, 2013
1903f8e
Update Login.php
nyamsprod Jul 1, 2013
51c8c7b
Update register.php
nyamsprod Jul 1, 2013
1400bf1
Update not_logged_in.php
nyamsprod Jul 1, 2013
25dca9c
Update not_logged_in.php
nyamsprod Jul 1, 2013
34aa25b
Update register.php
nyamsprod Jul 1, 2013
c5332c4
Update index.php
nyamsprod Jul 1, 2013
b858f08
Update register.php
nyamsprod Jul 1, 2013
0d8d0b8
Bug and indentation fixes
ignace-dev Jul 1, 2013
937125a
Bug fixes and example rewrite to help understand the new code for 1-m…
ignace-dev Jul 2, 2013
d1edbde
Update db.php
nyamsprod Jul 2, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Added Methods and PHPDocs comments
  • Loading branch information
nyamsprod committed Jul 1, 2013
commit ba8166f25def819bea095911b0b19455a57b1410
67 changes: 60 additions & 7 deletions 1-minimal/classes/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Auth
{
private $conn; // database connection
private $errors = array(); // collection of error messages
private $regexp = array(
public static final $regexp = array(
'user_name' => '^[a-zA-Z0-9]{2,64}$',
'user_password' => '^.{6,}$'
);
Expand All @@ -23,6 +23,9 @@ class Auth
const USER_EXISTS = 1;
const USER_UNKNOWN = 2;

/**
* The Constructor initialize the db connection
*/
public function __construct()
{
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
Expand All @@ -31,6 +34,27 @@ public function __construct()
}
}

/**
* Return the errors
* @param string $name an specified regular expression
* @return mixed
*/
public function getRegexp($name = null)
{
if (is_null($name)) {
return self::$regexp;
}
if (isset(self::$regexp[$name])) {
return self::$regexp[$name];
}
return null;
}

/**
* Return the errors
* @param string $name an specified error
* @return mixed
*/
public function getErrors($name = null)
{
if (is_null($name)) {
Expand All @@ -42,7 +66,12 @@ public function getErrors($name = null)
return null;
}

protected function isValidEmail($str = null)
/**
* check to see if the email is valid
* @param string $str the email to test
* @return mixed return the status to work with filter_* function
*/
public static function isValidEmail($str = null)
{
if (is_null($str)) {
return null;
Expand All @@ -55,7 +84,12 @@ protected function isValidEmail($str = null)
return $str;
}

protected function isValidPassword($str = null)
/**
* check to see if the password is valid
* @param string $str the password to test
* @return mixed the status to work with filter_* function
*/
public static function isValidPassword($str = null)
{
if (is_null($str)) {
return null;
Expand All @@ -65,7 +99,7 @@ protected function isValidPassword($str = null)
FILTER_VALIDATE_REGEXP,
array(
'options' => array(
'regexp' => '/'.$this->regexp['user_password'].'/'
'regexp' => '/'.self::regexp['user_password'].'/'
)
)
);
Expand All @@ -76,7 +110,12 @@ protected function isValidPassword($str = null)
return $str;
}

protected function isValidUserName($str = null)
/**
* check to see if the username is valid
* @param string $str the username to test
* @return mixed the status to work with filter_* function
*/
public static function isValidUserName($str = null)
{
if (is_null($str)) {
return null;
Expand All @@ -86,7 +125,7 @@ protected function isValidUserName($str = null)
FILTER_VALIDATE_REGEXP,
array(
'options' => array(
'regexp' => '/'.$this->regexp['user_name'].'/'
'regexp' => '/'.self::regexp['user_name'].'/'
)
)
);
Expand All @@ -95,7 +134,21 @@ protected function isValidUserName($str = null)
}

return $str;

}

/**
* return the user data
* @param str $login the user name
*
* @return array the user info
*/
private function getUserByName($login)
{
$login = $this->conn->real_escape_string($login);
$res = $this->conn->query("SELECT * FROM users WHERE user_name = '$login'");
if ($res->num_rows != 1) {
return array();
}
return $res->fetch_assoc();
}
}