Julio Montoya 10 years ago
parent
commit
25505ae234
2 changed files with 23 additions and 35 deletions
  1. 1 3
      main/auth/profile.php
  2. 22 32
      main/inc/lib/formvalidator/Rule/Username.php

+ 1 - 3
main/auth/profile.php

@@ -155,9 +155,7 @@ if (api_get_setting('profile', 'login') !== 'true') {
 $form->applyFilter('username', 'stripslashes');
 $form->applyFilter('username', 'trim');
 $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
-if (api_get_setting('login_is_email') != 'true'){
-    $form->addRule('username', get_lang('UsernameWrong'), 'username');
-}
+$form->addRule('username', get_lang('UsernameWrong'), 'username');
 $form->addRule('username', get_lang('UserTaken'), 'username_available', $user_data['username']);
 
 //    OFFICIAL CODE

+ 22 - 32
main/inc/lib/formvalidator/Rule/Username.php

@@ -1,40 +1,30 @@
 <?php
-/*
-==============================================================================
-	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
-==============================================================================
-*/
+/* For licensing terms, see /license.txt */
 
 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 {
-	/**
-	 * 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, $options) {		
-		return UserManager::is_username_valid($username);
-	}
+class HTML_QuickForm_Rule_Username extends HTML_QuickForm_Rule
+{
+    /**
+     * Function to check if a username is of the correct format
+     *
+     * @param   string  $username Wanted username
+     * @param   array   $options
+     *
+     * @return boolean True if username is of the correct format
+     * @author Modified by Ivan Tcholakov, 15-SEP-2009.
+     * @see HTML_QuickForm_Rule
+     * The validation rule is served by the UserManager class as of this moment.
+     */
+    public function validate($username, $options)
+    {
+        if (api_get_setting('login_is_email') == 'true') {
+            return api_valid_email($username);
+        } else {
+            return UserManager::is_username_valid($username);
+        }
+    }
 }