2013-07-03 46 views
1

我有一個用於用戶驗證的設計gem的Rails應用程序。如何驗證Titanium客戶端

在Titanium應用上驗證用戶的最佳方式是什麼?我希望用戶在Titanium應用程序中輸入他的憑據,然後Rails應用程序會使用設計檢查登錄名/密碼。

應用程序之間的通信是通過REST接口完成的,我使用自定義HTTP標頭來傳輸證書。

+1

您需要提供自定義HTTP頭信息。 –

回答

0

說你已經制定了這樣的觀點,接受用戶名和密碼:一旦用戶進入輸入和打你發送HTTP請求的登錄按鈕

<Alloy> 
    <View layout="vertical" height="Ti.UI.SIZE" width="80%" top="25%"> 
     <TextField id="username" height="40dp" width="60%"/> 
     <TextField id="pwd" height="40dp" width="60%"/> 
     <Button id="loginBtn" width="80%"/> 
    </View> 
</Alloy> 

。這裏是一個很好的guide on the ins and outs,但它的功能類似於大多數HTTPClient wrappers.

var xhr = Titanium.Network.createHTTPClient({ 
    timeout : 2000, 
    onload : function() { 
     // Successful return, do something with it 
     var retval = this.responseText; 
    }, 
    onerror : function() { 
     Ti.API.error(this.responseText); 
    } 

}); 
xhr.open('POST',"http://your-web-service"); 

// Set headers here, _after_ opening 
var userinfo = {username : $.username.value, pwd : $.pwd.value}; 
xhr.setRequestHeader("Authorization_Custom_Header", "Assemble your header here or use OAuth"); 
xhr.send(); 
+0

這可以工作,但它沒有通過標題中的憑據,這是他在原始問題 –

+0

錯過了那部分,更新我的答案反映了他給的信息。 –