gpt4 book ai didi

iphone - 创建 iPhone 应用程序 + Rails 应用程序 + Devise 身份验证

转载 作者:行者123 更新时间:2023-12-03 19:24:21 29 4
gpt4 key购买 nike

我目前有一个使用 Devise 的 Rails 应用程序,并且可以通过浏览器登录。我现在想要创建一个使用这个 Rails 应用程序作为后端的 native iPhone 应用程序。我想要什么:

  • 当用户首次打开 iOS 应用时,他们会看到登录屏幕。
  • 他们输入信息,应用程序尝试登录他们。如果成功,它会列出 Rails 应用程序的用户(目前)。否则提示登录错误。
  • 然后,用户可以点击用户的姓名,然后就会显示用户的个人资料等。应用需要能够执行所有 CRUD 操作,就像在网站本身上一样。

现在我正在为 iPhone 应用程序使用 Devise 和 RestKit。我在 Rails 应用程序中启用了 http_auth,并且可以设置用户名/密码并从我的/users 页面获取响应(以 JSON 形式列出我的用户)。

rails :

class UsersController < ApplicationController

before_filter :authenticate_user!

def index
@users = User.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @users }
end
end

end

iPhone(使用 Restkit):

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
RKClient *client = [RKClient clientWithBaseURL:@"http://192.168.1.105:3000" username:@"xxxx" password:@"xxxx"];

[[RKClient sharedClient] get:@"/users.json" delegate:self];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)request:(RKRequest*)request didFailLoadWithError:(NSError *)error {
NSLog(@"error");
}

- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
NSLog(response.bodyAsString);
}

我不知道从这里开始做什么或如何处理它。

  1. 如何处理登录屏幕?好的,我可以做一个'http://localhost:3000' 使用 http 基本身份验证 GET 并获取用户列出回来,但这就是我应该如何测试用户的凭据输入正确吗?有什么方法可以让你得到“OK”或“NOT”确定返回登录信息吗?
  2. 最好的互动方式是什么使用 Rails 应用程序?可以使用 GET/users/2 进行类似的操作吗休息套件?或者我需要构建某种 api 吗?我不知道在哪里从这样的事情开始。

最佳答案

如果你有设计,为什么还要使用基本的 http 身份验证?使用 devise,您可以在 json 哈希中返回身份验证错误,并将其显示在登录屏幕上。

以经典的 REST 方式构建您的应用程序,对于 Web 客户端和移动客户端来说都非常舒适。

您还可以尝试使用 Rabl https://github.com/nesquena/rabl 之类的内容用于在 Rails 应用程序中构建智能 JSON API。

关于iphone - 创建 iPhone 应用程序 + Rails 应用程序 + Devise 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12772614/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com