1

我有一个带有用于用户身份验证的设计 gem 的 Rails 应用程序。

在 Titanium 应用程序上对用户进行身份验证的最佳方式是什么?我希望用户在 Titanium 应用程序上输入他的凭据,然后 rails 应用程序使用设计检查登录名/密码。

应用程序之间的通信是通过 REST 接口完成的,我使用自定义 HTTP 标头来传输凭据。

4

1 回答 1

0

假设您有一个这样的视图,它接受用户名和密码:

<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>

一旦用户输入输入并点击登录按钮,您就会发送一个 http 请求。这是一个很好的细节指南,但它的功能类似于大多数HTTPClient 包装器。

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();
于 2013-07-04T13:08:20.413 回答