Skip to content

Commit

Permalink
Added user check when deleting items
Browse files Browse the repository at this point in the history
  • Loading branch information
josteitv committed May 20, 2015
1 parent 9dc3dba commit 2468fdc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/java/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,14 @@ public static void updateTodoItem(TodoItem todoItem) {

}

public static void deleteTodoItem(String id) {
String sql = "delete from TODO_ITEM where id = ?";
public static void deleteTodoItem(String id, String user) {
String sql = "delete from TODO_ITEM where id = ? and user = ?";

Connection connection = getDBConnection();
try {
PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1, id);
ps.setString(2, user);
ps.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/TodoServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
String todo = request.getParameter("todo");
String delete = request.getParameter("delete");

// UTF8-problem i chrome...
// String html = "<h2>TODO for bruker '" + user + "'</h2>";
String html = "<h2>TODO</h2>";

String todoText = "";
String idText = "";

if (!isNullOrEmpty(id) && !isNullOrEmpty(delete)) {
// Delete todo item
Repository.deleteTodoItem(id);
Repository.deleteTodoItem(id, user);

} else if (!isNullOrEmpty(id) && isNullOrEmpty(todo)) {
// View todo item
Expand Down

0 comments on commit 2468fdc

Please sign in to comment.