Skip to content

Commit d5855db

Browse files
committed
Merge branch 'master' of https://github.com/LeRon1605/TDBlog
2 parents b17f3ae + dc65154 commit d5855db

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/main/java/controllers/post/DeleteServlet.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import javax.servlet.http.HttpServletRequest;
88
import javax.servlet.http.HttpServletResponse;
99

10+
import controllers.BaseServlet;
1011
import models.BO.PostBO;
1112
import models.Bean.Post;
1213

1314
@WebServlet("/posts/delete")
14-
public class DeleteServlet extends HttpServlet {
15+
public class DeleteServlet extends BaseServlet {
1516
private PostBO postBO;
1617
public DeleteServlet() {
1718
postBO = new PostBO();
@@ -21,10 +22,22 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
2122
}
2223

2324
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
24-
String id = request.getParameter("id");
25-
Post post = postBO.getById(id);
26-
if (post == null) {
27-
response.sendRedirect("/page-not-found");
25+
super.doPost(request, response);
26+
if(this.authContext.isInRole("ADMIN")) {
27+
String id = request.getParameter("id");
28+
Post post = postBO.getById(id);
29+
if(post == null) {
30+
response.sendRedirect("/page-not-found");
31+
} else {
32+
boolean result = postBO.deletePost(id);
33+
if(result) {
34+
response.sendRedirect("/admin");
35+
} else {
36+
response.sendRedirect("/page-not-found");
37+
}
38+
}
39+
} else {
40+
request.getRequestDispatcher("/views/errors/unauthorized.jsp").forward(request, response);
2841
}
2942
}
3043

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package models.DAO;
2+
3+
public class DatabaseConfig {
4+
public static String host = "localhost:3306";
5+
public static String name = "TDBlog";
6+
public static String username = "root";
7+
public static String password = "ronle75";
8+
9+
public static String getConnectionString() {
10+
return "jdbc:mysql://" + host + "/" + name + "?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterSetResults=utf8&characterEncodi‌​ng=UTF-8";
11+
}
12+
}

0 commit comments

Comments
 (0)