Esempio n. 1
0
 public static function addUser($contestData, $user)
 {
     // Prepare our request
     $r = new Request();
     $r['contest_alias'] = $contestData['request']['alias'];
     $r['usernameOrEmail'] = $user->getUsername();
     // Log in the contest director
     $r['auth_token'] = OmegaupTestCase::login($contestData['director']);
     // Call api
     ContestController::apiAddUser($r);
     unset($_REQUEST);
 }
Esempio n. 2
0
 public static function addUser($contestData, $user)
 {
     // Prepare our request
     $r = new Request();
     $r["contest_alias"] = $contestData["request"]["alias"];
     $r["usernameOrEmail"] = $user->getUsername();
     // Log in the contest director
     $r["auth_token"] = OmegaupTestCase::login($contestData["director"]);
     // Call api
     ContestController::apiAddUser($r);
     unset($_REQUEST);
 }
Esempio n. 3
0
 /**
  *
  * @param Request $r
  * @return array
  * @throws ForbiddenAccessException
  */
 public static function apiGenerateOmiUsers(Request $r)
 {
     self::authenticateRequest($r);
     $response = array();
     $is_system_admin = Authorization::IsSystemAdmin($r['current_user_id']);
     if ($r['contest_type'] == 'OMI') {
         if (!$is_system_admin) {
             throw new ForbiddenAccessException();
         }
         // Arreglo de estados de MX
         $keys = array('OMI2015-AGU' => 4, 'OMI2015-BCN' => 4, 'OMI2015-BCS' => 4, 'OMI2015-CAM' => 4, 'OMI2015-COA' => 4, 'OMI2015-COL' => 4, 'OMI2015-CHP' => 4, 'OMI2015-CHH' => 8, 'OMI2015-DIF' => 4, 'OMI2015-DUR' => 4, 'OMI2015-GUA' => 4, 'OMI2015-GRO' => 4, 'OMI2015-HID' => 4, 'OMI2015-JAL' => 4, 'OMI2015-MEX' => 4, 'OMI2015-MIC' => 4, 'OMI2015-MOR' => 4, 'OMI2015-NAY' => 4, 'OMI2015-NLE' => 4, 'OMI2015-OAX' => 4, 'OMI2015-PUE' => 4, 'OMI2015-QUE' => 4, 'OMI2015-ROO' => 4, 'OMI2015-SLP' => 4, 'OMI2015-SIN' => 4, 'OMI2015-SON' => 4, 'OMI2015-TAB' => 4, 'OMI2015-TAM' => 4, 'OMI2015-TLA' => 4, 'OMI2015-VER' => 4, 'OMI2015-YUC' => 4, 'OMI2015-ZAC' => 4, 'OMI2015-INV' => 4);
     } elseif ($r['contest_type'] == 'OMIPS') {
         if ($r['current_user']->getUsername() != 'andreasantillana' && !$is_system_admin) {
             throw new ForbiddenAccessException();
         }
         $keys = array('OMIPS2015-P' => 25, 'OMIPS2015-S' => 25);
     } elseif ($r['contest_type'] == 'ORIG') {
         if ($r['current_user']->getUsername() != 'kuko.coder' && !$is_system_admin) {
             throw new ForbiddenAccessException();
         }
         $keys = array('ORIG1516-CEL' => 38, 'ORIG1516-DHI' => 15, 'ORIG1516-GTO' => 14, 'ORIG1516-IRA' => 37, 'ORIG1516-PEN' => 22, 'ORIG1516-LEO' => 43, 'ORIG1516-SLP' => 14, 'ORIG1516-SLV' => 14, 'ORIG1516-URI' => 17, 'ORIG1516-VDS' => 15);
     } elseif ($r['contest_type'] == 'OMIAGS') {
         if ($r['current_user']->getUsername() != 'andreasantillana' && !$is_system_admin) {
             throw new ForbiddenAccessException();
         }
         $keys = array('OMIAGS' => 35);
     } elseif ($r['contest_type'] == 'OSI') {
         if ($r['current_user']->getUsername() != 'cope_quintana' && !$is_system_admin) {
             throw new ForbiddenAccessException();
         }
         $keys = array('OSI16' => 120);
     } elseif ($r['contest_type'] == 'UNAMFC') {
         if ($r['current_user']->getUsername() != 'manuelalcantara52' && $r['current_user']->getUsername() != 'manuel52' && !$is_system_admin) {
             throw new ForbiddenAccessException();
         }
         $keys = array('UNAMFC15' => 30);
     } elseif ($r['contest_type'] == 'OVI') {
         if ($r['current_user']->getUsername() != 'covi.academico' && !$is_system_admin) {
             throw new ForbiddenAccessException();
         }
         $keys = array('OVI15' => 200);
     } else {
         throw new InvalidParameterException('parameterNotInExpectedSet', 'contest_type', array('bad_elements' => $r['contest_type'], 'expected_set' => 'OMI, OMIAGS, ORIG, OSI, OVI'));
     }
     self::$permissionKey = $r['permission_key'] = self::randomString(32);
     foreach ($keys as $k => $n) {
         $digits = floor(log10($n) + 1);
         for ($i = 1; $i <= $n; $i++) {
             $username = $k . '-' . str_pad($i, $digits, '0', STR_PAD_LEFT);
             $password = self::randomString(8);
             if (self::omiPrepareUser($r, $username, $password)) {
                 $response[$username] = $password;
             }
             // Add user to contest if needed
             if (!is_null($r['contest_alias'])) {
                 $addUserRequest = new Request();
                 $addUserRequest['auth_token'] = $r['auth_token'];
                 $addUserRequest['usernameOrEmail'] = $username;
                 $addUserRequest['contest_alias'] = $r['contest_alias'];
                 ContestController::apiAddUser($addUserRequest);
             }
         }
     }
     return $response;
 }
Esempio n. 4
0
 /**
  *
  * @param Request $r
  * @return array
  * @throws ForbiddenAccessException
  */
 public static function apiGenerateOmiUsers(Request $r)
 {
     self::authenticateRequest($r);
     $response = array();
     if ($r["contest_type"] == "OMI") {
         if (!Authorization::IsSystemAdmin($r["current_user_id"])) {
             throw new ForbiddenAccessException();
         }
         // Arreglo de estados de MX
         $keys = array("OMI2015-AGU" => 4, "OMI2015-BCN" => 4, "OMI2015-BCS" => 4, "OMI2015-CAM" => 4, "OMI2015-COA" => 4, "OMI2015-COL" => 4, "OMI2015-CHP" => 4, "OMI2015-CHH" => 8, "OMI2015-DIF" => 4, "OMI2015-DUR" => 4, "OMI2015-GUA" => 4, "OMI2015-GRO" => 4, "OMI2015-HID" => 4, "OMI2015-JAL" => 4, "OMI2015-MEX" => 4, "OMI2015-MIC" => 4, "OMI2015-MOR" => 4, "OMI2015-NAY" => 4, "OMI2015-NLE" => 4, "OMI2015-OAX" => 4, "OMI2015-PUE" => 4, "OMI2015-QUE" => 4, "OMI2015-ROO" => 4, "OMI2015-SLP" => 4, "OMI2015-SIN" => 4, "OMI2015-SON" => 4, "OMI2015-TAB" => 4, "OMI2015-TAM" => 4, "OMI2015-TLA" => 4, "OMI2015-VER" => 4, "OMI2015-YUC" => 4, "OMI2015-ZAC" => 4, "OMI2015-INV" => 4);
     } else {
         if ($r["contest_type"] == "OMIPS") {
             if (!Authorization::IsSystemAdmin($r["current_user_id"])) {
                 throw new ForbiddenAccessException();
             }
             $keys = array("OMIPS2015-P" => 25, "OMIPS2015-S" => 25);
         } else {
             if ($r["contest_type"] == "ORIG") {
                 if (!($r["current_user"]->getUsername() == "kuko.coder" || Authorization::IsSystemAdmin($r["current_user_id"]))) {
                     throw new ForbiddenAccessException();
                 }
                 $keys = array("ORIG1516-CEL" => 38, "ORIG1516-DHI" => 15, "ORIG1516-GTO" => 14, "ORIG1516-IRA" => 37, "ORIG1516-PEN" => 22, "ORIG1516-LEO" => 43, "ORIG1516-SLP" => 14, "ORIG1516-SLV" => 14, "ORIG1516-URI" => 17, "ORIG1516-VDS" => 15);
             } else {
                 if ($r["contest_type"] == "OMIAGS") {
                     if (!($r["current_user"]->getUsername() == "andreasantillana" || Authorization::IsSystemAdmin($r["current_user_id"]))) {
                         throw new ForbiddenAccessException();
                     }
                     $keys = array("OMIAGS" => 35);
                 } else {
                     if ($r["contest_type"] == "OSI") {
                         if (!($r["current_user"]->getUsername() == "cope_quintana" || Authorization::IsSystemAdmin($r["current_user_id"]))) {
                             throw new ForbiddenAccessException();
                         }
                         $keys = array("OSI16" => 120);
                     } else {
                         if ($r["contest_type"] == "UNAMFC") {
                             if (!($r["current_user"]->getUsername() == "manuelalcantara52" || $r["current_user"]->getUsername() == "manuel52" || Authorization::IsSystemAdmin($r["current_user_id"]))) {
                                 throw new ForbiddenAccessException();
                             }
                             $keys = array("UNAMFC15" => 30);
                         } else {
                             if ($r["contest_type"] == "OVI") {
                                 if (!($r["current_user"]->getUsername() == "covi.academico" || Authorization::IsSystemAdmin($r["current_user_id"]))) {
                                     throw new ForbiddenAccessException();
                                 }
                                 $keys = array("OVI15" => 200);
                             } else {
                                 throw new InvalidParameterException("parameterNotInExpectedSet", "contest_type", array("bad_elements" => $r["contest_type"], "expected_set" => "OMI, OMIAGS, ORIG, OSI, OVI"));
                             }
                         }
                     }
                 }
             }
         }
     }
     self::$permissionKey = $r['permission_key'] = self::randomString(32);
     foreach ($keys as $k => $n) {
         $digits = floor(log10($n) + 1);
         for ($i = 1; $i <= $n; $i++) {
             $username = $k . "-" . str_pad($i, $digits, '0', STR_PAD_LEFT);
             $password = self::randomString(8);
             if (self::omiPrepareUser($r, $username, $password)) {
                 $response[$username] = $password;
             }
             // Add user to contest if needed
             if (!is_null($r["contest_alias"])) {
                 $addUserRequest = new Request();
                 $addUserRequest["auth_token"] = $r["auth_token"];
                 $addUserRequest["usernameOrEmail"] = $username;
                 $addUserRequest["contest_alias"] = $r["contest_alias"];
                 ContestController::apiAddUser($addUserRequest);
             }
         }
     }
     return $response;
 }