Changeset 1428

Show
Ignore:
Timestamp:
10/30/09 14:21:05 (4 years ago)
Author:
gbastien
Message:

* Network can now be set as case insensitive. Emails are now never case sensitive and usernames' case sensitivity is consistent with network settings (#616)
* Yet again some tab alignment

Location:
trunk/wifidog-auth
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/CHANGELOG

    r1424 r1428  
    11# $Id$ 
    22 
     32009-10-30 Geneviève Bastien <gbastien@versatic.net> 
     4  * Network can now be set as case insensitive.  Emails are now never case sensitive and usernames' case sensitivity is consistent with network settings (#616) 
     5  * Yet again some tab alignment 
     6   
    372009-10-02 Geneviève Bastien <gbastien@versatic.net> 
    48  * Email address format now corresponds to newer standard RFC2822 (#624) 
  • trunk/wifidog-auth/wifidog/classes/AbstractDb.php

    r1421 r1428  
    142142 
    143143        if ($debug == TRUE) 
    144         echo "<p>".sprintf(_("Elapsed time for query execution : %.6f second(s)"), $sql_timetaken)."</p>\n"; 
     144            echo "<p>".sprintf(_("Elapsed time for query execution : %.6f second(s)"), $sql_timetaken)."</p>\n"; 
    145145 
    146146        if ($result == FALSE) 
     
    317317    { 
    318318        $retval = ""; 
    319  
     319         
    320320        /* PHP time */ 
    321321        $parts_of_starttime = explode(' ', $this->construct_start_time); 
  • trunk/wifidog-auth/wifidog/classes/Authenticators/AuthenticatorLocalUser.php

    r1419 r1428  
    119119        } 
    120120        else{ 
     121            /* gbastien: this is not reusable!!, why not use password directly? */ 
     122            //$password_hash = User::passwordHash($_REQUEST['password']); 
     123            $password_hash = User::passwordHash($password); 
    121124            $password = $db->escapeString($password); 
    122             $password_hash = User::passwordHash($_REQUEST['password']); 
    123  
    124             $sql = "SELECT user_id FROM users WHERE (username='$username' OR email='$username') AND account_origin='".$this->getNetwork()->getId()."' AND pass='$password_hash'"; 
     125             
     126            $comparison = ($this->getNetwork()->getUsernamesCaseSensitive()? ' = ': ' ILike '); 
     127            $sql = "SELECT user_id FROM users WHERE (username$comparison'$username' OR email$comparison'$username') AND account_origin='".$this->getNetwork()->getId()."' AND pass='$password_hash'"; 
    125128            $db->execSqlUniqueRes($sql, $user_info, false); 
    126129 
     
    141144                 */ 
    142145                $user_info = null; 
    143                 $db->execSqlUniqueRes("SELECT * FROM users WHERE (username='$username' OR email='$username') AND account_origin='".$this->getNetwork()->getId()."'", $user_info, false); 
     146                $db->execSqlUniqueRes("SELECT * FROM users WHERE (username$comparison'$username' OR email$comparison'$username') AND account_origin='".$this->getNetwork()->getId()."'", $user_info, false); 
    144147 
    145148                if ($user_info == null) { 
  • trunk/wifidog-auth/wifidog/classes/Network.php

    r1421 r1428  
    16181618        return $retVal; 
    16191619    } 
     1620     
     1621          /** Are usernames on this network case sensitive or not 
     1622     * 
     1623     * @return bool true or false 
     1624     */ 
     1625    public function getUsernamesCaseSensitive() 
     1626    { 
     1627        return (($this->_row['usernames_case_sensitive'] == 't') ? true : false); 
     1628    } 
     1629 
     1630    /** Are usernames on this network case sensitive or not 
     1631     * If set to false, we need to verify if some users have name-clash and propose actions 
     1632     * 
     1633     * @param string $value The new creation date 
     1634     * 
     1635     * @return bool True on success, false on failure 
     1636     */ 
     1637    public function setUsernamesCaseSensitive($value) 
     1638    { 
     1639        // Init values 
     1640        $retval = true; 
     1641 
     1642        if ($value != $this->getUsernamesCaseSensitive()) { 
     1643            $db = AbstractDb::getObject(); 
     1644            // Verify if usernames differing by case exists 
     1645            if (!$value) { 
     1646                $sql = "Select username, email from users where  
     1647                    lower(username) in (Select lower(username) as uname from users where account_origin = '{$this->getId()}' group by lower(username) having count(user_id) > 1) 
     1648                    or lower(email) in (Select lower(email) from users where account_origin = '{$this->getId()}' group by lower(email) having count(user_id) > 1) order by username"; 
     1649                if (!$db->execSql($sql, $duplicates))  
     1650                    $retval = false; 
     1651                if (!empty($duplicates)) { 
     1652                    $duplicatenames = array(); 
     1653                    foreach($duplicates as $duplicate) $duplicatenames[] = "{$duplicate['username']} ({$duplicate['email']})"; 
     1654                    $this->errorMsg = _("You cannot change the case sensitivity of this network because some users would have duplicate names or emails.  Some action must be performed before.<br/>Here is a list of duplicate usernames: " . implode(', ', $duplicatenames)); 
     1655                    $retval = false; 
     1656                } 
     1657            } 
     1658            if ($retval) { 
     1659                $value ? $value = 'TRUE' : $value = 'FALSE'; 
     1660                $retval = $db->execSqlUpdate("UPDATE networks SET usernames_case_sensitive = {$value} WHERE network_id = '{$this->getId()}'", false); 
     1661                $this->refresh(); 
     1662            } 
     1663        } 
     1664 
     1665        return $retval; 
     1666    } 
    16201667 
    16211668 
     
    16311678        // Init values 
    16321679        $html = ''; 
     1680         
     1681        /* 
     1682         * Verify if an error message was registered before outputting the form 
     1683         */ 
     1684        if (isset($this->errorMsg)) { 
     1685             $html .= "<div class='errormsg'>" . $this->errorMsg . "</div>"; 
     1686        } 
    16331687 
    16341688        /* 
     
    17111765        $data = ThemePack::getSelectUI("network_" . $this->getId() . "_theme_pack", $this->getThemePack()); 
    17121766        $html_network_properties[] = InterfaceElements::generateAdminSectionContainer("network_theme_pack", $title, $data); 
    1713  
     1767       
    17141768        // Build section 
    17151769        $html .= InterfaceElements::generateAdminSectionContainer("network_properties", _("Network properties"), implode(null, $html_network_properties)); 
     
    17361790        $help = _("Are nodes allowed to redirect users to the web page they originally requested instead of the portal?"); 
    17371791        $data = InterfaceElements::generateInputCheckbox("network_" . $this->getId() . "_allow_original_URL_redirect", "", _("Yes"), $this->getPortalOriginalUrlAllowed(), "network_allow_original_URL_redirect_radio"); 
    1738         $html_network_node_properties[] = InterfaceElements::generateAdminSectionContainer("network_allow_original_URL_redirect", $title, $data, $help); 
     1792        $html_network_node_properties[] = InterfaceElements::generateAdminSectionContainer("network_allow_original_URL_redirect", $title, $data, $help);    
    17391793 
    17401794        // Build section 
     
    17621816        $data = InterfaceElements::generateInputCheckbox("network_" . $this->getId() . "_allow_multiple_login", "", _("Yes"), $this->getMultipleLoginAllowed(), "network_allow_multiple_login_radio"); 
    17631817        $html_network_user_verification[] = InterfaceElements::generateAdminSectionContainer("network_allow_multiple_login", $title, $data, $help); 
     1818         
     1819           
     1820        //  network_authenticator_params 
     1821        $title = _("Case sensitivity"); 
     1822        $help = _("Are usernames case sensitive?"); 
     1823        $data = InterfaceElements::generateInputCheckbox("network_" . $this->getId() . "_usernames_case_sensitive","", _("Yes"), $this->getUsernamesCaseSensitive(), "network_usernames_case_sensitive"); 
     1824        $html_network_user_verification[] = InterfaceElements::generateAdminSectionContainer("network_usernames_case_sensitive", $title, $data, $help); 
    17641825 
    17651826        // Build section 
     
    19241985        $name = "network_".$this->getId()."_validation_email_from_address"; 
    19251986        $this->setValidationEmailFromAddress($_REQUEST[$name]); 
     1987         
     1988        $name = "network_" . $this->getId() . "_usernames_case_sensitive"; 
     1989        $this->setUsernamesCaseSensitive(empty ($_REQUEST[$name]) ? false : true); 
    19261990 
    19271991        //  theme_pack 
  • trunk/wifidog-auth/wifidog/classes/NodeList.php

    r1391 r1428  
    208208 
    209209        $items[] = array('path' => 'node_lists/map', 
    210         'title' => _("Deployed HotSpots map"), 
    211         'url' => BASE_URL_PATH."hotspots_map.php" 
    212                 ); 
     210            'title' => _("Deployed HotSpots map"), 
     211            'url' => BASE_URL_PATH."hotspots_map.php" 
     212       ); 
    213213 
    214214        $listTypes=self::getAvailableNodeListTypes(); 
    215215        //pretty_print_r($listTypes); 
    216216        foreach ($listTypes as $type) { 
    217                     $nodeListClass = "NodeList" . $type; 
    218                     require_once("classes/NodeLists/NodeList{$type}.php"); 
     217            $nodeListClass = "NodeList" . $type; 
     218            require_once("classes/NodeLists/NodeList{$type}.php"); 
    219219            if(call_user_func(array($nodeListClass, 'isAvailable'))) { 
    220             $items[] = array('path' => 'node_lists/'.$type, 
    221             'title' => sprintf(_("List in %s format"), $type), 
    222             'url' => BASE_URL_PATH."hotspot_status.php?format=$type" 
    223             ); 
     220                $items[] = array('path' => 'node_lists/'.$type, 
     221                    'title' => sprintf(_("List in %s format"), $type), 
     222                    'url' => BASE_URL_PATH."hotspot_status.php?format=$type" 
     223                ); 
    224224            } 
    225225        } 
    226226        $items[] = array('path' => 'node_lists/technical_status', 
    227         'title' => _("Full node technical status (includes non-deployed nodes)"), 
    228         'url' => BASE_URL_PATH."node_list.php" 
    229                 ); 
     227            'title' => _("Full node technical status (includes non-deployed nodes)"), 
     228            'url' => BASE_URL_PATH."node_list.php" 
     229        ); 
    230230        $items[] = array('path' => 'node_lists', 
    231         'title' => _('Find Hotspots'), 
    232         'type' => MENU_ITEM_GROUPING); 
    233  
    234  
    235  
     231            'title' => _('Find Hotspots'), 
     232            'type' => MENU_ITEM_GROUPING); 
    236233 
    237234        return $items; 
  • trunk/wifidog-auth/wifidog/classes/User.php

    r1421 r1428  
    160160 
    161161        $username_str = $db->escapeString($username); 
     162        $comparison = ($account_origin->getUsernamesCaseSensitive()? '=': 'ILike'); 
    162163        $account_origin_str = $db->escapeString($account_origin->getId()); 
    163         $db->execSqlUniqueRes("SELECT user_id FROM users WHERE username = '$username_str' AND account_origin = '$account_origin_str'", $user_info, false); 
     164        $db->execSqlUniqueRes("SELECT user_id FROM users WHERE username {$comparison} '$username_str' AND account_origin = '$account_origin_str'", $user_info, false); 
    164165 
    165166        if ($user_info != null) { 
     
    182183 
    183184        $usernameOrEmail_str = $db->escapeString($usernameOrEmail); 
    184         $db->execSqlUniqueRes("SELECT user_id FROM users WHERE username ILike '$usernameOrEmail_str' OR email ILike '$usernameOrEmail_str'", $user_info, false); 
     185        $db->execSqlUniqueRes("SELECT user_id FROM users WHERE username = '$usernameOrEmail_str' OR email ILike '$usernameOrEmail_str'", $user_info, false); 
    185186 
    186187        if ($user_info != null) { 
     
    221222        $email_str = $db->escapeString($email); 
    222223        $account_origin_str = $db->escapeString($account_origin->getId()); 
    223         $db->execSqlUniqueRes("SELECT user_id FROM users WHERE email = '$email_str' AND account_origin = '$account_origin_str'", $user_info, false); 
     224        $db->execSqlUniqueRes("SELECT user_id FROM users WHERE email ILike '$email_str' AND account_origin = '$account_origin_str'", $user_info, false); 
    224225 
    225226        if ($user_info != null) 
     
    378379        if ($value != $this->getUsername()) { 
    379380            $db = AbstractDb::getObject(); 
     381            $otherUser = User::getUserByUsernameAndOrigin($value, $this->getNetwork()); 
     382            if (!is_null($otherUser)) { 
     383                throw new exception(sprintf(_("Sorry, the username %s is not available"), $value)); 
     384            } 
    380385            $value = $db->escapeString($value); 
    381386            $retval = @ $db->execSqlUpdate("UPDATE users SET username = '{$value}' WHERE user_id='{$this->id}'", false); 
    382             if (!$retval) { 
    383                 throw new exception(sprintf(_("Sorry, the username %s is not available"), $value)); 
    384             } 
    385387            $this->refresh(); 
    386388        } 
  • trunk/wifidog-auth/wifidog/include/common.php

    r1421 r1428  
    347347 
    348348            return $string; 
    349     } 
    350 } 
    351 $myLogfile = !defined('WIFIDOG_LOGFILE') ? "tmp/wifidog.log" : constant('WIFIDOG_LOGFILE'); 
    352 if (!empty ($myLogfile)) { 
    353     if (substr($myLogfile, 0, 1) != '/') 
    354     $myLogfile = WIFIDOG_ABS_FILE_PATH . $myLogfile; 
    355  
    356     EventLogging :: stAddChannel(new FileChannel($myLogfile, new WifidogSyslogFormatter(), 'warning,notice'), 'logfile'); 
    357 } 
     349        } 
     350    } 
     351    $myLogfile = !defined('WIFIDOG_LOGFILE') ? "tmp/wifidog.log" : constant('WIFIDOG_LOGFILE'); 
     352    if (!empty ($myLogfile)) { 
     353        if (substr($myLogfile, 0, 1) != '/') 
     354            $myLogfile = WIFIDOG_ABS_FILE_PATH . $myLogfile; 
     355 
     356        EventLogging :: stAddChannel(new FileChannel($myLogfile, new WifidogSyslogFormatter(), 'warning,notice'), 'logfile'); 
     357    } 
    358358 
    359359// trigger_error("here i am", E_USER_NOTICE); 
  • trunk/wifidog-auth/wifidog/include/schema_validate.php

    r1421 r1428  
    4848 * Define current database schema version 
    4949 */ 
    50 define('REQUIRED_SCHEMA_VERSION', 66); 
     50define('REQUIRED_SCHEMA_VERSION', 67); 
    5151/** Used to test a new shecma version before modyfying the database */ 
    5252define('SCHEMA_UPDATE_TEST_MODE', false); 
     
    14491449    } 
    14501450     
     1451    $new_schema_version = 67; 
     1452    if ($schema_version < $new_schema_version && $new_schema_version <= $targetSchema) { 
     1453        printUpdateVersion($new_schema_version); 
     1454        $sql .= "\n\nUPDATE schema_info SET value='$new_schema_version' WHERE tag='schema_version';\n"; 
     1455        $sql .= "\n\nALTER TABLE networks ADD COLUMN usernames_case_sensitive boolean NOT NULL DEFAULT true;\n"; 
     1456    } 
     1457     
    14511458    /* 
    14521459     $new_schema_version = ; 
  • trunk/wifidog-auth/wifidog/js/formutils.js

    r1424 r1428  
    4545  var str = elem.value; 
    4646  //var re = /^[\w-+]+(\.[\w+-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/; 
    47   var re = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/; 
     47  var re = /^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/; 
    4848  if (!str.match(re)) { 
    4949        focusElement(elem.form.name, elem.name);