Ejemplo n.º 1
0
 /**
  * Creates a new session for a given user.
  *
  * @param int  $userId       User's ID
  * @param bool $isPersistent Whether the session is persistent or not
  *
  * @return Session
  *
  * @throws Exception
  */
 public static function createSession($userId, $isPersistent = false)
 {
     self::validateIsPersistent($isPersistent);
     $creationDate = time();
     if ($isPersistent) {
         $expiryDate = strtotime(\PHPAuth\Configuration::SESSION_PERSISTENT_TIME);
     } else {
         $expiryDate = strtotime(\PHPAuth\Configuration::SESSION_NON_PERSISTENT_TIME);
     }
     $ipAddress = $_SERVER['REMOTE_ADDR'];
     $userAgent = $_SERVER['HTTP_USER_AGENT'];
     $uuid = \PHPAuth\Util::generateUuid();
     return new self($uuid, $userId, $userAgent, $ipAddress, $creationDate, $expiryDate, NULL, $isPersistent);
 }
Ejemplo n.º 2
0
 /**
  * Creates a new log entry
  *
  * @param   int     $userId     User's ID
  * @param   string  $action     Action that was logged
  * @param   string  $comment    Extra information
  * @param   string  $ipAddress  IP address associated with action
  *
  * @return  Log
  *
  * @throws  Exception
  */
 public static function createLog($userId, $action, $comment, $ipAddress)
 {
     self::validateAction($action);
     $comment = \PHPAuth\Util::sanitizeString($comment);
     self::validateComment($comment);
     return new self(null, $userId, $action, $comment, $ipAddress, time());
 }