Ejemplo n.º 1
0
 public function loginAction(Request $request, Player $me)
 {
     if ($me->isValid()) {
         throw new ForbiddenException("You are already logged in!");
     }
     $query = $request->query;
     $session = $request->getSession();
     $token = $query->get("token");
     $username = $query->get("username");
     if (!$token || !$username) {
         throw new BadRequestException();
     }
     // Don't check whether IPs match if we're on a development environment
     $checkIP = !$this->isDebug();
     $info = validate_token($token, $username, array(), $checkIP);
     if (!isset($info)) {
         throw new ForbiddenException("There was an error processing your login. Please go back and try again.");
     }
     $session->set("username", $info['username']);
     $session->set("groups", $info['groups']);
     $redirectToProfile = false;
     if (!Player::playerBZIDExists($info['bzid'])) {
         // If they're new, redirect to their profile page so they can add some info
         $player = Player::newPlayer($info['bzid'], $info['username']);
         $redirectToProfile = true;
     } else {
         $player = Player::getFromBZID($info['bzid']);
         if ($player->isDeleted()) {
             $player->setStatus('active');
         }
     }
     $session->set("playerId", $player->getId());
     $player->updateLastLogin();
     $player->setUsername($info['username']);
     Visit::enterVisit($player->getId(), $request->getClientIp(), gethostbyaddr($request->getClientIp()), $request->server->get('HTTP_USER_AGENT'), $request->server->get('HTTP_REFERER'));
     $this->configPromoteAdmin($player);
     if ($redirectToProfile) {
         $profile = Service::getGenerator()->generate('profile_show');
         return new RedirectResponse($profile);
     } else {
         return $this->goBack();
     }
 }
Ejemplo n.º 2
0
 /**
  * Only include matches where a specific team/player played
  *
  * @param  Team|Player $participant The team/player which played the matches
  * @param  string      $result      The outcome of the matches (win, draw or loss)
  * @return self
  */
 public function with($participant, $result = null)
 {
     if (!$participant || !$participant->isValid()) {
         return $this;
     }
     if ($participant instanceof Team) {
         $team_a_query = "team_a = ?";
         $team_b_query = "team_b = ?";
     } elseif ($participant instanceof Player) {
         $team_a_query = "FIND_IN_SET(?, team_a_players)";
         $team_b_query = "FIND_IN_SET(?, team_b_players)";
     } else {
         throw new InvalidArgumentException("Invalid model provided");
     }
     switch ($result) {
         case "wins":
         case "win":
         case "victory":
         case "victories":
             $query = "({$team_a_query} AND team_a_points > team_b_points) OR ({$team_b_query} AND team_b_points > team_a_points)";
             break;
         case "loss":
         case "lose":
         case "losses":
         case "defeat":
         case "defeats":
             $query = "({$team_a_query} AND team_b_points > team_a_points) OR ({$team_b_query} AND team_a_points > team_b_points)";
             break;
         case "draw":
         case "draws":
         case "tie":
         case "ties":
             $query = "({$team_a_query} OR {$team_b_query}) AND team_a_points = team_b_points";
             break;
         default:
             $query = "{$team_a_query} OR {$team_b_query}";
     }
     $this->conditions[] = $query;
     $this->parameters[] = $participant->getId();
     $this->parameters[] = $participant->getId();
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Assert that the user is logged in
  * @throws HTTPException
  * @param  string        $message The message to show if the user is not logged in
  * @return void
  */
 protected function requireLogin($message = "You need to be signed in to do this")
 {
     $me = new Player($this->getRequest()->getSession()->get('playerId'));
     if (!$me->isValid()) {
         throw new ForbiddenException($message);
     }
 }
Ejemplo n.º 4
0
 /**
  * Add a new news article
  *
  * @param string $subject    The subject of the article
  * @param string $content    The content of the article
  * @param int    $authorID   The ID of the author
  * @param int    $categoryId The ID of the category this article will be published under
  * @param string $status     The status of the article: 'published', 'disabled', or 'deleted'
  *
  * @internal param int $categoryID The ID of the category
  * @return News|bool An object representing the article that was just created or false if the article was not created
  */
 public static function addNews($subject, $content, $authorID, $categoryId = 1, $status = 'published')
 {
     $author = new Player($authorID);
     // Only allow real players to post news articles and if the player posting has permissions to create new posts
     if ($author->isValid() && $author->hasPermission(Permission::PUBLISH_NEWS)) {
         return self::create(array('category' => $categoryId, 'subject' => $subject, 'content' => $content, 'author' => $authorID, 'editor' => $authorID, 'status' => $status), 'issiis', array('created', 'updated'));
     }
     return false;
 }