diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-12-02 12:06:00 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-12-02 12:06:00 +1300 |
commit | a0c9cec5beb28448073b127c31df23134336f4cf (patch) | |
tree | c52c396dbfaf4b10084677af1720908efc00c7cb | |
parent | a0a96b253b90d389a5c06ba1133b2a2f32ecb0fc (diff) | |
download | trackermap-server-a0c9cec5beb28448073b127c31df23134336f4cf.tar.gz trackermap-server-a0c9cec5beb28448073b127c31df23134336f4cf.tar.bz2 trackermap-server-a0c9cec5beb28448073b127c31df23134336f4cf.zip |
Implement REST login in the web app
-rw-r--r-- | src/org/traccar/api/resource/SessionResource.java | 8 | ||||
-rw-r--r-- | web/app/Application.js | 4 | ||||
-rw-r--r-- | web/app/view/LoginController.js | 20 |
3 files changed, 20 insertions, 12 deletions
diff --git a/src/org/traccar/api/resource/SessionResource.java b/src/org/traccar/api/resource/SessionResource.java index fc0741f8c..347beb9a3 100644 --- a/src/org/traccar/api/resource/SessionResource.java +++ b/src/org/traccar/api/resource/SessionResource.java @@ -21,10 +21,12 @@ import org.traccar.model.User; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; @@ -70,4 +72,10 @@ public class SessionResource extends BaseResource { } } + @DELETE + public Response remove() { + req.getSession().removeAttribute(USER_ID_KEY); + return Response.noContent().build(); + } + } diff --git a/web/app/Application.js b/web/app/Application.js index 34d65d13a..5cc192686 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -79,7 +79,9 @@ Ext.define('Traccar.Application', { }, showError: function (response) { - if (response.statusText) { + if (Ext.isString(response)) { + Ext.Msg.alert(Strings.errorTitle, response); + } else if (response.statusText) { Ext.Msg.alert(Strings.errorTitle, response.statusText); } else { Ext.Msg.alert(Strings.errorTitle, Strings.errorConnection); diff --git a/web/app/view/LoginController.js b/web/app/view/LoginController.js index 0b2090ffb..0ac8408fa 100644 --- a/web/app/view/LoginController.js +++ b/web/app/view/LoginController.js @@ -34,19 +34,16 @@ Ext.define('Traccar.view.LoginController', { Ext.getBody().mask(Strings.sharedLoading); Ext.Ajax.request({ scope: this, - url: '/api/login', + method: 'POST', + url: '/api/rest/session', params: form.getValues(), callback: function (options, success, response) { - var result; Ext.getBody().unmask(); - if (Traccar.ErrorManager.check(success, response)) { - result = Ext.decode(response.responseText); - if (result.success) { - Traccar.app.setUser(result.data); - this.fireViewEvent('login'); - } else { - Traccar.ErrorManager.error(Strings.loginFailed); - } + if (success) { + Traccar.app.setUser(Ext.decode(response.responseText)); + this.fireViewEvent('login'); + } else { + Traccar.app.showError(Strings.loginFailed); } } }); @@ -56,7 +53,8 @@ Ext.define('Traccar.view.LoginController', { logout: function () { Ext.Ajax.request({ scope: this, - url: '/api/logout', + method: 'DELETE', + url: '/api/rest/session', callback: function () { window.location.reload(); } |