Results 1 to 9 of 9

Thread: How to save your login and password in the local memory

  1. #1
    Sencha User
    Join Date
    Oct 2013
    Location
    Minsk
    Posts
    43
    Vote Rating
    0
      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
      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
    39,339
    Vote Rating
    1297
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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
      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
      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 Premium User wemerson.januario's Avatar
    Join Date
    Nov 2008
    Location
    Goinia - GO, Brazil
    Posts
    635
    Vote Rating
    49
      0  

    Default

    auto login example please?
    Wemerson Januario
    Site/Blog: http://wemersonjanuario.com.brFrom: Goinia, GO, Brazil
    Consulting Training and Web Development

  7. #7
    Sencha Premium User Iveco's Avatar
    Join Date
    Aug 2007
    Location
    Germany
    Posts
    106
    Vote Rating
    24
      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
    454
    Vote Rating
    22
      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
      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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •