implemented administration of relationship type (edit and delete are not yet working)
/trunk/src/ch/ffhs/webE/action/UserForm.java |
---|
File deleted |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: RelationshipTypeAction.java |
=================================================================== |
--- RelationshipTypeAction.java (nonexistent) |
+++ RelationshipTypeAction.java (revision 26) |
@@ -0,0 +1,104 @@ |
+package ch.ffhs.webE.action; |
+ |
+import java.util.ArrayList; |
+import java.util.List; |
+ |
+import javax.servlet.http.HttpServletRequest; |
+ |
+import org.apache.struts2.ServletActionContext; |
+ |
+import ch.ffhs.webE.dao.RelationshipTypeDAO; |
+import ch.ffhs.webE.dao.RelationshipTypeDAOImpl; |
+import ch.ffhs.webE.domain.RelationshipType; |
+ |
+import com.opensymphony.xwork2.ActionContext; |
+import com.opensymphony.xwork2.ActionSupport; |
+import com.opensymphony.xwork2.ModelDriven; |
+ |
+public class RelationshipTypeAction extends ActionSupport implements |
+ ModelDriven<RelationshipType> |
+{ |
+ |
+ private static final long serialVersionUID = -3644691864156792139L; |
+ |
+ private RelationshipType relType = new RelationshipType(); |
+ private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>(); |
+ private RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl(); |
+ |
+ @Override |
+ public RelationshipType getModel() |
+ { |
+ return relType; |
+ } |
+ |
+ public String add() |
+ { |
+ relTypeDAO.saveRelationshipType(relType); |
+ return SUCCESS; |
+ } |
+ |
+ public String list() |
+ { |
+ relTypeList = relTypeDAO.listRelationshipTypes(); |
+ return SUCCESS; |
+ } |
+ |
+ /** |
+ * deletes a relationshipType, gets the ID from the id parameter that was |
+ * submitted |
+ * |
+ * @return String - either success or error |
+ */ |
+ public String delete() |
+ { |
+ HttpServletRequest request = (HttpServletRequest) ActionContext |
+ .getContext().get(ServletActionContext.HTTP_REQUEST); |
+ |
+ //Make sure the ID from the request parameter is valid |
+ int id = 0; |
+ |
+ try |
+ { |
+ id = Integer.parseInt(request.getParameter("id")); |
+ } |
+ catch (Exception e) |
+ { |
+ return ERROR; |
+ } |
+ |
+ // Check for malicious ID values |
+ if (id > 0) |
+ { |
+ relTypeDAO.deleteRelationshipType(id); |
+ return SUCCESS; |
+ } |
+ else |
+ { |
+ return ERROR; |
+ } |
+ } |
+ |
+ /* |
+ * Getters and setters |
+ */ |
+ |
+ public RelationshipType getRelType() |
+ { |
+ return relType; |
+ } |
+ |
+ public void setRelType(RelationshipType relType) |
+ { |
+ this.relType = relType; |
+ } |
+ |
+ public List<RelationshipType> getRelTypeList() |
+ { |
+ return relTypeList; |
+ } |
+ |
+ public void setRelTypeList(List<RelationshipType> relTypeList) |
+ { |
+ this.relTypeList = relTypeList; |
+ } |
+} |
\ No newline at end of file |
/RelationshipTypeAction.java |
---|
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: LoginAction.java |
=================================================================== |
--- LoginAction.java (revision 25) |
+++ LoginAction.java (revision 26) |
@@ -1,6 +1,5 @@ |
package ch.ffhs.webE.action; |
- |
import java.util.Map; |
import ch.ffhs.webE.dao.UserDAO; |
@@ -11,7 +10,8 @@ |
import com.opensymphony.xwork2.ActionSupport; |
import com.opensymphony.xwork2.ModelDriven; |
-public class LoginAction extends ActionSupport implements ModelDriven<User>{ |
+public class LoginAction extends ActionSupport implements ModelDriven<User> |
+{ |
private static final long serialVersionUID = 1799753056277211344L; |
private User user = new User(); |
@@ -24,21 +24,27 @@ |
//Session Object |
Map<String, Object> session = ActionContext.getContext().getSession(); |
- |
- public LoginAction() { |
+ public LoginAction() |
+ { |
} |
- public String doLogin() { |
+ public String doLogin() |
+ { |
//If password or user name are empty, the login fails. |
- if("".equals(getUserName()) || "".equals(getPw()) || getUserName() == null || getPw() == null) { |
+ if ("".equals(getUserName()) || "".equals(getPw()) |
+ || getUserName() == null || getPw() == null) |
+ { |
return ERROR; |
} |
String verifiedUser = verifyUser(getUserName(), getPw()); |
- if(verifiedUser.equals("failed")) { |
+ if (verifiedUser.equals("failed")) |
+ { |
return ERROR; |
- } else { |
+ } |
+ else |
+ { |
//Put user name, password into session |
session.put("username", getUserName()); |
@@ -47,7 +53,8 @@ |
} |
} |
- public String doLogout() { |
+ public String doLogout() |
+ { |
//TODO: Kill session content for logout |
return SUCCESS; |
} |
@@ -54,11 +61,15 @@ |
/** |
* Verify user credentials |
- * @param String username: User name |
- * @param String password: Password (hashed) |
+ * |
+ * @param String |
+ * username: User name |
+ * @param String |
+ * password: Password (hashed) |
* @return |
*/ |
- public String verifyUser(String username, String password) { |
+ public String verifyUser(String username, String password) |
+ { |
//DB Query |
User u = userDAO.searchUsername(username); |
@@ -71,31 +82,39 @@ |
return ERROR; |
//User credentials are fine, check for admin rights |
- if(u.isAdmin()) { |
+ if (u.isAdmin()) |
+ { |
return "admin"; |
- } else { |
+ } |
+ else |
+ { |
return "user"; |
} |
} |
- public String getUserName() { |
+ public String getUserName() |
+ { |
return userName; |
} |
- public void setUserName(String userName) { |
+ public void setUserName(String userName) |
+ { |
this.userName = userName; |
} |
- public String getPw() { |
+ public String getPw() |
+ { |
return pw; |
} |
- public void setPw(String pw) { |
+ public void setPw(String pw) |
+ { |
this.pw = pw; |
} |
@Override |
- public User getModel() { |
+ public User getModel() |
+ { |
return user; |
} |
} |
/trunk/src/ch/ffhs/webE/action/UserAction.java |
---|
15,7 → 15,8 |
import ch.ffhs.webE.domain.User; |
public class UserAction extends ActionSupport implements ModelDriven<User> { |
public class UserAction extends ActionSupport implements ModelDriven<User> |
{ |
private static final long serialVersionUID = -6659925652584240539L; |
24,41 → 25,88 |
private UserDAO userDAO = new UserDAOImpl(); |
@Override |
public User getModel() { |
public User getModel() |
{ |
return user; |
} |
public String add() { |
/** |
* Executes the DB query to save the user |
* |
* @return |
*/ |
public String add() |
{ |
userDAO.saveUser(user); |
return SUCCESS; |
} |
public String list() { |
/** |
* DB query for userList |
* |
* @return SUCCESS |
*/ |
public String list() |
{ |
userList = userDAO.listUser(); |
return SUCCESS; |
} |
public User getUser() { |
/** |
* deletes a user, gets the ID from the "id" parameter that was submitted |
* with the HTTP request |
* |
* @return String - either SUCCESS or ERROR constant |
*/ |
public String delete() |
{ |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(ServletActionContext.HTTP_REQUEST); |
int id = 0; |
try |
{ |
id = Integer.parseInt(request.getParameter("id")); |
} |
catch (Exception e) |
{ |
return ERROR; |
} |
// Check for malicious ID values |
if (id > 0) |
{ |
userDAO.deleteUser(id); |
return SUCCESS; |
} |
else |
{ |
return ERROR; |
} |
} |
/* |
* Standard getters and setters |
*/ |
public User getUser() |
{ |
return user; |
} |
public void setUser(User user) { |
public void setUser(User user) |
{ |
this.user = user; |
} |
public List<User> getUserList() { |
public List<User> getUserList() |
{ |
return userList; |
} |
public void setUserList(List<User> userList) { |
public void setUserList(List<User> userList) |
{ |
this.userList = userList; |
} |
public String delete() { |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(ServletActionContext.HTTP_REQUEST); |
userDAO.deleteUser(Integer.parseInt(request.getParameter("id"))); |
return SUCCESS; |
} |
} |