Rev 18 | Rev 20 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
18 | moos | 1 | package ch.ffhs.webE.action; |
2 | |||
19 | moos | 3 | |
4 | import ch.ffhs.webE.dao.UserDAO; |
||
5 | import ch.ffhs.webE.dao.UserDAOImpl; |
||
6 | import ch.ffhs.webE.domain.User; |
||
7 | |||
18 | moos | 8 | import com.opensymphony.xwork2.ActionSupport; |
19 | moos | 9 | import com.opensymphony.xwork2.ModelDriven; |
18 | moos | 10 | |
19 | moos | 11 | public class LoginAction extends ActionSupport implements ModelDriven<User>{ |
18 | moos | 12 | |
13 | private static final long serialVersionUID = 1799753056277211344L; |
||
19 | moos | 14 | private User user = new User(); |
15 | private UserDAO userDAO = new UserDAOImpl(); |
||
18 | moos | 16 | |
19 | moos | 17 | |
18 | moos | 18 | private String userName ; |
19 | moos | 19 | private String pw; |
18 | moos | 20 | |
21 | public LoginAction() { |
||
22 | } |
||
23 | |||
19 | moos | 24 | public String verifyUser() { |
25 | |||
26 | //If password or user name are empty, the login fails. |
||
27 | if("".equals(getUserName()) || "".equals(getPw()) || getUserName() == null || getPw() == null) { |
||
28 | return "failed"; |
||
29 | } |
||
30 | |||
31 | User u = userDAO.searchUsername(getUserName()); |
||
32 | |||
33 | if(u == null) |
||
34 | return "failed"; |
||
35 | |||
36 | if(!u.getPassword().equals(getPw())) |
||
37 | return "failed"; |
||
38 | |||
39 | if(u.isAdmin()) { |
||
40 | return "admin"; |
||
18 | moos | 41 | } else { |
19 | moos | 42 | return "user"; |
18 | moos | 43 | } |
44 | } |
||
45 | |||
46 | public String getUserName() { |
||
47 | return userName; |
||
48 | } |
||
49 | |||
50 | public void setUserName(String userName) { |
||
51 | this.userName = userName; |
||
52 | } |
||
19 | moos | 53 | |
54 | public String getPw() { |
||
55 | return pw; |
||
56 | } |
||
18 | moos | 57 | |
19 | moos | 58 | public void setPw(String pw) { |
59 | this.pw = pw; |
||
18 | moos | 60 | } |
19 | moos | 61 | |
62 | @Override |
||
63 | public User getModel() { |
||
64 | return user; |
||
18 | moos | 65 | } |
66 | |||
67 | |||
68 | |||
69 | |||
70 | } |