Issue #306 - Making logic in the UserManager class about usernames more precise. Adding new methods UserManager::purify_username() and UserManager::is_username_valid().
// 1. ASCII-letters and digits only are acceptable, 20 characters length.
// 2. Empty username is formally valid, but it is reserved for the anonymous user.
define('USERNAME_MAX_LENGTH', 20);
define('USERNAME_PURIFIER', '/[^0-9A-Za-z]/');
define('USERNAME_PURIFIER_SHALLOW', '/\s/');
// Constants for user extra field types.
define('USER_FIELD_TYPE_TEXT',1);
define('USER_FIELD_TYPE_TEXTAREA',2);
define('USER_FIELD_TYPE_TEXT',1);
define('USER_FIELD_TYPE_TEXTAREA',2);
define('USER_FIELD_TYPE_RADIO',3);
define('USER_FIELD_TYPE_SELECT',4);
define('USER_FIELD_TYPE_SELECT_MULTIPLE',5);
define('USER_FIELD_TYPE_DATE',6);
define('USER_FIELD_TYPE_DATETIME',7);
define('USER_FIELD_TYPE_DOUBLE_SELECT',8);
define('USER_FIELD_TYPE_DIVIDER',9);
define('USER_FIELD_TYPE_SELECT_MULTIPLE',5);
define('USER_FIELD_TYPE_DATE',6);
define('USER_FIELD_TYPE_DATETIME',7);
define('USER_FIELD_TYPE_DOUBLE_SELECT',8);
define('USER_FIELD_TYPE_DIVIDER',9);
class UserManager {
private function __construct () {
@ -405,21 +408,51 @@ class UserManager {
return $username;
}
/**
* Modifies a given username for compliance with the specification.
* @param $username string The input username.
* @param bool $strict (optional) When this flag is TRUE, the result is guaranteed for full compliance, otherwise compliance may be partial. The default value is FALSE.
* @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 string The resulting purified username.
*/
public function purify_username($username, $strict = false, $encoding = null) {
if ($strict) {
// 1. Conversion of unacceptable letters (latinian letters with accents for example) into ASCII letters in order they not to be totally removed.
* @param int The name of the field we want to know everything about
* @return array Array containing all the information about the extra profile field (first level of array contains field details, then 'options' sub-array contains options details, as returned by the database)
* @author Julio Montoya
* @since Dokeos 1.8.6
* @since Dokeos 1.8.6
*/
public static function get_extra_field_information_by_name ($field_variable, $fuzzy=false) {
// database table definition
@ -1531,7 +1565,7 @@ class UserManager {
*/
public static function get_personal_session_course_list ($user_id) {