Subversion Repositories WebE

Compare Revisions

Last modification

Ignore whitespace Rev 25 → Rev 26

/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,91 +10,111 @@
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
-public class LoginAction extends ActionSupport implements ModelDriven<User>{
-
- private static final long serialVersionUID = 1799753056277211344L;
- 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 class LoginAction extends ActionSupport implements ModelDriven<User>
+{
- public LoginAction() {
- }
-
- public String doLogin() {
-
- //If password or user name are empty, the login fails.
- if("".equals(getUserName()) || "".equals(getPw()) || getUserName() == null || getPw() == null) {
- return ERROR;
- }
-
- String verifiedUser = verifyUser(getUserName(), getPw());
- if(verifiedUser.equals("failed")) {
- return ERROR;
- } 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 ERROR;
-
- //User password does not match
- if(!u.getPassword().equals(password))
- return ERROR;
-
- //User credentials are fine, check for admin rights
- if(u.isAdmin()) {
- return "admin";
- } else {
- return "user";
- }
- }
-
- public String getUserName() {
- return userName;
- }
+ private static final long serialVersionUID = 1799753056277211344L;
+ private User user = new User();
+ private UserDAO userDAO = new UserDAOImpl();
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- public String getPw() {
- return pw;
- }
+ // Form fields
+ private String userName;
+ private String pw;
- public void setPw(String pw) {
- this.pw = pw;
- }
+ // Session Object
+ Map<String, Object> session = ActionContext.getContext().getSession();
- @Override
- public User getModel() {
- return user;
- }
+ public LoginAction()
+ {
+ }
+
+ public String doLogin()
+ {
+
+ // If password or user name are empty, the login fails.
+ if ("".equals(getUserName()) || "".equals(getPw())
+ || getUserName() == null || getPw() == null)
+ {
+ return ERROR;
+ }
+
+ String verifiedUser = verifyUser(getUserName(), getPw());
+ if (verifiedUser.equals("failed"))
+ {
+ return ERROR;
+ }
+ 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 ERROR;
+
+ // User password does not match
+ if (!u.getPassword().equals(password))
+ return ERROR;
+
+ // User credentials are fine, check for admin rights
+ if (u.isAdmin())
+ {
+ return "admin";
+ }
+ else
+ {
+ return "user";
+ }
+ }
+
+ public String getUserName()
+ {
+ return userName;
+ }
+
+ public void setUserName(String userName)
+ {
+ this.userName = userName;
+ }
+
+ public String getPw()
+ {
+ return pw;
+ }
+
+ public void setPw(String pw)
+ {
+ this.pw = pw;
+ }
+
+ @Override
+ public User getModel()
+ {
+ return user;
+ }
}
/trunk/src/ch/ffhs/webE/action/UserAction.java
15,50 → 15,98
 
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;
private static final long serialVersionUID = -6659925652584240539L;
 
private User user = new User();
private List<User> userList = new ArrayList<User>();
private UserDAO userDAO = new UserDAOImpl();
private User user = new User();
private List<User> userList = new ArrayList<User>();
private UserDAO userDAO = new UserDAOImpl();
 
@Override
public User getModel() {
return user;
}
@Override
public User getModel()
{
return user;
}
 
public String add() {
userDAO.saveUser(user);
return SUCCESS;
}
/**
* Executes the DB query to save the user
*
* @return
*/
public String add()
{
userDAO.saveUser(user);
return SUCCESS;
}
 
public String list() {
userList = userDAO.listUser();
return SUCCESS;
}
/**
* DB query for userList
*
* @return SUCCESS
*/
public String list()
{
userList = userDAO.listUser();
return SUCCESS;
}
 
public User getUser() {
return user;
}
/**
* 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);
 
public void setUser(User user) {
this.user = user;
}
int id = 0;
try
{
id = Integer.parseInt(request.getParameter("id"));
}
catch (Exception e)
{
return ERROR;
}
 
public List<User> getUserList() {
return userList;
}
// Check for malicious ID values
if (id > 0)
{
userDAO.deleteUser(id);
return SUCCESS;
}
else
{
return ERROR;
}
}
 
public void setUserList(List<User> userList) {
this.userList = userList;
}
/*
* Standard getters and setters
*/
 
public String delete() {
HttpServletRequest request = (HttpServletRequest) ActionContext
.getContext().get(ServletActionContext.HTTP_REQUEST);
userDAO.deleteUser(Integer.parseInt(request.getParameter("id")));
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;
}
}