Browse Source

Issue #306 - FormValidator: Updating code for the validation rule 'username'. This rule is served by the UserManager class now.

Ivan Tcholakov 15 years ago
parent
commit
a3019a9959
2 changed files with 15 additions and 14 deletions
  1. 15 13
      main/inc/lib/formvalidator/Rule/Username.php
  2. 0 1
      main/inc/lib/usermanager.lib.php

+ 15 - 13
main/inc/lib/formvalidator/Rule/Username.php

@@ -2,40 +2,42 @@
 /*
 ==============================================================================
 	Dokeos - elearning and course management software
-	
+
 	Copyright (c) 2004-2005 Dokeos S.A.
 	Copyright (c) Bart Mollet, Hogeschool Gent
-	
+
 	For a full list of contributors, see "credits.txt".
 	The full license can be read in "license.txt".
-	
+
 	This program is free software; you can redistribute it and/or
 	modify it under the terms of the GNU General Public License
 	as published by the Free Software Foundation; either version 2
 	of the License, or (at your option) any later version.
-	
+
 	See the GNU General Public License for more details.
-	
+
 	Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
 	Mail: info@dokeos.com
 ==============================================================================
 */
-require_once ('HTML/QuickForm/Rule.php');
+
+require_once 'HTML/QuickForm/Rule.php';
+
 /**
  * QuickForm rule to check if a username is of the correct format
  */
-class HTML_QuickForm_Rule_Username extends HTML_QuickForm_Rule
-{
+class HTML_QuickForm_Rule_Username extends HTML_QuickForm_Rule {
 	/**
 	 * Function to check if a username is of the correct format
 	 * @see HTML_QuickForm_Rule
 	 * @param string $username Wanted username
 	 * @return boolean True if username is of the correct format
+	 * @author Modified by Ivan Tcholakov, 15-SEP-2009. The validation rule is served by the UserManager class as of this moment.
 	 */
-	function validate($username)
-	{
-		$filtered_username = eregi_replace('[^a-z0-9_.-@-]', '_', strtr($username, '�����������������������������������������������������', 'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn'));
-		return $filtered_username == $username;
+	function validate($username) {
+		if (!class_exists('UserManager')) {
+			require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
+		}
+		return UserManager::is_username_valid($username);
 	}
 }
-?>

+ 0 - 1
main/inc/lib/usermanager.lib.php

@@ -421,7 +421,6 @@ class UserManager {
 	/**
 	 * Checks whether a given username matches to the specification strictly. The empty username is assumed here as invalid.
 	 * Mostly this function is to be used in the user interface built-in validation routines for providing feedback while usernames are enterd manually.
-	 * TODO: Before applying this method, currently implemented UI validation has to be studied.
 	 * @param string $username				The input username.
 	 * @param string $encoding (optional)	The character encoding for the input names. If it is omitted, the platform character set will be used by default.
 	 * @return bool							Returns TRUE if the username is valid, FALSE otherwise.