1. #1
    Sencha User
    Join Date
    Oct 2013
    Location
    Minsk
    Posts
    43
    Vote Rating
    0
    samaelal is on a distinguished road

      0  

    Default How to save your login and password in the local memory

    Prompt! How to keep the local store username and password. There's this code:


    Code:
    Ext.define("MM.view.LoginView", {			extend : 'Ext.form.Panel',
    			xtype : 'loginForm',
    			id : 'loginForm',
    			requires : ['Ext.form.FieldSet', 'Ext.field.Password',
    					'Ext.field.Toggle'],
    			config : {
    				title : 'Log in',
    				iconCls : 'user',
    				items : [{
    							xtype : 'fieldset',
    							title : 'Авторизация',
    							items : [{
    										xtype : 'textfield',
    										label : 'Пользователь',
    										labelWidth : '40%',
    										id : 'userField',
    										hideAnimation : 'fadeOut',
    										showAnimation : 'fadeIn',
    										required : true,
    										labelAlign : 'top',
    										value : '',
    										name : 'user'
    									}, {
    										xtype : 'passwordfield',
    										label : 'Пароль',
    										labelWidth : '40%',
    										hideAnimation : 'fadeOut',
    										showAnimation : 'fadeIn',
    										id : 'passField',
    										required : true,
    										labelAlign : 'top',
    										value : '',
    										name : 'pass'
    									}, {
    										xtype : 'togglefield',
    										label : 'Запомнить пароль?',
    										labelWidth : '60%',
    										id : 'togEss',
    										name : 'spass',
    										value : false,
                                    handler: function()
                                    {
    
    
                                    }
    									}]
    						}, {
    							xtype : 'toolbar',
    							height : 70,
    							docked : 'bottom',
    							layout : {
    								pack : 'left',
    								type : 'hbox'
    							},
    							defaults : {
    								ui : 'plain'
    							},
    							items : [{
    										xtype : 'button',
    										ui : 'action',
    										height : 50,
    										width : 100,
    										id : 'doLogout',
    										flex : 1,
    										text : 'Закрыть'
    									}, {
    										xtype : 'button',
    										ui : 'action',
    										height : 50,
    										width : 100,
    										id : 'doLogon',
    										flex : 1,
    										text : 'Войти'
    									}
    
    
    							]
    						}]
    			},
                initialize : function(record) {
    
    
                }
    		});

    Code:
    Ext.define('MM.store.CurrentUser', {	extend: 'Ext.data.Store',
    	
    	config: {
    		model: 'MM.model.CurrentUser',
    		autoLoad: false
    	}
    });

    Code:
    Ext.define('MM.model.CurrentUser', {	extend: 'Ext.data.Model',
    	config: {
    		fields: [
    			{name: 'name', type: 'string'},
                {name: 'pass', type : 'string'},
                {name: 'spass', type : 'string'}
    		],
    
    
    		proxy: {
    			type: 'localstorage',
    			id: 'simple-login-data'
    		}
    	}
    });

    Advance very grateful for any help

  2. #2
    Sencha User armode's Avatar
    Join Date
    Nov 2011
    Location
    Germany / Darmstadt
    Posts
    64
    Vote Rating
    4
    armode is on a distinguished road

      1  

    Default

    You've just to add the credentials to the store and sync the store after that.
    Have a look into the docs: http://docs.sencha.com/touch/2.3.1/#...y.LocalStorage

    But I think it's not a good idea to save the password in an unsafe place like the local storage. You could use a cookie or maybe save it to the iOS keychain if you package your app with phonegap/cordova.

    Maybe someone else can say what's the best practice to implement an autologin feature?

  3. #3
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    38,582
    Vote Rating
    1136
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default

    I would agree this is a bad idea. Instead you need to save a token that you can then map to a session on the back end.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #4
    Sencha User
    Join Date
    Oct 2013
    Location
    Minsk
    Posts
    43
    Vote Rating
    0
    samaelal is on a distinguished road

      0  

    Default

    ok! thank you .... and if you can you give an example

  5. #5
    Sencha Premium Member
    Join Date
    Oct 2013
    Posts
    45
    Vote Rating
    4
    mattkim is on a distinguished road

      0  

    Default

    Quote Originally Posted by mitchellsimoens View Post
    I would agree this is a bad idea. Instead you need to save a token that you can then map to a session on the back end.
    Is there any example of this? What is the best way of sending back a token on every request?

  6. #6
    Sencha User wemerson.januario's Avatar
    Join Date
    Nov 2008
    Location
    Brazil, Goiânia
    Posts
    558
    Vote Rating
    27
    wemerson.januario has a spectacular aura about wemerson.januario has a spectacular aura about

      0  

    Default

    auto login example please?
    Wemerson Januario
    Blog: http://wemersonjanuario.com.br
    Twitter: @januariocoder
    From: Goiânia, GO, Brazil
    Ext JS developer and consulting

  7. #7
    Sencha Premium Member Iveco's Avatar
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    107
    Vote Rating
    23
    Iveco will become famous soon enough Iveco will become famous soon enough

      0  

    Default

    +1, would like to see an auto-login example too.
    Would be great to see one for android and one for iOS.
    Also one which is safe to use and enforces current best-practices for secure communication and storage of cookie/session-data.
    Can understand if no code is being posted, at least give some technical hints what techniques to use.

    Good example but no auto-login: http://miamicoder.com/2012/adding-a-...h-application/
    German EXT-User and -Lover :-).

  8. #8
    Sencha User
    Join Date
    Aug 2011
    Location
    London
    Posts
    458
    Vote Rating
    22
    digeridoo will become famous soon enough digeridoo will become famous soon enough

      0  

    Default Joshua Morony's one...

    If you go on Josh Morony's blog and you buy his tutorial 'How to build a sencha touch login system' it does exactly what you are after....including sync to local storage check so you can login instantly if the session cookie is already there. Facebook login is also included

    It doesn't save the password locally for obvious security reasons...

    :-)

  9. #9
    Sencha User
    Join Date
    Oct 2013
    Posts
    10
    Vote Rating
    0
    reallyjosh is on a distinguished road

      0  

    Default Tutorial

    Using a paid tutorial isn't idea for all, so I thought I'd take a moment to explain this. You need to use local storage to store a session token using a store and a model. You then need to check that token in your app launch function and if it's valid move through the apps interface to the "already logged in" view, otherwise you would want to lead the user to a log in or register view. Everyone here always says an explanation is no good without an example, so I will post an example of how I'm doing it below in one of my apps. I'm no expert, and there may be better ways to do it, but I'll show you how I'm getting the job done. First, my application is using Parse.com rest api to authenticate users and then it stores their username in a local store. When users log out it deletes the username from the store, so my method of checking for stored login is just to check if the store has a count of greater than 0 on app launch. Here's the code:

    My launch function in app.js is left untouched.

    Code:
    launch: function() {        // Destroy the #appLoadingIndicator element
            Ext.fly('appLoadingIndicator').destroy();
    
    
            // Initialize the main view
            Ext.Viewport.add(Ext.create('AppName.view.MainView'));
            
    
    
        }
    I have a launch function in my controller like this.

    Code:
    launch: function() {        this.callParent(arguments);
            mainView = this.getMainView(), // Main view
                loginPanel = this.getLoginPanel(), // Login and register buttons
                welcomePanel = this.getWelcomePanel(); // Welcome panel
            var me = this;
    
    
            var myStore = Ext.getStore('loginstore');
            myStore.load({
                callback: function(records) {}
            });
            //console.log(myStore.getCount()); 
            if (myStore.getCount() > 0) {
                var store = Ext.getStore('notesstore');
                var proxy = store.getProxy();
                var user = Ext.getStore('loginstore').getAt(0).get('username');
                proxy.setExtraParams({
                    'where': '{"createdBy":"' + user + '"}'
                });
                store.load();
                mainView.pop();
                loginPanel.hide();
                welcomePanel.show();
            } //end of if
            else {
                mainView.pop();
                // Hide login panel
                loginPanel.show();
                // Show welcome panel
                //welcomePanel.hide();
            }//end of else
        }//end of launch function