aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/http/MainServlet.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-05-10 18:11:40 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-05-10 18:11:40 +1200
commitbd09a39f12c4471bdc342e5a16fbabdffdc645d1 (patch)
treedb94476ee604c2026c5653975c526352093d5628 /src/org/traccar/http/MainServlet.java
parent953852e6e984f8a639cf1a5ac4116fff755d538a (diff)
downloadtrackermap-server-bd09a39f12c4471bdc342e5a16fbabdffdc645d1.tar.gz
trackermap-server-bd09a39f12c4471bdc342e5a16fbabdffdc645d1.tar.bz2
trackermap-server-bd09a39f12c4471bdc342e5a16fbabdffdc645d1.zip
Refactor web app architecture
Diffstat (limited to 'src/org/traccar/http/MainServlet.java')
-rw-r--r--src/org/traccar/http/MainServlet.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/org/traccar/http/MainServlet.java b/src/org/traccar/http/MainServlet.java
index 036c472f8..18430f0c3 100644
--- a/src/org/traccar/http/MainServlet.java
+++ b/src/org/traccar/http/MainServlet.java
@@ -41,24 +41,34 @@ public class MainServlet extends BaseServlet {
}
private void session(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.getWriter().println("{ success: true, session: " + (req.getSession().getAttribute(USER_ID) != null) + " }");
+ User user = (User) req.getSession().getAttribute(USER_KEY);
+ if (user != null) {
+ sendResponse(resp.getWriter(), JsonConverter.objectToJson(user));
+ } else {
+ sendResponse(resp.getWriter(), false);
+ }
}
private void login(HttpServletRequest req, HttpServletResponse resp) throws Exception {
- req.getSession().setAttribute(USER_ID, Context.getDataManager().login(
- req.getParameter("email"), req.getParameter("password")));
- sendResponse(resp.getWriter());
+ User user = Context.getDataManager().login(
+ req.getParameter("email"), req.getParameter("password"));
+ if (user != null) {
+ req.getSession().setAttribute(USER_KEY, user);
+ sendResponse(resp.getWriter(), JsonConverter.objectToJson(user));
+ } else {
+ sendResponse(resp.getWriter(), false);
+ }
}
private void logout(HttpServletRequest req, HttpServletResponse resp) throws Exception {
- req.getSession().removeAttribute(USER_ID);
- sendResponse(resp.getWriter());
+ req.getSession().removeAttribute(USER_KEY);
+ sendResponse(resp.getWriter(), true);
}
private void register(HttpServletRequest req, HttpServletResponse resp) throws Exception {
User user = JsonConverter.objectFromJson(req.getReader(), new User());
Context.getDataManager().addUser(user);
- sendResponse(resp.getWriter());
+ sendResponse(resp.getWriter(), true);
}
}