1

我正在尝试使用 Sencha Touch 2 构建一个多登录系统,用户是否必须选择他是代理还是追随者。到目前为止,我已经能够想出一个简单的登录表单。没有功能。我的代码是这样的:

Ext.define("ikhlas.view.login", {
extend: 'Ext.Panel',
xtype: 'loginpanel',

    config:{
        title: 'Login',
        iconCls: 'more',
        styleHtmlContent: true,

    layout:{
        type: 'vbox',

        },

    items: [
        {
       xtype: 'fieldset',
       iconCls: 'add',

    items: [

        {
            xtype: 'emailfield',
            name: 'email',
            placeHolder: 'Username'
        },

        {
            xtype: 'passwordfield',
            name: 'password',
            placeHolder: 'Password'
        },

        {
            xtype: 'selectfield',
            label: 'User Type',
            options: [
            {text: 'Agent',  value: '0'},
            {text: 'Follower', value: '1'}
            ]
        }

   ]},
        {
            xtype: 'button',
            text: 'LogIn',
            ui: 'confirm',
            width: '40%',
            height: '7%',
            flex: 1,
            left: '55%',
            action: 'submitContact'
        },
        {
            xtype: 'button',
            text: 'Forgot Username',
            ui: 'confirm',
            width: '41%',
            height: '4%',
            top: '90%',
            flex: 1,
            action: 'ForgotUsername'   
        },
        {
            xtype: 'button',
            text: 'Forgot Password',
            ui: 'confirm',
            width: '40%',
            height: '4%',
            top: '90%',
            flex: 1,
            left: '47%',
            action: 'ForgotPassword'  
        },
    ]}
});

现在我想知道如何从 API 验证用户信息(用户名和密码)(将给出一个 url),以便在允许他们访问应用程序之前确认登录用户名和密码是正确的。其次,如果用户名或密码不正确,我想抛出一条错误消息。

4

1 回答 1

0

很明显,您必须在服务器端进行身份验证。假设你已经拥有了一个,那么剩下的不是很困难。

最简单的方法就是发送一个Ext.Ajax.request

Ext.Ajax.request({
        url: your_API_url,
        params: {
                       username: your_username_from_formpanel, 
                       password: your_password_from_formpanel
                    },
        timeout: 10000, // time out for your request

        success: function(result) {
                      // here, base on your response, provide suitable messages
                      // and further processes for your users
        },

        failure: function(){
            Ext.Msg.alert("Could not connect to server.");
        }   
    });

注意:出于安全原因,您应该在将用户密码发送到服务器之前对其进行加密。

于 2012-05-22T18:28:20.957 回答