1

ユーザー認証用のdevise 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 に答える