Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
Tz Tools
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
3e664ea6
authored
2010-04-21 14:59:53 +0000
by
Chris Boden
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Added Validation library, updated Auth component
1 parent
25c1a81a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
26 deletions
com/Auth/Auth.php
lib/Validation.php
com/Auth/Auth.php
View file @
3e664ea
...
...
@@ -33,7 +33,7 @@ class Auth {
}
$auth
=
_signon
(
Array
(
'user_login'
=>
$username
'user_login'
=>
esc_sql
(
$username
)
,
'user_password'
=>
esc_sql
(
$password
)
,
'remember'
=>
$remember
));
...
...
@@ -63,9 +63,23 @@ class Auth {
}
public
static
function
register
(
$user_data
=
Array
(),
$registration_method
)
{
require_once
(
ABSPATH
.
WPINC
.
DIRECTORY_SEPARATOR
.
'registration.php'
);
$valid
=
new
Auth_Validation
(
$user_data
);
if
(
count
(
$valid
->
errors
)
>
0
)
{
throw
new
BadMethodCallException
(
implode
(
"
\n
"
,
$valid
->
errors
));
}
public
static
function
activate
()
{
array_filter
(
$user_data
,
'esc_sql'
);
$id
=
(
int
)
_insert_user
(
$user_data
);
global
$wpdb
;
$wpdb
->
query
(
"UPDATE `
{
$wpdb
->
users
}
` SET `user_status` = 1 WHERE `ID` =
{
$id
}
"
);
return
$id
;
}
public
static
function
activate
(
$username
,
$activation_key
)
{
do_action
(
self
::
ACTION_ACTIVATE
,
$user_id
);
}
...
...
@@ -74,63 +88,49 @@ class Auth {
}
}
class
Auth_Validation
{
public
static
$errors
=
Array
();
class
Auth_Validation
extends
Validation
{
/**
* @rule Not blank
* @rule Valid WordPress username
* @returns Boolean
*/
p
ublic
static
function
username
(
$val
)
{
p
rotected
function
username
(
$val
)
{
if
(
empty
(
$val
))
{
self
::
$errors
[]
=
'Username is blank'
;
return
false
;
throw
new
Exception
(
'Username is blank'
);
}
require_once
(
ABSPATH
.
WPINC
.
DIRECTORY_SEPARATOR
.
'registration.php'
);
if
(
!
validate_username
(
$val
))
{
self
::
$errors
[]
=
'Username must be at least 4 characters, letters and numbers only'
;
return
false
;
throw
new
Exception
(
'Username must be at least 4 characters, letters and numbers only'
);
}
if
(
username_exists
(
$_POST
[
'reg_username'
]))
{
self
::
$errors
[]
=
'Username already exists'
;
return
false
;
throw
new
Exception
(
'Username already exists'
);
}
return
true
;
}
/**
* @rule Not blank
* @returns Boolean
*/
p
ublic
static
function
password
(
$val
)
{
p
rotected
function
password
(
$val
)
{
if
(
empty
(
$val
))
{
self
::
$errors
[]
=
'Password can not be blank'
;
return
false
;
throw
new
Exception
(
'Password can not be blank'
);
}
return
true
;
}
/**
* @rule Valid email address (*@*.*)
* @returns Boolean
*/
p
ublic
static
function
email
(
$val
)
{
p
rotected
function
email
(
$val
)
{
if
(
!
(
boolean
)
filter_var
(
$val
,
FILTER_VALIDATE_EMAIL
))
{
self
::
$errors
[]
=
'Invalid email address'
;
return
false
;
throw
new
Exception
(
'Invalid email address'
);
}
if
(
false
!==
email_exists
(
$val
))
{
self
::
$errors
[]
=
'Email address already registered'
;
return
false
;
throw
new
Exception
(
'Email address already registered'
);
}
return
true
;
}
}
?>
\ No newline at end of file
...
...
lib/Validation.php
0 → 100644
View file @
3e664ea
<?php
abstract
class
Validation
{
/**
* Associative array of valid fields
* @type Array
* @public
* @read-only
*/
private
$valid
=
Array
();
/**
* Associative array if invalid fields
* @type Array
* @public
* @read-only
*/
private
$errors
=
Array
();
/**
* @param {Array} $data Associative array of data to validate
*/
final
public
function
__construct
(
Array
$data
)
{
foreach
(
$data
as
$key
=>
$val
)
{
if
(
method_exists
(
$this
,
$key
))
{
try
{
call_user_func
(
Array
(
$this
,
$key
),
$val
);
$this
->
valid
[
$key
]
=
$val
;
}
catch
(
Exception
$e
)
{
$this
->
errors
[
$key
]
=
$e
->
getMessage
();
}
}
}
}
/**
* @private
*/
final
public
function
__get
(
$key
)
{
$private
=
$key
;
if
(
isset
(
$this
->
$private
))
{
return
$this
->
$private
;
}
}
}
?>
Please
register
or
sign in
to post a comment