diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-09-17 16:57:31 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-09-17 16:57:31 +1200 |
commit | 8baf73493d24c85bc5d13069044fc1150ed62c2e (patch) | |
tree | ce421f9431ac3e13e91817bfd989bcd272034649 /web/app/view/login | |
parent | 4154c2cd31f23c5d5fb336dfcd68ba192b297f93 (diff) | |
download | trackermap-server-8baf73493d24c85bc5d13069044fc1150ed62c2e.tar.gz trackermap-server-8baf73493d24c85bc5d13069044fc1150ed62c2e.tar.bz2 trackermap-server-8baf73493d24c85bc5d13069044fc1150ed62c2e.zip |
Move login calls to controller
Diffstat (limited to 'web/app/view/login')
-rw-r--r-- | web/app/view/login/LoginController.js | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/web/app/view/login/LoginController.js b/web/app/view/login/LoginController.js index 48a4aa0f7..0344f5542 100644 --- a/web/app/view/login/LoginController.js +++ b/web/app/view/login/LoginController.js @@ -24,10 +24,43 @@ Ext.define('Traccar.view.login.LoginController', { init: function() { this.lookupReference('registerButton').setDisabled( - !Traccar.app.getServer().get('registration') - ); + !Traccar.app.getServer().get('registration')); this.lookupReference('languageField').setValue(language); + }, + login: function() { + var form = this.lookupReference('form'); + if (form.isValid()) { + Ext.getBody().mask(strings.sharedLoading); + Ext.Ajax.request({ + scope: this, + url: '/api/login', + params: form.getValues(), + callback: function(options, success, response) { + Ext.getBody().unmask(); + if (Traccar.ErrorManager.check(success, response)) { + var result = Ext.decode(response.responseText); + if (result.success) { + Traccar.app.setUser(result.data); + this.fireViewEvent('login'); + } else { + Traccar.ErrorManager.error(strings.loginFailed); + } + } + + } + }); + } + }, + + logout: function() { + Ext.Ajax.request({ + scope: this, + url: '/api/logout', + callback: function() { + window.location.reload(); + } + }); }, onSelectLanguage: function(selected) { @@ -56,37 +89,15 @@ Ext.define('Traccar.view.login.LoginController', { onSpecialKey: function(field, e) { if (e.getKey() === e.ENTER) { - this.doLogin(); + this.login(); } }, onLoginClick: function() { Ext.getElementById('submitButton').click(); - this.doLogin(); + this.login(); }, - - doLogin: function() { - var form = this.lookupReference('form'); - if (form.isValid()) { - Ext.getBody().mask(strings.sharedLoading); - - Traccar.LoginManager.login({ - data: form.getValues(), - scope: this, - callback: 'onLoginReturn' - }); - } - }, - - onLoginReturn: function(success) { - Ext.getBody().unmask(); - if (success) { - this.fireViewEvent('login'); - } else { - Traccar.ErrorManager.error(strings.loginFailed); - } - }, - + onRegisterClick: function() { Ext.create('Traccar.view.login.Register').show(); } |