aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/http/www/Login.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/http/www/Login.java')
-rw-r--r--src/main/java/com/juick/http/www/Login.java29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/main/java/com/juick/http/www/Login.java b/src/main/java/com/juick/http/www/Login.java
index 3e9c5e09..f12c7096 100644
--- a/src/main/java/com/juick/http/www/Login.java
+++ b/src/main/java/com/juick/http/www/Login.java
@@ -17,11 +17,10 @@
*/
package com.juick.http.www;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import java.io.IOException;
import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
@@ -33,7 +32,7 @@ import javax.servlet.http.HttpServletResponse;
*/
public class Login {
- protected void doGetLoginForm(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGetLoginForm(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null) {
Utils.sendTemporaryRedirect(response, "/");
@@ -41,8 +40,7 @@ public class Login {
}
response.setContentType("text/html; charset=UTF-8");
- PrintWriter out = response.getWriter();
- try {
+ try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
@@ -182,12 +180,10 @@ public class Login {
out.println("</body>");
out.println("</html>");
- } finally {
- out.close();
}
}
- protected void doGetLogin(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGetLogin(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String hash = request.getQueryString();
if (hash.length() > 32) {
response.sendError(400);
@@ -204,7 +200,7 @@ public class Login {
}
}
- protected void doPostLogin(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doPostLogin(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username == null || password == null || username.length() > 32 || password.isEmpty()) {
@@ -230,19 +226,10 @@ public class Login {
}
}
- protected void doGetLogout(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGetLogout(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
if (visitor != null) {
- PreparedStatement stmt = null;
- try {
- stmt = sql.prepareStatement("DELETE FROM logins WHERE user_id=?");
- stmt.setInt(1, visitor.getUID());
- stmt.executeUpdate();
- } catch (SQLException e) {
- System.err.println(e);
- } finally {
- Utils.finishSQL(null, stmt);
- }
+ sql.update("DELETE FROM logins WHERE user_id=?", visitor.getUID());
}
Cookie c = new Cookie("hash", "-");