Changeset 368 for devel/lib

Show
Ignore:
Timestamp:
05/27/06 14:21:20 (2 years ago)
Author:
ben
Message:

Persistent logins are reinstated; login functions are slightly rejigged to allow for several different login methods

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/lib/elgglib.php

    r367 r368  
    33443344} 
    33453345 
     3346// Fills user information 
     3347function init_user_var($user) { 
     3348     
     3349    global $CFG; 
     3350     
     3351    $user->loggedin = true; 
     3352    $user->site     = $CFG->wwwroot; // for added security, store the site in the session 
     3353    $user->sesskey  = random_string(10); 
     3354    $user->sessionIP = md5(getremoteaddr());   // Store the current IP in the session 
     3355    // backwards compatibility (TODO this will have to go eventually) 
     3356    fill_legacy_user_session($user); 
     3357    return $user; 
     3358     
     3359} 
     3360 
    33463361 
    33473362// Authentication Function 
     
    33753390     
    33763391    // Set Persistent Cookie 
    3377     $rememberme = optional_param('remember',0,PARAM_INT); 
     3392    $rememberme = optional_param('remember',0); 
    33783393    if (!empty($rememberme)) { 
    33793394        remember_login($user->ident); 
    33803395    } 
    33813396     
    3382     $user->loggedin = true; 
    3383     $user->site     = $CFG->wwwroot; // for added security, store the site in the session 
    3384     $user->sesskey  = random_string(10); 
    3385     $user->sessionIP = md5(getremoteaddr());   // Store the current IP in the session 
    3386     // backwards compatibility (TODO this will have to go eventually) 
    3387     fill_legacy_user_session($user); 
    3388     $USER = $user; 
     3397     
     3398    $USER = init_user_var($user); 
    33893399    return $ok; 
    33903400} 
    33913401 
    3392 /** 
    3393  * elgg doesn't have a 'login' page yet, but it will so this can stay here for now 
    3394  */ 
    3395 function require_login() { 
    3396     global $USER, $SESSION,$FULLME; 
    3397     // Check to see if there's a persistent cookie 
     3402// Attempts to get login from a cookie 
     3403function cookied_login() { 
     3404    global $USER; 
    33983405    if($ticket = md5($_COOKIE[AUTH_COOKIE])) { 
    33993406        if ($user = get_record('users','code',$ticket)) { 
     
    34013408             
    34023409            /*** TODO: Create Proper Abstraction Interface - don't use file binding -- ugh ***/ 
    3403             if (!run("users:flags:get", array("banned",$row->ident))) { 
    3404                 $USER = $user
     3410            if (!run("users:flags:get", array("banned",$user->ident))) { 
     3411                $USER = init_user_var($user)
    34053412                return true; 
    34063413            } else { 
    34073414                global $messages; 
    34083415                $messages[] = gettext("You have been banned from the system!"); 
     3416                return false; 
    34093417            } 
    34103418        } 
    34113419    } 
     3420} 
     3421 
     3422/** 
     3423 * elgg doesn't have a 'login' page yet, but it will so this can stay here for now 
     3424 */ 
     3425function require_login() { 
     3426    global $USER, $SESSION,$FULLME; 
     3427     
     3428    // Check to see if there's a persistent cookie 
     3429    cookied_login(); 
    34123430     
    34133431    // First check that the user is logged in to the site. 
     
    34503468     
    34513469    setcookie(AUTH_COOKIE, $ticket, time()+AUTH_COOKIE_LENGTH, '/'); 
     3470    global $messages; 
     3471    $messages[] = gettext("The system will remember you and automatically log you in next time."); 
    34523472     
    34533473    return 1; 
    34543474} 
    34553475 
     3476// Returns whether the user is logged in or not; 
     3477// if not logged in, checks for persistent cookie 
    34563478function isloggedin() {  
    34573479    global $USER; 
     3480    if (empty($USER->ident) && empty($USER->loggedin)) { 
     3481        cookied_login(); 
     3482    } 
    34583483    return (!empty($USER->ident) && !empty($USER->loggedin)); 
    34593484}