/** * 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"]; }
/** * Test user login with valid credentials, username and password * * @expectedException InvalidCredentialsException */ public function testNativeLoginWithOldPassword() { // Create an user in omegaup $user = UserFactory::createUser(); $plainPassword = $user->getPassword(); // Set old password $user->setPassword(md5($plainPassword)); UsersDAO::save($user); // Let's put back plain password $user->setPassword($plainPassword); // Inflate request with user data $r = new Request(array('usernameOrEmail' => $user->getUsername(), 'password' => $user->getPassword())); // Call the API $response = UserController::apiLogin($r); }