Esempio n. 1
0
 public function login($username, $password)
 {
     if ($user = User::authenticate($username, $password)) {
         // user just logged in, update login time.
         $user->lastLogin(time());
         $_SESSION['username'] = $user->username;
         $_SESSION['user_id'] = intval($user->user_id);
         $online = Friend::of($user->user_id);
         return array('r' => 'logged in', 's' => session_id(), 'f' => $online);
     } else {
         return array('r' => 'error', 'e' => 'invalid user');
     }
 }
Esempio n. 2
0
 public function login($username, $password)
 {
     if ($user = User::authenticate($username, $password)) {
         // user just logged in, update login time.
         $user->lastLogin(time());
         $session_id = md5(microtime(true) . $user->username);
         $session = array('username' => $user->username, 'user_id' => intval($user->user_id), 'session_id' => $session_id, 'friends' => Friend::of($user->user_id, true));
         $cookie = json_encode(array('user' => $user->username, 'sid' => $session_id));
         setcookie(COOKIE_NAME, $cookie, time() + 60 * 60 * 24 * COOKIE_PERIOD, '/', COOKIE_DOMAIN);
         $this->memcache->add($user->username, json_encode($session));
         return array('r' => 'logged in', 's' => $session_id, 'f' => $session['friends']);
     } else {
         return array('r' => 'error', 'e' => 'invalid user');
     }
 }
Esempio n. 3
0
 public function login($username, $password)
 {
     if (!empty($_COOKIE[COOKIE_NAME]) && !empty($_SESSION['username']) && !empty($_SESSION['user_id']) && $_SESSION['username'] == $username) {
         return array('r' => 'resume');
     } elseif ($user = User::authenticate($username, $password)) {
         // user just logged in, update login time.
         ### we do this now in User::authenticate, and also update the ip address
         ### $user->lastLogin(time());
         ### this is problematic !!!
         ### the hosting application might use these session vars !!!
         ### either use unique variable names, e.g. imjs_username or
         ### move this to MySQL.php, so we set these session vars only in the stand-alone
         ### chat and define a separate function to test if a user is online. The stand-alone chat
         ### would then test these session vars and the application-specific classes will
         ### use application-specific functions to check if a user is online.
         ### Time will tell the wiser after trying it with osDate and joomla.
         ### A big question is: as the hosting app is performing a login, should ajax-im
         ### perform a second login, just to set up the data structures? We could handle this
         ### all with the resume method in the js module.
         $_SESSION['username'] = $user->username;
         $_SESSION['user_id'] = $user->user_id;
         $session_id = md5(microtime(true) . $user->username);
         $friends = Friend::of($user->user_id);
         //replaced with $session, to prepare memcache usage
         $cookie = json_encode(array('user' => $user->username, 'sid' => $session_id));
         setcookie(COOKIE_NAME, $cookie, time() + 60 * 60 * 24 * COOKIE_PERIOD, '/', COOKIE_DOMAIN);
         /* memcache variant (NOT ALL SERVERS MIGHT SUPPORT MEMCACHE)
            ### not sure if we need to store the friends. friends are updated dynamically with messages or
            ### restored when the page is loaded. well, maybe we won't need to read the DB on a reload.
            $session = array(
                'username' => $user->username,
                'user_id' => intval($user->user_id),
                'session_id' => $session_id,
                'friends' => Friend::of($user->user_id, true)
            );
            $this->memcache->add($user->username, json_encode($session));
            */
         ### we could do this in User::authenticate()
         $status = Status::of($user->user_id);
         return array('r' => 'logged in', 's' => session_id(), 'u' => $user->username, 's' => $status->status_id, 'f' => $friends, 'x' => COOKIE_NAME . ',' . $cookie . ',' . COOKIE_PERIOD . ',' . COOKIE_DOMAIN);
     } else {
         return array('r' => 'error', 'e' => 'invalid user');
     }
 }