public function testLogin() { // Turn off sending email on usere creation UserController::$sendEmailOnVerify = false; // Create a user $contestant = UserFactory::createUserWithoutVerify(); // Open index $this->open('/'); // Click in Iniciar Sesion $this->clickAndWait('link=Inicia sesion'); // Type login data $this->type('user', $contestant->getUsername()); $this->type('pass', $contestant->getPassword()); // Click inicia sesion $this->clickAndWait("//input[@value='Inicia sesion']"); // Wait for message $this->waitForElementPresent('//*[@id="content"]/div[2]/div'); $this->assertElementContainsText('//*[@id="content"]/div[2]/div', 'Your email is not verified yet. Please check your e-mail.'); // Go to verification page and wait for redirection to login page $this->open('/api/user/verifyemail/id/' . $contestant->getVerificationId()); $this->waitForElementPresent('//*[@id="content"]/div[2]/div[1]/h1'); // Type login data $this->type('user', $contestant->getUsername()); $this->type('pass', $contestant->getPassword()); // Click inicia sesion $this->clickAndWait("//input[@value='Inicia sesion']"); // Sanity check that we are logged in $this->waitForElementPresent('//*[@id="wrapper"]/div[1]/a'); $this->assertElementContainsText('//*[@id="wrapper"]/div[1]/a', $contestant->getUsername()); }
/** * Logs in a user an returns the auth_token * * @param Users $user * @return string auth_token */ public static function login(Users $user) { UserController::$sendEmailOnVerify = false; // Deactivate cookie setting $oldCookieSetting = SessionController::$setCookieOnRegisterSession; SessionController::$setCookieOnRegisterSession = false; // Inflate request with user data $r = new Request(array("usernameOrEmail" => $user->getUsername(), "password" => $user->getPassword())); // Call the API $response = UserController::apiLogin($r); // Sanity check self::assertEquals("ok", $response["status"]); // Clean up leftovers of Login API unset($_REQUEST); // Set cookie setting as it was before the login SessionController::$setCookieOnRegisterSession = $oldCookieSetting; return $response["auth_token"]; }
public function testLogin() { // Turn off sending email on usere creation UserController::$sendEmailOnVerify = false; // Create a user $contestant = UserFactory::createUser(); // Open index $this->open('/'); // Click in Iniciar Sesion $this->clickAndWait('link=Inicia sesion'); // Type login data $this->type('user', $contestant->getUsername()); $this->type('pass', $contestant->getPassword()); // Click inicia sesion $this->clickAndWait("//input[@value='Inicia sesion']"); // Sanity check that we are logged in $this->waitForElementPresent('//*[@id="wrapper"]/div[1]/a'); $this->assertElementContainsText('//*[@id="wrapper"]/div[1]/a', $contestant->getUsername()); }
/** * Resets the password of the OMI user and adds the user to the private * contest. * If the user does not exists, we create him. * * @param Request $r * @param string $username * @param string $password */ private static function omiPrepareUser(Request $r, $username, $password) { try { $user = UsersDAO::FindByUsername($username); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } if (is_null($user)) { self::$log->info('Creating user: '******'username' => $username, 'password' => $password, 'email' => $username . '@omi.com', 'permission_key' => $r['permission_key'])); UserController::$sendEmailOnVerify = false; self::apiCreate($createRequest); return true; } elseif (is_null($r['change_password']) || $r['change_password'] !== 'false') { if (!$user->getVerified()) { self::apiVerifyEmail(new Request(array('auth_token' => $r['auth_token'], 'usernameOrEmail' => $username))); } // Pwd changes are by default unless explictly disabled $resetRequest = new Request(); $resetRequest['auth_token'] = $r['auth_token']; $resetRequest['username'] = $username; $resetRequest['password'] = $password; $resetRequest['permission_key'] = $r['permission_key']; self::apiChangePassword($resetRequest); return true; } return false; }
require_once OMEGAUP_ROOT . "/tests/controllers/ApiCallerMock.php"; // Load test utils require_once OMEGAUP_ROOT . "/tests/controllers/OmegaupTestCase.php"; require_once OMEGAUP_ROOT . "/tests/common/Utils.php"; // Load Factories require_once OMEGAUP_ROOT . '/tests/factories/ProblemsFactory.php'; require_once OMEGAUP_ROOT . '/tests/factories/ContestsFactory.php'; require_once OMEGAUP_ROOT . '/tests/factories/ClarificationsFactory.php'; require_once OMEGAUP_ROOT . '/tests/factories/UserFactory.php'; require_once OMEGAUP_ROOT . '/tests/factories/RunsFactory.php'; require_once OMEGAUP_ROOT . '/tests/factories/GroupsFactory.php'; // Clean previous log Utils::CleanLog(); // Clean problems and runs path Utils::CleanPath(PROBLEMS_PATH); Utils::CleanPath(PROBLEMS_GIT_PATH); Utils::CleanPath(RUNS_PATH); Utils::CleanPath(GRADE_PATH); Utils::CleanPath(IMAGES_PATH); for ($i = 0; $i < 256; $i++) { mkdir(RUNS_PATH . sprintf('/%02x', $i), 0775, true); mkdir(GRADE_PATH . sprintf('/%02x', $i), 0775, true); } // Clean DB Utils::CleanupDB(); // Create a test default user for manual UI operations UserController::$sendEmailOnVerify = false; UserFactory::createUser("test", "testtesttest"); UserController::$sendEmailOnVerify = true; // Globally disable run wait gap. RunController::$defaultSubmissionGap = 0;
/** * Resets the password of the OMI user and adds the user to the private * contest. * If the user does not exists, we create him. * * @param Request $r * @param string $username * @param string $password */ private static function omiPrepareUser(Request $r, $username, $password) { try { $user = UsersDAO::FindByUsername($username); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } if (is_null($user)) { self::$log->info("Creating user: "******"username" => $username, "password" => $password, "email" => $username . "@omi.com", "permission_key" => $r['permission_key'])); UserController::$sendEmailOnVerify = false; self::apiCreate($createRequest); return true; } else { if (is_null($r["change_password"]) || $r["change_password"] !== "false") { if (!$user->getVerified()) { self::apiVerifyEmail(new Request(array("auth_token" => $r["auth_token"], "usernameOrEmail" => $username))); } // Pwd changes are by default unless explictly disabled $resetRequest = new Request(); $resetRequest["auth_token"] = $r["auth_token"]; $resetRequest["username"] = $username; $resetRequest["password"] = $password; $resetRequest['permission_key'] = $r['permission_key']; self::apiChangePassword($resetRequest); return true; } } return false; }