Last active
November 29, 2017 19:42
-
-
Save Felipe00/c7b4198408e7ccbb8a24dd8f83d80e7b to your computer and use it in GitHub Desktop.
Como usar threads e fazer a página aguardar a requisição ser finalizada. [CompletableFuture<Result> , Firebase]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** This method was called by Play! through the some tag in the html */ | |
public CompletableFuture<Result> submit() { | |
auth = FirebaseAuth.getInstance(app); | |
final Form<LoginForm> filledForm = loginForm.bindFromRequest(); | |
return signIn(filledForm); | |
} | |
private CompletableFuture<Result> signIn(Form<LoginForm> filledForm) { | |
final CompletableFuture<Result> resultFuture = new CompletableFuture(); | |
final ApiFuture<UserRecord> firebaseFuture = auth.getUserByEmailAsync(filledForm.get().getEmail()); | |
ApiFutures.addCallback(firebaseFuture, new ApiFutureCallback<UserRecord>() { | |
@Override | |
public void onFailure(Throwable throwable) { | |
Logger.debug("Erro: " + throwable.getMessage()); | |
resultFuture.complete(badRequest(views.html.index.render())); | |
} | |
@Override | |
public void onSuccess(UserRecord userRecord) { | |
Logger.debug("Logado com sucesso"); | |
resultFuture.complete(ok(views.html.profile.render(user))); | |
} | |
}); | |
return resultFuture; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment