function __updateKeepMeLoggedInId() { global $loggedInUser, $__loginAppuserpersistentloginDAO, $KEEP_ME_LOGGED_IN_TIME, $MAX_KEEP_ME_LOGGED_IN; // Create a new unique identifier and expiration time for automatic login. // Check that the unique identifier we assigned is actually unique and // only exists on this user, to prevent account hijacking. // Set a cookie containing the identifier. for ($tries = 1; $tries <= 10; $tries++) { // Be sure there is at least one available slot in this user. // Delete the oldest slots, if necessary. $kmlis = $__loginAppuserpersistentloginDAO->findByUser_id($loggedInUser->id, '=', 'last_used'); if (count($kmlis) >= $MAX_KEEP_ME_LOGGED_IN) { $numToDel = count($kmlis) - ($MAX_KEEP_ME_LOGGED_IN - 1); for ($i = 0; $i < $numToDel; $i++) { $__loginAppuserpersistentloginDAO->delete($kmlis[$i]->id); } } // Add a persistent login row for this user, with a unique Id. $kmli = Appuserpersistentlogin::createDefault(); $kmli->user_id = $loggedInUser->id; $kmli->keep_me_logged_in_uniqid = uniqid('', true); try { @$__loginAppuserpersistentloginDAO->insert($kmli); } catch (Exception $ex) { } // Confirm that we were able to add the row successfully. $kmlis = $__loginAppuserpersistentloginDAO->findByKeep_me_logged_in_uniqid($kmli->keep_me_logged_in_uniqid); if (count($kmlis) == 1 && $kmlis[0]->user_id == $loggedInUser->id) { // Success. Set the cookie and stop trying new unique Ids. setcookie('kmliuid', $kmli->keep_me_logged_in_uniqid, time() + $KEEP_ME_LOGGED_IN_TIME, '/'); return true; } } return false; }
public static function createDefault() { $v = new Appuserpersistentlogin(); $v->defaultAllFields(); return $v; }
public function findWithPreparedStatement($ps) { $cacheKey = null; if ($this->cache !== null) { $cacheKey = serialize($ps); if (($rows = $this->cache->get($cacheKey)) !== false) { return $rows; } } $rows = array(); $rs = $this->connection->executeQuery($ps); while ($arr = $this->connection->fetchArray($rs)) { $row = new Appuserpersistentlogin(); $row->loadFromArray($arr); $rows[] = $row; } $this->connection->freeResult($rs); if ($this->cache !== null) { $this->cache->set($cacheKey, $rows); } return $rows; }