From 47cea42e319176aa69decc43e8d8074374ff0c4b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 11 Jan 2013 19:48:19 +1300 Subject: Add logout button --- src/org/traccar/web/server/model/DataServiceImpl.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/org/traccar/web/server') diff --git a/src/org/traccar/web/server/model/DataServiceImpl.java b/src/org/traccar/web/server/model/DataServiceImpl.java index 9c69b48e..01ab3164 100644 --- a/src/org/traccar/web/server/model/DataServiceImpl.java +++ b/src/org/traccar/web/server/model/DataServiceImpl.java @@ -55,7 +55,11 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService private void setUser(User user) { HttpSession session = getThreadLocalRequest().getSession(); - session.setAttribute(ATTRIBUTE_USER, user); + if (user != null) { + session.setAttribute(ATTRIBUTE_USER, user); + } else { + session.removeAttribute(ATTRIBUTE_USER); + } } private User getUser() { @@ -69,7 +73,7 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService } @Override - public boolean authenticate(String login, String password) { + public boolean login(String login, String password) { TypedQuery query = entityManager.createQuery( "SELECT x FROM User x WHERE x.login = :login", User.class); query.setParameter("login", login); @@ -82,6 +86,12 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService return false; } + @Override + public boolean logout() { + setUser(null); + return true; + } + @Override public boolean register(String login, String password) { User user = new User(); -- cgit v1.2.3