MentaTutorials

Rev

Rev 25 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 soliveira 1
package org.menta.action;
2
 
3
import org.menta.exception.LoginException;
4
import org.menta.model.User;
5
import org.menta.service.UserService;
6
import org.mentawai.action.BaseLoginAction;
7
import org.mentawai.validation.Validatable;
8
import org.mentawai.validation.Validator;
9
 
10
 
11
public class LoginAction extends BaseLoginAction implements Validatable {
12
 
13
   private final UserService userService;
14
 
15
   public LoginAction(UserService userService) {
16
           this.userService = userService;
17
   }
18
 
19
   public String execute(User user) {
20
 
21
           try {
22
 
23
                   User userFinded = userService.login(user);
24
 
25
                   setSessionObj(userFinded);
26
                   setSessionGroups(userFinded.getGroup());
27
                   setSessionLocale(userFinded.getLocale());
28
 
29
                   return SUCCESS;
30
 
31
                } catch (LoginException e) {
32
                        addError("username", e.getType().toString());
33
                        return ERROR;
34
                }
35
 
36
   }
37
 
38
        @Override
39
        public void prepareValidator(Validator validator, String innerAction) {
40
                validator.requiredFields("username.password.required", "username","password");
41
        }
42
 
43
}