2012-05-22 63 views
1

我想建立一個多日誌系統使用Sencha觸摸2,用戶必須選擇,如果他是代理或追隨者。到目前爲止,我已經能夠想出一個簡單的登錄形式。沒有功能。我的代碼僅僅是這樣的:建設Sencha觸摸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(網址將被給予)驗證用戶信息(用戶名和密碼),以確認登錄的用戶名和密碼是正確的,才能被允許訪問應用程序。其次,如果用戶名或密碼不正確,我想拋出一條錯誤消息。

+0

你打算使用哪種服務器端語言? – fuzzyLikeSheep

回答

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."); 
     } 
    }); 

注:出於安全原因,你應該把它發送給服務器之前加密你的用戶的密碼。

+0

嗨Thiem阮,感謝您的迴應,此刻我不認證我的服務器端,是否有可能可以幫助我一個PHP腳本的身份驗證。其次,我如何加密密碼?用一些腳本幫助我。如果可能的話,我需要一個可以處理SQL注入的腳本,以便讓應用程序無法破解或降低整個應用程序的安全性。非常感謝。我的數據庫名稱是:ikhlas,表格將是ikalas_logs –