MentaTutorials

Compare Revisions

Ignore whitespace Rev 25 → Rev 24

/MentaRefAppWithService/trunk/src/test/java/org/menta/action/LoginActionTest.java
38,8 → 38,13
 
String result, errorId;
User user = new User();
// test wrong password...
result = login.execute("testUser", "wrong_pass");
input.setValue("username", "testUser");
input.setValue("password", "wrong_pass");
input.inject(user);
result = login.execute(user);
errorId = login.getError("username");
47,8 → 52,11
Assert.assertEquals(Type.WRONG_PASSWORD.toString(), errorId);
// test success...
result = login.execute("testUser", "abc123");
input.setValue("password", "abc123");
input.inject(user);
result = login.execute(user);
Assert.assertEquals(SUCCESS, result);
}
/MentaRefAppWithService/trunk/src/main/java/org/menta/service/UserService.java
15,6 → 15,6
* @return User if username and password match
* @throws LoginException if username or password doesn't match
*/
public User login(String username, String password) throws LoginException;
public User login(User user) throws LoginException;
}
/MentaRefAppWithService/trunk/src/main/java/org/menta/service/impl/UserServiceImpl.java
84,18 → 84,18
}
 
@Override
public User login(final String username, String password) throws LoginException {
public User login(final User user) throws LoginException {
 
final User userFound = userDAO.findByUsername(username);
final User userFinded = userDAO.findByUsername(user.getUsername());
 
if (userFound == null) {
if (userFinded == null) {
throw new LoginException(Type.USERNAME_NOTFOUND);
}
 
if (!userFound.getPassword().equals(password)) {
if (!userFinded.getPassword().equals(user.getPassword())) {
throw new LoginException(Type.WRONG_PASSWORD);
}
 
return userFound;
return userFinded;
}
}
/MentaRefAppWithService/trunk/src/main/java/org/menta/AppManager.java
154,7 → 154,6
.all(ajax(new ResultRenderer())); // return text/plain with the result...
action("/Login", LoginAction.class)
.pojoParams("username", "password")
.on(ERROR, fwd("/jsp/login.jsp"))
.on(SUCCESS, redir("/jsp/index.jsp"));
/MentaRefAppWithService/trunk/src/main/java/org/menta/action/LoginAction.java
16,15 → 16,15
this.userService = userService;
}
 
public String execute(String username, String password) {
public String execute(User user) {
try {
User userFound = userService.login(username, password);
User userFinded = userService.login(user);
setSessionObj(userFound);
setSessionGroups(userFound.getGroup());
setSessionLocale(userFound.getLocale());
setSessionObj(userFinded);
setSessionGroups(userFinded.getGroup());
setSessionLocale(userFinded.getLocale());
return SUCCESS;