-
-
Save rafaeltoledo/5f4ce3d70297e7aa1de03a4807f31362 to your computer and use it in GitHub Desktop.
Mentawai 03
This file contains 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
package net.rafaeltoledo.mentawai.controller.action; | |
import org.mentawai.action.BaseLoginAction; | |
public class LoginAction extends BaseLoginAction { | |
@Override | |
public String execute() throws Exception { | |
String email = input.getString("email"); | |
String senha = input.getString("senha"); | |
// Aqui você pode realizar a sua consulta ao banco | |
if (!"admin@rafaeltoledo.net".equals(email) || !"admin".equals(senha)) { | |
return ERROR; | |
} | |
setUserSession(email); | |
return SUCCESS; | |
} | |
} |
This file contains 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
package net.rafaeltoledo.mentawai.controller; | |
import net.rafaeltoledo.mentawai.controller.action.LoginAction; | |
import org.mentawai.core.ActionConfig; | |
import org.mentawai.core.Forward; | |
import org.mentawai.core.Redirect; | |
import org.mentawai.filter.AuthenticationFilter; | |
public class ApplicationManager extends org.mentawai.core.ApplicationManager { | |
@Override | |
public void loadActions() { | |
addGlobalFilter(new AuthenticationFilter()); | |
addGlobalConsequence(AuthenticationFilter.LOGIN, new Redirect("/login.jsp")); | |
ActionConfig ac = new ActionConfig("Login", LoginAction.class); | |
ac.addConsequence(LoginAction.SUCCESS, new Redirect("/home.jsp")); | |
ac.addConsequence(LoginAction.ERROR, new Forward("/login.jsp")); | |
addActionConfig(ac); | |
} | |
} |
This file contains 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
ac = new ActionConfig("Logout", LogoutAction.class); | |
ac.addConsequence(LogoutAction.SUCCESS, new Redirect("/home.jsp")); | |
addActionConfig(ac); |
This file contains 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
<%@ taglib uri="http://www.mentaframework.org/tags-mtw/" prefix="mtw" %> | |
<mtw:requiresAuthentication /> | |
<html> | |
<body> | |
<h1>O usuário só verá esta página se estiver autenticado!</h1> | |
</body> | |
</html> |
This file contains 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
ActionConfig ac = new ActionConfig("Login", LoginAction.class); | |
ac.addConsequence(LoginAction.SUCCESS, new Redirect("/home.jsp")); | |
ac.addConsequence(LoginAction.ERROR, new Forward("/login.jsp")); | |
addActionConfig(ac); | |
ac.addFilter(new RedirectAfterLoginFilter()); | |
ac.addConsequence(RedirectAfterLoginFilter.REDIR, new Redirect()); |
This file contains 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
<%@ taglib uri="http://www.mentaframework.org/tags-mtw/" prefix="mtw" %> | |
<mtw:requiresAuthentication redir="true" /> | |
<html> | |
<body> | |
<h1>Após a autenticação, o usuário volta pra cá!</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment