gpt4 book ai didi

ios - 通过原生 iOS 应用使用 Devise 创建用户帐户

转载 作者:行者123 更新时间:2023-12-01 17:32:44 26 4
gpt4 key购买 nike

我有一个使用 Devise 的原生 Rails 应用程序用于身份验证(使用 token_authenticatable 模块)。使用现有帐户,一旦获得 token ,我就可以使用 JSON 在我的 native iOS 应用程序中成功执行 API 调用。

我想将功能添加到 创建一个新帐户通过 iOS 应用程序,无需使用浏览器。 Devise 是否只允许通过 HTML 创建帐户?

我看过这个帖子
Rails/Devise - Creating new users via json request

并通过 CURL 尝试了各种方法,包括:

$ curl -H "Content-Type: application/json" -d '{"email":"who@me.com","password":"mypass"}' -vX POST http://localhost:5000/users.json
...
* Connected to localhost (127.0.0.1) port 5000 (#0)
> POST /users.json HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:5000
> Accept: */*
> Content-Type: application/json
> Content-Length: 44
>
* upload completely sent off: 44 out of 44 bytes
< HTTP/1.1 406 Not Acceptable
< Content-Type: application/json; charset=utf-8
< X-Ua-Compatible: IE=Edge
< Cache-Control: no-cache
< X-Request-Id: 338234ca2a6c378426ab67d7a080d44e
< X-Runtime: 0.006427
< Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-12-25)
< Date: Sat, 09 Feb 2013 23:11:19 GMT
< Content-Length: 1
< Connection: Keep-Alive
< Set-Cookie: _MyRailsApp_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRkkiJTY1ZWIzMTdiYzc5ODdmMzNkOWI5MDM4NTMzYTQ0MWVkBjsAVA%3D%3D--c5871e8577987f36c614483b7a28b08fed55b7b8; path=/; HttpOnly

最佳答案

为设计启用 json

config.navigational_formats = ["/", :json]

并添加新文件

class RegistrationsController < Devise::RegistrationsController

def create

@user = User.create(params[:user])
if @user.save
render :json => {:state => {:code => 0}, :data => @user }
else
render :json => {:state => {:code => 1, :messages => @user.errors.full_messages} }
end

end
end

在路线:
  devise_for :users, :controllers => {:registrations => "registrations"}

更新

json也应该看起来:
{"user" : {"email":"who@me.com","password":"mypass"}}

关于ios - 通过原生 iOS 应用使用 Devise 创建用户帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14792746/

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