From c6d8d7646a06e2624a0dac48b93fd5b1dd0db146 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 18 Nov 2016 16:06:02 +0500 Subject: Implement users tokens --- web/app/controller/Root.js | 5 ++++- web/app/model/User.js | 3 +++ web/app/view/UserDialog.js | 12 ++++++++++++ web/app/view/UserDialogController.js | 14 ++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) (limited to 'web/app') diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index 568b761d..b0067c01 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -34,11 +34,14 @@ Ext.define('Traccar.controller.Root', { }, onServerReturn: function (options, success, response) { + var tokenParameter; if (success) { Traccar.app.setServer(Ext.decode(response.responseText)); + tokenParameter = window.location.search.match('/token=([a-zA-Z0-9]+)/'); + tokenParameter = tokenParameter !== null ? '?' + tokenParameter[0] : ''; Ext.Ajax.request({ scope: this, - url: 'api/session', + url: 'api/session' + tokenParameter, callback: this.onSessionReturn }); } else { diff --git a/web/app/model/User.js b/web/app/model/User.js index 48912417..6df6afc0 100644 --- a/web/app/model/User.js +++ b/web/app/model/User.js @@ -71,6 +71,9 @@ Ext.define('Traccar.model.User', { }, { name: 'deviceLimit', type: 'int' + }, { + name: 'token', + type: 'string' }, { name: 'attributes' }], diff --git a/web/app/view/UserDialog.js b/web/app/view/UserDialog.js index a54a20c6..52ec933c 100644 --- a/web/app/view/UserDialog.js +++ b/web/app/view/UserDialog.js @@ -130,6 +130,18 @@ Ext.define('Traccar.view.UserDialog', { fieldLabel: Strings.userDeviceLimit, disabled: true, reference: 'deviceLimitField' + }, { + xtype: 'textfield', + name: 'token', + reference: 'tokenField', + fieldLabel: Strings.userToken, + disabled: true, + triggers: { + generate: { + cls: 'iconCls: x-fa fa-refresh', + handler: 'generateToken' + } + } }] }, diff --git a/web/app/view/UserDialogController.js b/web/app/view/UserDialogController.js index cd0a9512..e2e822e7 100644 --- a/web/app/view/UserDialogController.js +++ b/web/app/view/UserDialogController.js @@ -26,9 +26,23 @@ Ext.define('Traccar.view.UserDialogController', { this.lookupReference('disabledField').setHidden(false); this.lookupReference('expirationTimeField').setDisabled(false); this.lookupReference('deviceLimitField').setDisabled(false); + this.lookupReference('tokenField').setDisabled(false); } }, + symbols: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', + + generateToken: function () { + var newToken, i; + newToken = ''; + + for (i = 0; i < 16; i++) { + newToken += this.symbols.charAt(Math.floor(Math.random() * this.symbols.length)); + } + + this.lookupReference('tokenField').setValue(newToken); + }, + onSaveClick: function (button) { var dialog, record, store; dialog = button.up('window').down('form'); -- cgit v1.2.3 From ef58095c5f841863c271c9f0995a20ac5215fe58 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 18 Nov 2016 17:10:47 +0500 Subject: Fix passing parameter and declaration --- web/app/view/UserDialogController.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'web/app') diff --git a/web/app/view/UserDialogController.js b/web/app/view/UserDialogController.js index e2e822e7..020bd801 100644 --- a/web/app/view/UserDialogController.js +++ b/web/app/view/UserDialogController.js @@ -33,8 +33,7 @@ Ext.define('Traccar.view.UserDialogController', { symbols: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', generateToken: function () { - var newToken, i; - newToken = ''; + var i, newToken = ''; for (i = 0; i < 16; i++) { newToken += this.symbols.charAt(Math.floor(Math.random() * this.symbols.length)); -- cgit v1.2.3 From 38d94e65e9bb46cc10cbe7559daa41d1468ba853 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 18 Nov 2016 17:12:14 +0500 Subject: Fix passing parameter and variable declaration --- web/app/controller/Root.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'web/app') diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index b0067c01..adc188c0 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -37,11 +37,14 @@ Ext.define('Traccar.controller.Root', { var tokenParameter; if (success) { Traccar.app.setServer(Ext.decode(response.responseText)); - tokenParameter = window.location.search.match('/token=([a-zA-Z0-9]+)/'); - tokenParameter = tokenParameter !== null ? '?' + tokenParameter[0] : ''; + tokenParameter = window.location.search.match('token=([a-zA-Z0-9]+)'); Ext.Ajax.request({ scope: this, - url: 'api/session' + tokenParameter, + url: 'api/session', + method: 'GET', + params: tokenParameter !== null ? { + token: tokenParameter[1] + } : {}, callback: this.onSessionReturn }); } else { -- cgit v1.2.3 From be60c87c9b5333e847c85d109484c431d5651562 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 18 Nov 2016 18:11:04 +0500 Subject: Cleanup token parsing --- web/app/controller/Root.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'web/app') diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index adc188c0..e30446c9 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -34,17 +34,18 @@ Ext.define('Traccar.controller.Root', { }, onServerReturn: function (options, success, response) { - var tokenParameter; + var token, parameters = {}; if (success) { Traccar.app.setServer(Ext.decode(response.responseText)); - tokenParameter = window.location.search.match('token=([a-zA-Z0-9]+)'); + token = Ext.Object.fromQueryString(window.location.search).token; + if (token) { + parameters.token = token; + } Ext.Ajax.request({ scope: this, url: 'api/session', method: 'GET', - params: tokenParameter !== null ? { - token: tokenParameter[1] - } : {}, + params: parameters, callback: this.onSessionReturn }); } else { -- cgit v1.2.3