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

サーバー側で認証する必要があることは明らかです。すでに 1 つ持っていると仮定すると、残りはそれほど難しくありません。

最も簡単な方法は、送信するだけ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 に答える