| 1,23 → 1,45 |
| package ch.ffhs.webE.action; |
| |
| |
| import ch.ffhs.webE.dao.UserDAO; |
| import ch.ffhs.webE.dao.UserDAOImpl; |
| import ch.ffhs.webE.domain.User; |
| |
| import com.opensymphony.xwork2.ActionSupport; |
| import com.opensymphony.xwork2.ModelDriven; |
| |
| public class LoginAction extends ActionSupport { |
| public class LoginAction extends ActionSupport implements ModelDriven<User>{ |
| |
| private static final long serialVersionUID = 1799753056277211344L; |
| private User user = new User(); |
| private UserDAO userDAO = new UserDAOImpl(); |
| |
| |
| private String userName ; |
| private String password; |
| private String pw; |
| |
| public LoginAction() { |
| } |
| |
| public String execute() { |
| //TODO: DB Abfrage für Login |
| if("moos".equals(getUserName())) { |
| return "success"; |
| public String verifyUser() { |
| |
| //If password or user name are empty, the login fails. |
| if("".equals(getUserName()) || "".equals(getPw()) || getUserName() == null || getPw() == null) { |
| return "failed"; |
| } |
| |
| User u = userDAO.searchUsername(getUserName()); |
| |
| if(u == null) |
| return "failed"; |
| |
| if(!u.getPassword().equals(getPw())) |
| return "failed"; |
| |
| if(u.isAdmin()) { |
| return "admin"; |
| } else { |
| return "failed"; |
| return "user"; |
| } |
| } |
| |
| 28,12 → 50,18 |
| public void setUserName(String userName) { |
| this.userName = userName; |
| } |
| |
| public String getPw() { |
| return pw; |
| } |
| |
| public String getPassword() { |
| return password; |
| public void setPw(String pw) { |
| this.pw = pw; |
| } |
| public void setPassword(String password) { |
| this.password = password; |
| |
| @Override |
| public User getModel() { |
| return user; |
| } |
| |
| |