[pLog-svn] r6914 - in plog/branches/lifetype-1.2/class: action/admin data/validator summary/action test/tests/data/validator
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Wed Sep 9 14:26:24 EDT 2009
Author: jondaley
Date: 2009-09-09 14:26:24 -0400 (Wed, 09 Sep 2009)
New Revision: 6914
Modified:
plog/branches/lifetype-1.2/class/action/admin/adminloginaction.class.php
plog/branches/lifetype-1.2/class/data/validator/usernamevalidator.class.php
plog/branches/lifetype-1.2/class/summary/action/summarysendresetemail.class.php
plog/branches/lifetype-1.2/class/test/tests/data/validator/usernamevalidator_test.class.php
Log:
a user asked for this code, (bug #1608) but now that I've done it, I don't think it is correct. I'll check it in, and revert it, so we have a copy of it, in case he convinces me that it is a good fix
Modified: plog/branches/lifetype-1.2/class/action/admin/adminloginaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/adminloginaction.class.php 2009-09-09 17:52:17 UTC (rev 6913)
+++ plog/branches/lifetype-1.2/class/action/admin/adminloginaction.class.php 2009-09-09 18:26:24 UTC (rev 6914)
@@ -40,7 +40,7 @@
$this->_locale =& Locales::getLocale( $this->_config->getValue( "default_locale" ));
// data validation
- $this->registerFieldValidator( "userName", new UsernameValidator());
+ $this->registerFieldValidator( "userName", new UsernameValidator(false));
$this->registerFieldValidator( "userPassword", new StringValidator());
$view = new AdminDefaultView();
$view->setErrorMessage( $this->_locale->tr("error_incorrect_username_or_password"));
Modified: plog/branches/lifetype-1.2/class/data/validator/usernamevalidator.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/data/validator/usernamevalidator.class.php 2009-09-09 17:52:17 UTC (rev 6913)
+++ plog/branches/lifetype-1.2/class/data/validator/usernamevalidator.class.php 2009-09-09 18:26:24 UTC (rev 6914)
@@ -25,17 +25,19 @@
*/
class UsernameValidator extends Validator
{
- function UsernameValidator()
+ function UsernameValidator($checkForbidden=true)
{
$this->Validator();
$this->addRule( new NonEmptyRule());
$this->addRule( new RegExpRule( ONLY_ALPHANUMERIC_REGEXP ));
$this->addRule( new StringRangeRule( 1, 15 )); // to make sure they're not longer than 15 characters
- $config =& Config::getConfig();
- $forbiddenUsernames = $config->getValue( "forbidden_usernames", "" );
- $forbiddenUsernamesArray = explode( " ", $forbiddenUsernames );
- $this->addRule( new FilteredPatternsRule( $forbiddenUsernamesArray, false ));
+ if($checkForbidden){
+ $config =& Config::getConfig();
+ $forbiddenUsernames = $config->getValue( "forbidden_usernames", "" );
+ $forbiddenUsernamesArray = explode( " ", $forbiddenUsernames );
+ $this->addRule( new FilteredPatternsRule( $forbiddenUsernamesArray, false ));
+ }
}
}
?>
\ No newline at end of file
Modified: plog/branches/lifetype-1.2/class/summary/action/summarysendresetemail.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/summary/action/summarysendresetemail.class.php 2009-09-09 17:52:17 UTC (rev 6913)
+++ plog/branches/lifetype-1.2/class/summary/action/summarysendresetemail.class.php 2009-09-09 18:26:24 UTC (rev 6914)
@@ -31,7 +31,7 @@
$this->_request->registerFilter( "userEmail", $f );
// data validation
- $this->registerFieldValidator( "userName", new UsernameValidator());
+ $this->registerFieldValidator( "userName", new UsernameValidator(false));
$this->registerFieldValidator( "userEmail", new EmailValidator());
$this->setValidationErrorView( new SummaryView( "resetpassword" ));
}
Modified: plog/branches/lifetype-1.2/class/test/tests/data/validator/usernamevalidator_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/data/validator/usernamevalidator_test.class.php 2009-09-09 17:52:17 UTC (rev 6913)
+++ plog/branches/lifetype-1.2/class/test/tests/data/validator/usernamevalidator_test.class.php 2009-09-09 18:26:24 UTC (rev 6914)
@@ -47,7 +47,24 @@
$this->assertFalse( $this->u->validate( $tmp ), "A forbidden username should not be accepted as valid!" );
}
-
+
+ /**
+ * tests that a forbidden username does not validate
+ */
+ function testUnforbiddenUsername()
+ {
+ // get the list of forbidden words, based on our configuration settings
+ lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
+ $config =& Config::getConfig();
+
+ $forbiddenUsernames = $config->getValue( "forbidden_usernames" );
+ $forbiddenUsernamesArray = explode( " ", $forbiddenUsernames );
+ $tmp = array_pop( $forbiddenUsernamesArray );
+
+ $uf = new UsernameValidator(false);
+ $this->assertTrue( $uf->validate( $tmp ), "A forbidden username should not be blocked when ignoring forbidden names!" );
+ }
+
/**
* test a username with upper-case characters
*/
More information about the pLog-svn
mailing list