5
I have a login screen where I authenticate a user, but when I put one action
to switch page regardless of whether the user was authenticated or not the page opens.
My question is to know where I have to do the verification if the user is authenticated or not to redirect?
Knob:
<f:facet name="footer">
<p:commandButton value="Entrar" update=":msgGlobal"
actionListener="#{usuarioBean.entrar}" action="principal?faces-redirect=true"/>
</f:facet>
Method that authenticates:
public void entrar() {
try {
UsuarioDAO usuarioDAO = new UsuarioDAO();
usuarioLogado = usuarioDAO.autenticar(usuarioLogado.getLogin(),
usuarioLogado.getSenha());
if (usuarioLogado == null) {
FacesUtil.adicionarMsgErro("Login ou Senha inválidos");
} else {
FacesUtil.adicionarMsgInfo("Usuario Autenticado com Sucesso");
}
} catch (RuntimeException ex) {
FacesUtil.adicionarMsgErro("Erro ao tentar entrar no Sistema");
}
}
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero