implemented administration of relationship type (edit and delete are not yet working)
/trunk/src/ch/ffhs/webE/action/RelationshipTypeAction.java |
---|
File deleted |
\ No newline at end of file |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: LoginAction.java |
=================================================================== |
--- LoginAction.java (revision 26) |
+++ LoginAction.java (revision 25) |
@@ -1,5 +1,6 @@ |
package ch.ffhs.webE.action; |
+ |
import java.util.Map; |
import ch.ffhs.webE.dao.UserDAO; |
@@ -10,111 +11,91 @@ |
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(); |
+ private UserDAO userDAO = new UserDAOImpl(); |
+ |
+ //Form fields |
+ private String userName ; |
+ private String pw; |
+ |
+ //Session Object |
+ Map<String, Object> session = ActionContext.getContext().getSession(); |
+ |
- private static final long serialVersionUID = 1799753056277211344L; |
- private User user = new User(); |
- private UserDAO userDAO = new UserDAOImpl(); |
+ 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; |
+ } |
- // Form fields |
- private String userName; |
- private String pw; |
+ public void setUserName(String userName) { |
+ this.userName = userName; |
+ } |
+ |
+ public String getPw() { |
+ return pw; |
+ } |
- // Session Object |
- Map<String, Object> session = ActionContext.getContext().getSession(); |
+ public void setPw(String pw) { |
+ this.pw = pw; |
+ } |
- 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; |
- } |
+ @Override |
+ public User getModel() { |
+ return user; |
+ } |
} |
/trunk/src/ch/ffhs/webE/action/UserAction.java |
---|
15,98 → 15,50 |
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; |
} |
/** |
* Executes the DB query to save the user |
* |
* @return |
*/ |
public String add() |
{ |
userDAO.saveUser(user); |
return SUCCESS; |
} |
public String add() { |
userDAO.saveUser(user); |
return SUCCESS; |
} |
/** |
* DB query for userList |
* |
* @return SUCCESS |
*/ |
public String list() |
{ |
userList = userDAO.listUser(); |
return SUCCESS; |
} |
public String list() { |
userList = userDAO.listUser(); |
return SUCCESS; |
} |
/** |
* 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 User getUser() { |
return user; |
} |
int id = 0; |
try |
{ |
id = Integer.parseInt(request.getParameter("id")); |
} |
catch (Exception e) |
{ |
return ERROR; |
} |
public void setUser(User user) { |
this.user = user; |
} |
// Check for malicious ID values |
if (id > 0) |
{ |
userDAO.deleteUser(id); |
return SUCCESS; |
} |
else |
{ |
return ERROR; |
} |
} |
public List<User> getUserList() { |
return userList; |
} |
/* |
* Standard getters and setters |
*/ |
public void setUserList(List<User> userList) { |
this.userList = userList; |
} |
public User getUser() |
{ |
return user; |
} |
public String delete() { |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(ServletActionContext.HTTP_REQUEST); |
userDAO.deleteUser(Integer.parseInt(request.getParameter("id"))); |
return SUCCESS; |
} |
public void setUser(User user) |
{ |
this.user = user; |
} |
public List<User> getUserList() |
{ |
return userList; |
} |
public void setUserList(List<User> userList) |
{ |
this.userList = userList; |
} |
} |
/trunk/src/ch/ffhs/webE/action/UserForm.java |
---|
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; |
} |
} |
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |