예제 #1
0
 public function authenticate($username, $password)
 {
     $user = $this->getUser($username);
     $log = new Log();
     $log->setDateTime(date("Y-m-d H:i:s"));
     if (isset($_SERVER["HTTP_HOST"])) {
         $log->setClientAddress($_SERVER["HTTP_HOST"]);
     }
     if (isset($_SERVER["REMOTE_ADDR"])) {
         $log->setClientIp($_SERVER["REMOTE_ADDR"]);
     }
     if (isset($_SERVER["HTTP_USER_AGENT"])) {
         if (ini_get("browscap")) {
             $browser = get_browser(null, true);
         } else {
             $browser = self::getBrowser();
         }
         $log->setClientAgent($browser["browser"] . " (v" . $browser["version"] . ")");
         $log->setClientPlatform($browser["platform"]);
     }
     if (!is_object($user)) {
         $log->setType("LOGIN_FAILED");
         $log->setLogText("A login try of an unregistered user, user given: {$username}");
         $log->save();
         throw new \Exception(i18n::translate("Invalid User, the user \"%s\" is not registered!", $username));
     }
     if ($user->getStatus() !== "ACTIVE") {
         $log->setLogText("A login try of an inactive user, user given: {$username}");
         $log->save();
         throw new \Exception(i18n::translate("The user \"%s\" is not active.", $username));
     }
     if (!$user->authenticate($password)) {
         $log->setLogText("A login try of an user with invalid password, user given: {$username}");
         $log->save();
         throw new \Exception(i18n::translate("Authentication failed."));
     }
     $log->setType("LOGIN_SUCCESS");
     if (session_status() === PHP_SESSION_ACTIVE) {
         $log->setSessionId(session_id());
     }
     $log->setUsername($username);
     $log->setUserId($user->getId());
     $log->save();
     return $user;
 }
예제 #2
0
 /**
  * Exclude object from result
  *
  * @param   ChildLog $log Object to remove from the list of results
  *
  * @return $this|ChildLogQuery The current query, for fluid interface
  */
 public function prune($log = null)
 {
     if ($log) {
         $this->addUsingAlias(LogTableMap::COL_ID, $log->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }