0
votes

I have a rest api and for user authentication, the rest url is: https://api.abc.com/user/{username}/{password}. So I need to set two parameters for the rest proxy. Can any one please help me?

Here is my User model:

Ext.define('NCAPP.model.User', {
extend:'Ext.data.Model',

config:{
    fields:[
        { name:'id', type: 'int'},           
        { name: 'username', type: 'string'},
        { name: 'netshop_id', type:'int'},
        { name: 'firstname', type: 'string'},
        { name: 'lastname', type: 'string'},
        { name: 'address', type: 'string'},
         { name:'password', type:'string'},

    ],

    proxy: {
        type:'rest',
        url:https://api.abc.com/user/',
        noCache: false,           
        reader: {
            type:'json',
            rootProperty:'user'
        }            

    }

}

});

And here is my LoginController on loginbuttion tap function:

 onLoginButtonTap:function(){

    var values=this.getLoginForm().getValues(); 

    Ext.ModelMgr.getModel('NCAPP.model.User').load(values.username,{
        success:  function(user){
            if(user==null)
                {
                    Ext.Msg.alert('NCAPP',"Invalid username or password!");
                }
                else
                {
                    Ext.Msg.alert('NCAPP','Welcome! '+user.get('username'));
                    //do after login implementation
                }

        },
        failure: function(user){
            console.log("Uff, Something went worng!");
        }
    });    
},

In the following line, i want to pass user name and password: Ext.ModelMgr.getModel('NCAPP.model.User').load(values.username, values.password, {.....

Can anyone help me achieving this goal?

1

1 Answers

0
votes

You can use the method "setProxy" to add dynamically a proxy to your model/Store.

var values = this.getLoginForm().getValues();
YOURMODEL.setProxy({
    proxy: {
        type: 'rest',
        url: 'https://api.abc.com/user/'+ values.username +'/'+ values.password,
        noCache: false,           
        reader: {
            type: 'json',
            rootProperty: 'user'
        }            

    }
});