- introduced sitemesh for templating, all templates rewritten - added some basic admin stuff
| /trunk/src/struts.xml |
|---|
| 3,14 → 3,40 |
| "http://struts.apache.org/dtds/struts-2.0.dtd"> |
| <struts> |
| <package name="default" extends="hibernate-default"> |
| <constant name="struts.devMode" value="false" /> <!-- set to true for more debugging output --> |
| <!-- User environment --> |
| <package name="user" namespace="/user" extends="struts-default"> |
| </package> |
| <!-- Admin environment --> |
| <package name="admin" namespace="/admin" extends="hibernate-default"> |
| <action name="userAddForm"> |
| <result>/admin/userAddForm.jsp</result> |
| </action> |
| <action name="LoginDo" method="verifyUser" class="ch.ffhs.webE.action.LoginAction"> |
| <result name="admin" type="redirect">/admin_index.jsp</result> |
| <result name="user" type="redirect">/user_index.jsp</result> |
| <action name="doUserAdd" method="addForm" class="ch.ffhs.webE.action.UserAction"> |
| <result name="success" type="redirect">/admin/userAdd.jsp</result> |
| </action> |
| <action name="userList"> |
| <result>/admin/userList.jsp</result> |
| </action> |
| </package> |
| <!-- Remaining environment of the session--> |
| <package name="default" namespace="" extends="hibernate-default"> |
| <!-- Login --> |
| <action name="Login" method="doLogin" class="ch.ffhs.webE.action.LoginAction"> |
| <result name="admin" type="redirect">/admin/main.jsp</result> |
| <result name="user" type="redirect">/user/main.jsp</result> |
| <result name="failed" type="redirect">/index.jsp</result> |
| </action> |
| <action name="Logout" method="doLogout" class="ch.ffhs.webE.action.LoginAction"> |
| <result name="success" type="redirect">/index.jsp</result> |
| </action> |
| </package> |
| </struts> |
| /trunk/src/ch/ffhs/webE/web/UserAction.java |
|---|
| File deleted |
| Property changes: |
| Deleted: svn:mime-type |
| ## -1 +0,0 ## |
| -text/plain |
| \ No newline at end of property |
| Index: ch/ffhs/webE/action/UserForm.java |
| =================================================================== |
| --- ch/ffhs/webE/action/UserForm.java (nonexistent) |
| +++ ch/ffhs/webE/action/UserForm.java (revision 20) |
| @@ -0,0 +1,73 @@ |
| +package ch.ffhs.webE.action; |
| + |
| +import javax.servlet.http.HttpServletRequest; |
| + |
| +import org.apache.struts2.components.ActionError; |
| +import org.apache.struts2.dispatcher.mapper.ActionMapping; |
| + |
| +import com.opensymphony.xwork2.ActionSupport; |
| + |
| +public class UserForm extends ActionSupport { |
| + |
| + private static final long serialVersionUID = 2574972467250197244L; |
| + |
| + private String username; |
| + private String password; |
| + private String firstname; |
| + private String lastname; |
| + private boolean admin; |
| + |
| + public void reset(ActionMapping mapping, HttpServletRequest request) { |
| + this.username = null; |
| + this.password = null; |
| + this.firstname = null; |
| + this.lastname = null; |
| + this.admin = false; |
| + } |
| + |
| + public void validate() { |
| + |
| + } |
| + |
| + |
| + // Getter and setters |
| + public String getUsername() { |
| + return username; |
| + } |
| + |
| + public void setUsername(String username) { |
| + this.username = username; |
| + } |
| + |
| + public String getPassword() { |
| + return password; |
| + } |
| + |
| + public void setPassword(String password) { |
| + this.password = password; |
| + } |
| + |
| + public String getFirstname() { |
| + return firstname; |
| + } |
| + |
| + public void setFirstname(String firstname) { |
| + this.firstname = firstname; |
| + } |
| + |
| + public String getLastname() { |
| + return lastname; |
| + } |
| + |
| + public void setLastname(String lastname) { |
| + this.lastname = lastname; |
| + } |
| + |
| + public boolean isAdmin() { |
| + return admin; |
| + } |
| + |
| + public void setAdmin(boolean admin) { |
| + this.admin = admin; |
| + } |
| +} |
| /ch/ffhs/webE/action/UserForm.java |
|---|
| Property changes: |
| Added: svn:mime-type |
| ## -0,0 +1 ## |
| +text/plain |
| \ No newline at end of property |
| Index: ch/ffhs/webE/action/LoginAction.java |
| =================================================================== |
| --- ch/ffhs/webE/action/LoginAction.java (revision 19) |
| +++ ch/ffhs/webE/action/LoginAction.java (revision 20) |
| @@ -1,10 +1,13 @@ |
| package ch.ffhs.webE.action; |
| +import java.util.Map; |
| + |
| import ch.ffhs.webE.dao.UserDAO; |
| import ch.ffhs.webE.dao.UserDAOImpl; |
| import ch.ffhs.webE.domain.User; |
| +import com.opensymphony.xwork2.ActionContext; |
| import com.opensymphony.xwork2.ActionSupport; |
| import com.opensymphony.xwork2.ModelDriven; |
| @@ -14,28 +17,60 @@ |
| private User user = new User(); |
| private UserDAO userDAO = new UserDAOImpl(); |
| - |
| + //Form fields |
| private String userName ; |
| private String pw; |
| + |
| + //Session Object |
| + Map<String, Object> session = ActionContext.getContext().getSession(); |
| + |
| public LoginAction() { |
| } |
| - public String verifyUser() { |
| + public String doLogin() { |
| //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()); |
| + String verifiedUser = verifyUser(getUserName(), getPw()); |
| + if(verifiedUser.equals("failed")) { |
| + return "failed"; |
| + } else { |
| + |
| + //Put user name, password into session |
| + session.put("username", getUserName()); |
| + session.put("pw", getPw()); |
| + return verifiedUser; |
| + } |
| + } |
| + |
| + public String doLogout() { |
| + //TODO: Kill session content for logout |
| + return SUCCESS; |
| + } |
| + |
| + /** |
| + * Verify user credentials |
| + * @param String username: User name |
| + * @param String password: Password (hashed) |
| + * @return |
| + */ |
| + public String verifyUser(String username, String password) { |
| + //DB Query |
| + User u = userDAO.searchUsername(username); |
| + //User does not exist |
| if(u == null) |
| return "failed"; |
| - if(!u.getPassword().equals(getPw())) |
| + //User password does not match |
| + if(!u.getPassword().equals(password)) |
| return "failed"; |
| + //User credentials are fine, check for admin rights |
| if(u.isAdmin()) { |
| return "admin"; |
| } else { |
| /trunk/src/ch/ffhs/webE/action/UserAction.java |
|---|
| 0,0 → 1,58 |
| package ch.ffhs.webE.action; |
| import java.util.ArrayList; |
| import java.util.List; |
| import com.opensymphony.xwork2.ActionSupport; |
| import com.opensymphony.xwork2.ModelDriven; |
| import ch.ffhs.webE.dao.UserDAO; |
| import ch.ffhs.webE.dao.UserDAOImpl; |
| import ch.ffhs.webE.domain.User; |
| public class UserAction extends ActionSupport implements ModelDriven<User> { |
| private static final long serialVersionUID = -6659925652584240539L; |
| private User user = new User(); |
| private List<User> userList = new ArrayList<User>(); |
| private UserDAO userDAO = new UserDAOImpl(); |
| @Override |
| public User getModel() { |
| return user; |
| } |
| public String add() |
| { |
| userDAO.saveUser(user); |
| return SUCCESS; |
| } |
| public String addForm() { |
| return SUCCESS; |
| } |
| public String list() |
| { |
| userList = userDAO.listUser(); |
| return SUCCESS; |
| } |
| public User getUser() { |
| return user; |
| } |
| public void setUser(User user) { |
| this.user = user; |
| } |
| public List<User> getUserList() { |
| return userList; |
| } |
| public void setUserList(List<User> userList) { |
| this.userList = userList; |
| } |
| } |
| Property changes: |
| Added: svn:mime-type |
| ## -0,0 +1 ## |
| +text/plain |
| \ No newline at end of property |
| Index: log4j.properties |
| =================================================================== |
| --- log4j.properties (revision 19) |
| +++ log4j.properties (revision 20) |
| @@ -3,4 +3,4 @@ |
| log4j.appender.stdout.Target=System.out |
| log4j.appender.stdout.layout=org.apache.log4j.PatternLayout |
| log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n |
| -log4j.rootLogger=debug, stdout |
| \ No newline at end of file |
| +log4j.rootLogger=info, stdout |
| \ No newline at end of file |