Changeset 1442

Show
Ignore:
Timestamp:
04/16/06 21:10:16 (3 years ago)
Author:
mbonetti
Message:

Proper mobile login

Location:
trunk/rss
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/rss/cls/user.php

    r1439 r1442  
    4242    /** List of valid IP subnets this user is allowed to log in via a cookie */ 
    4343    var $_validIPs; 
     44    /** Mobile session */ 
     45    var $_mobileSession; 
    4446 
    4547    /** 
     
    5153     */ 
    5254    function RSSUser() { 
     55     
     56            // We need sessions for the mobile version 
     57            ini_set('session.use_trans_sid',true); 
     58            session_start(); 
     59     
    5360        $this -> _uid = 0; 
    5461        $this -> _validIPs = array(); 
     
    5764        $this -> _realName = ''; 
    5865        $this -> _hash = null; 
    59  
     66                $this -> _mobileSession = (isset($_POST['media']) && 'mobile' == $_POST['media']); 
     67                 
    6068        if (array_key_exists('logout',$_GET)) { 
    6169            $this -> logout(); 
    6270            rss_redirect(''); 
    6371        } 
    64  
     72                 
    6573        $cuname = $chash = null; 
    6674        if (isset($_POST['username']) && isset($_POST['password'])) { 
    6775            $_cuname = trim($_POST['username']); 
    68             $_chash = md5($_POST['password']); 
     76            if ($this -> _mobileSession) { 
     77                $_chash = md5(md5($_POST['password'] . $_POST['username'])); 
     78            } else { 
     79                $_chash = md5($_POST['password']); 
     80            } 
    6981            if ($this -> login($_cuname,$_chash)) { 
    7082                $cuname = $_cuname; 
     
    7789        elseif(isset($_SESSION['mobile'])) { 
    7890            list($cuname,$chash) = explode('|',$_SESSION['mobile']); 
     91            $this -> _mobileSession = true; 
    7992        } 
    8093        if ($cuname && $chash) { 
     
    124137                   ." where uname = '$uname' "; 
    125138            rss_query($sql); 
    126             $this -> setUserCookie($uname,$pass); 
     139            if ($this -> _mobileSession) { 
     140                $this -> setUserSession($uname,$pass); 
     141            } else { 
     142                $this -> setUserCookie($uname,$pass); 
     143            } 
    127144            rss_invalidate_cache(); 
    128145            return true; 
     
    136153     */ 
    137154    function setUserCookie($user,$hash) { 
    138         // if (getConfig('rss.config.autologout')) { 
    139         //     $t = 0; 
    140         // } else { 
    141         $t =time()+COOKIE_LIFESPAN; 
    142         // } 
     155            $rs = rss_query( 
     156                'select value_ from ' .getTable('config') . "where key_ = 'rss.config.autologout'", false,true); 
     157                if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR) && rss_num_rows($rs) > 0) { 
     158                    list($als) = rss_fetch_row($rs); 
     159                    $al = ($als == 'true'); 
     160                } else { 
     161                    $al = false; 
     162                } 
     163        $t = $al ? 0: time()+COOKIE_LIFESPAN; 
    143164        setcookie(RSS_USER_COOKIE, $user .'|' . $hash , $t, getPath()); 
    144165    } 
    145166 
     167        function setUserSession($user,$hash) { 
     168            $_SESSION['mobile'] = $user . "|" . $hash; 
     169        } 
     170         
    146171    /** 
    147172     * Logs the user out. 
     
    151176     */ 
    152177    function logout() { 
    153         if (array_key_exists(RSS_USER_COOKIE, $_COOKIE)) { 
     178        if (array_key_exists(RSS_USER_COOKIE, $_COOKIE) || isset($_SESSION['mobile'])) { 
    154179            $subnet = preg_replace('#^([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$#','\1',$_SERVER['REMOTE_ADDR']); 
    155180 
     
    169194            unset($_COOKIE[RSS_USER_COOKIE]); 
    170195            setcookie(RSS_USER_COOKIE, "", -1, getPath()); 
     196            if (isset($_SESSION['mobile'])) { 
     197                unset($_SESSION['mobile']); 
     198            } 
     199 
    171200            rss_invalidate_cache(); 
    172201        } 
  • trunk/rss/themes/default/mobile/plugins.php

    r1434 r1442  
    33// stores constants for overrides' defaults 
    44require_once('mobileconstants.php'); 
    5  
    6 // Mobile theme relys on PHP sessions 
    7 ini_set('session.use_trans_sid',true); 
    8 session_start(); 
    9  
    10 //var_dump($_SESSION['mobile']); 
    115 
    126function __mobile_strip_images($i) {