Skip to content

Instantly share code, notes, and snippets.

@rafaeltoledo
Created November 8, 2019 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaeltoledo/5f4ce3d70297e7aa1de03a4807f31362 to your computer and use it in GitHub Desktop.
Save rafaeltoledo/5f4ce3d70297e7aa1de03a4807f31362 to your computer and use it in GitHub Desktop.
Mentawai 03
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;
}
}
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);
}
}
ac = new ActionConfig("Logout", LogoutAction.class);
ac.addConsequence(LogoutAction.SUCCESS, new Redirect("/home.jsp"));
addActionConfig(ac);
<%@ 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>
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());
<%@ 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