コード例 #1
0
ファイル: Users.dao.php プロジェクト: kukogit/omegaup
 public static function FindByUsername($username)
 {
     $vo_Query = new Users(array("username" => $username));
     $a_Results = UsersDAO::search($vo_Query);
     if (sizeof($a_Results) != 1) {
         return NULL;
     }
     return array_pop($a_Results);
 }
コード例 #2
0
 /**
  *
  */
 public function testViewProblemInAContestDetailsValid()
 {
     // Get a contest
     $contestData = ContestsFactory::createContest();
     // Get a user to be the author
     $author = UserFactory::createUser();
     // Get a problem
     $problemData = ProblemsFactory::createProblem(null, null, 1, $author);
     // Add the problem to the contest
     ContestsFactory::addProblemToContest($problemData, $contestData);
     // Get a user for our scenario
     $contestant = UserFactory::createUser();
     // Prepare our request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     $r["problem_alias"] = $problemData["request"]["alias"];
     // Log in the user
     $r["auth_token"] = $this->login($contestant);
     // Explicitly join contest
     ContestController::apiOpen($r);
     // Call api
     $response = ProblemController::apiDetails($r);
     // Get problem and contest from DB to check it
     $problemDAO = ProblemsDAO::getByAlias($problemData["request"]["alias"]);
     $contestDAO = ContestsDAO::getByAlias($contestData["request"]["alias"]);
     $contestantsDAO = UsersDAO::search(new Users(array("username" => $contestant->getUsername())));
     $contestantDAO = $contestantsDAO[0];
     // Assert data
     $this->assertEquals($response["title"], $problemDAO->getTitle());
     $this->assertEquals($response["alias"], $problemDAO->getAlias());
     $this->assertEquals($response["validator"], $problemDAO->getValidator());
     $this->assertEquals($response["time_limit"], $problemDAO->getTimeLimit());
     $this->assertEquals($response["memory_limit"], $problemDAO->getMemoryLimit());
     $this->assertEquals($response["problemsetter"]['username'], $author->username);
     $this->assertEquals($response["problemsetter"]['name'], $author->name);
     $this->assertEquals($response["source"], $problemDAO->getSource());
     $this->assertContains("<h1>Entrada</h1>", $response["problem_statement"]);
     $this->assertEquals($response["order"], $problemDAO->getOrder());
     $this->assertEquals($response["score"], 0);
     // Default data
     $this->assertEquals(0, $problemDAO->getVisits());
     $this->assertEquals(0, $problemDAO->getSubmissions());
     $this->assertEquals(0, $problemDAO->getAccepted());
     $this->assertEquals(0, $problemDAO->getDifficulty());
     // Verify that we have an empty array of runs
     $this->assertEquals(0, count($response["runs"]));
     // Verify that problem was marked as Opened
     $problem_opened = ContestProblemOpenedDAO::getByPK($contestDAO->getContestId(), $problemDAO->getProblemId(), $contestantDAO->getUserId());
     $this->assertNotNull($problem_opened);
     // Verify open time
     $this->assertEquals(Utils::GetPhpUnixTimestamp(), Utils::GetPhpUnixTimestamp($problem_opened->getOpenTime()));
 }
コード例 #3
0
 /**
  * Verifies the user given its verification id
  *
  * @param Request $r
  * @return type
  * @throws ApiException
  * @throws InvalidDatabaseOperationException
  * @throws NotFoundException
  */
 public static function apiVerifyEmail(Request $r)
 {
     $user = null;
     // Admin can override verification by sending username
     if (isset($r['usernameOrEmail'])) {
         self::authenticateRequest($r);
         if (!Authorization::IsSystemAdmin($r['current_user_id'])) {
             throw new ForbiddenAccessException();
         }
         self::$log->info('Admin verifiying user...' . $r['usernameOrEmail']);
         Validators::isStringNonEmpty($r['usernameOrEmail'], 'usernameOrEmail');
         $user = self::resolveUser($r['usernameOrEmail']);
         self::$redirectOnVerify = false;
     } else {
         // Normal user verification path
         Validators::isStringNonEmpty($r['id'], 'id');
         try {
             $users = UsersDAO::search(new Users(array('verification_id' => $r['id'])));
             $user = is_array($users) && count($users) > 0 ? $users[0] : null;
         } catch (Exception $e) {
             throw new InvalidDatabaseOperationException($e);
         }
     }
     if (is_null($user)) {
         throw new NotFoundException('verificationIdInvalid');
     }
     try {
         $user->setVerified(1);
         UsersDAO::save($user);
     } catch (Exception $e) {
         throw new InvalidDatabaseOperationException($e);
     }
     self::$log->info('User verification complete.');
     self::registerToSendy($user);
     if (self::$redirectOnVerify) {
         die(header('Location: /login/'));
     }
     return array('status' => 'ok');
 }