Skip to content Skip to sidebar Skip to footer

How To Store Login Credentials In Localstorage

If got a sencha touch application, with a login form. For returning users, I would like to store the login credentials in the local storage. User.js App.models.User = Ext.regModel(

Solution 1:

First make sure your saving the models right. For example do this:

var model = new App.models.User();
    model.data.username = 'theUser';
    model.data.password = 'thePass';
    model.save(); //the actual saving. Use chrome developer tools to see the local storage

Then load the model from the localstorage

users = App.stores.users.load();model = users.getAt(0);

Check if the loaded model is OK and load that to the form with load(model)

The form could be like this:

new Ext.Application({
launch: function() {
    new Ext.form.FormPanel({
            id:'theForm',
            fullscreen: true,
            defaults: {
                labelAlign: 'top',
                labelWidth: 'auto',
            },
            items: [
                {
                    id : 'userName',
                    name : 'username',
                    label: 'Email',
                    xtype: 'emailfield',
                },
                {
                    id : 'userPassword',
                    name: 'password',
                    label: 'Password',
                    xtype: 'passwordfield',
                }
             ]
        });
     }
});

Then load the record like this Ext.getCmp('theForm').load(users.getAt(0));

To get the model from the form: Ext.getCmp('theForm').getRecord();

Solution 2:

From a cursory look, it looks like a possible way to do it.

But, you should create model instances from the model manager, for instance:

Ext.ModelMgr.create({username: 'foo', password: 'bar'}, 'User');

Post a Comment for "How To Store Login Credentials In Localstorage"