From 8b68510d0f8c1baaad44d8b4011b92cf5efe76d9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 1 Jun 2015 11:30:44 +1200 Subject: Store current user model --- web/app/Application.js | 11 ++++++++++- web/app/LoginManager.js | 12 ++++++++++-- web/app/model/User.js | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'web/app') diff --git a/web/app/Application.js b/web/app/Application.js index e17be1a15..62dedf22b 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -37,5 +37,14 @@ Ext.define('Traccar.Application', { controllers: [ 'Root' - ] + ], + + setUser: function(user) { + this.user = user; + }, + + getUser: function() { + return this.user; + } + }); diff --git a/web/app/LoginManager.js b/web/app/LoginManager.js index 89df7684f..914b7d6a9 100644 --- a/web/app/LoginManager.js +++ b/web/app/LoginManager.js @@ -16,6 +16,14 @@ Ext.define('Traccar.LoginManager', { singleton: true, + + setUser: function(data) { + var reader = Ext.create('Ext.data.reader.Json', { + model: 'Traccar.model.User' + }); + Traccar.getApplication().setUser( + reader.readRecords(data).getRecords()[0]); + }, session: function(options) { Ext.Ajax.request({ @@ -31,7 +39,7 @@ Ext.define('Traccar.LoginManager', { if (Traccar.ErrorManager.check(success, response)) { var result = Ext.decode(response.responseText); if (result.success) { - this.user = result.data; + this.setUser(result.data); } Ext.callback(options.callback, options.scope, [result.success]); } @@ -52,7 +60,7 @@ Ext.define('Traccar.LoginManager', { if (Traccar.ErrorManager.check(success, response)) { var result = Ext.decode(response.responseText); if (result.success) { - this.user = result.data; + this.setUser(result.data); } Ext.callback(options.callback, options.scope, [result.success]); } diff --git a/web/app/model/User.js b/web/app/model/User.js index 68f7cafb4..04e3e25b5 100644 --- a/web/app/model/User.js +++ b/web/app/model/User.js @@ -21,7 +21,7 @@ Ext.define('Traccar.model.User', { fields: [ { name: 'id', type: 'int' }, { name: 'name', type: 'string' }, - { name: 'unqiueId', type: 'string' }, + { name: 'email', type: 'string' }, { name: 'password', type: 'string' }, { name: 'admin', type: 'boolean' } ] -- cgit v1.2.3