From bd09a39f12c4471bdc342e5a16fbabdffdc645d1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 10 May 2015 18:11:40 +1200 Subject: Refactor web app architecture --- src/org/traccar/http/BaseServlet.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/org/traccar/http/BaseServlet.java') diff --git a/src/org/traccar/http/BaseServlet.java b/src/org/traccar/http/BaseServlet.java index 9249b33d8..122dbe70b 100644 --- a/src/org/traccar/http/BaseServlet.java +++ b/src/org/traccar/http/BaseServlet.java @@ -26,10 +26,11 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.traccar.model.User; public abstract class BaseServlet extends HttpServlet { - public static final String USER_ID = "userId"; + public static final String USER_KEY = "user"; @Override protected final void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -46,16 +47,16 @@ public abstract class BaseServlet extends HttpServlet { protected abstract boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception; public long getUserId(HttpSession session) { - Long userId = (Long) session.getAttribute(USER_ID); - if (userId == null) { + User user = (User) session.getAttribute(USER_KEY); + if (user == null) { throw new AccessControlException("User is not logged in"); } - return userId; + return user.getId(); } - public void sendResponse(Writer writer) throws IOException { + public void sendResponse(Writer writer, boolean success) throws IOException { JsonObjectBuilder result = Json.createObjectBuilder(); - result.add("success", true); + result.add("success", success); writer.write(result.build().toString()); } -- cgit v1.2.3