chnselim
chnselim

Reputation: 254

ExtJS 5.1 Remember Me on local store

I'm trying to do Remember Me with an interesting algorithm. I was thinking, when i click the Remember Me and Login, the value of the text fields (username&password) will be saved as a default value. My login button click event here:

    var username = Ext.getCmp('setNo').getValue();
    var password= Ext.getCmp('setPass').getValue();

    if(refs.checkStudent.value === true){
        Ext.getCmp('setNo').setValue(username);
        Ext.getCmp('setPass').setValue(password);
    }
    else{
        Ext.getCmp('setNo').setValue("");
        Ext.getCmp('setParola').setValue("");
    }

On console, it is working. But I'm working with a local store, no server. So when i refresh the page, it's gone. Is there a way to not lose them?

Upvotes: 1

Views: 139

Answers (2)

Arvin
Arvin

Reputation: 1506

on your view onAfterRender event:

Ext.getCmp('setNo').setValue(localStorage.username);
Ext.getCmp('setPass').setValue(localStorage.password);

on your button click event:

if (refs.checkStudent.value === true) {
    localStorage.username = Ext.getCmp('setNo').getValue();
    localStorage.password = Ext.getCmp('setPass').getValue();
} else {
    localStorage.removeItem('username');
    localStorage.removeItem('password');
}

Upvotes: 1

Balram Maurya
Balram Maurya

Reputation: 164

Use ExtJs utility to set and get values in cookies. At time of login set 
username and password in cookies and after refresh the page read username
and password value from the cookie. 

Ext.util.Cookies.set('username', username); // To set value in cookie.
Ext.util.Cookies.get('username'); // to get value form cookie.

Upvotes: 1

Related Questions