From 5b526f60f29b222a3269547ac938ab512d1ba4d6 Mon Sep 17 00:00:00 2001 From: ninioe Date: Mon, 1 Aug 2016 17:29:54 +0300 Subject: added remember me checkbox at login --- web/app/view/Login.js | 6 ++++++ web/app/view/LoginController.js | 13 +++++++++++++ 2 files changed, 19 insertions(+) (limited to 'web/app/view') diff --git a/web/app/view/Login.js b/web/app/view/Login.js index 4f04a0f37..085f853be 100644 --- a/web/app/view/Login.js +++ b/web/app/view/Login.js @@ -54,6 +54,7 @@ Ext.define('Traccar.view.Login', { }, { xtype: 'textfield', name: 'email', + id: 'txtUser', fieldLabel: Strings.userEmail, allowBlank: false, enableKeyEvents: true, @@ -65,6 +66,7 @@ Ext.define('Traccar.view.Login', { }, { xtype: 'textfield', name: 'password', + id: 'txtPassword', fieldLabel: Strings.userPassword, inputType: 'password', allowBlank: false, @@ -73,6 +75,10 @@ Ext.define('Traccar.view.Login', { specialKey: 'onSpecialKey' }, inputAttrTpl: ['autocomplete="on"'] + }, { + xtype: 'checkboxfield', + id: 'chkRememberMe', + fieldLabel: Strings.rememberMe }, { xtype: 'component', html: '' diff --git a/web/app/view/LoginController.js b/web/app/view/LoginController.js index 3dd8af082..3b4fc8754 100644 --- a/web/app/view/LoginController.js +++ b/web/app/view/LoginController.js @@ -26,6 +26,13 @@ Ext.define('Traccar.view.LoginController', { this.lookupReference('registerButton').setDisabled( !Traccar.app.getServer().get('registration')); this.lookupReference('languageField').setValue(Locale.language); + var user = Ext.util.Cookies.get('user'); + var pass = Ext.util.Cookies.get('pass'); + if (user && pass) { + Ext.getCmp('txtUser').setValue(user); + Ext.getCmp('txtPassword').setValue(pass); + this.login(); + } }, login: function () { @@ -40,6 +47,10 @@ Ext.define('Traccar.view.LoginController', { callback: function (options, success, response) { Ext.getBody().unmask(); if (success) { + if (Ext.getCmp('chkRememberMe').getValue()) { + Ext.util.Cookies.set('user', Ext.getCmp('txtUser').getValue(), Ext.Date.add(new Date(), Ext.Date.YEAR, 1)); + Ext.util.Cookies.set('pass', Ext.getCmp('txtPassword').getValue(), Ext.Date.add(new Date(), Ext.Date.YEAR, 1)); + } Traccar.app.setUser(Ext.decode(response.responseText)); this.fireViewEvent('login'); } else { @@ -51,6 +62,8 @@ Ext.define('Traccar.view.LoginController', { }, logout: function () { + Ext.util.Cookies.clear('user'); + Ext.util.Cookies.clear('pass'); Ext.Ajax.request({ scope: this, method: 'DELETE', -- cgit v1.2.3