简体   繁体   English

Rails + Devise + API +用户注册

[英]Rails + Devise + API + User Registration

I am new to ruby and rails and so far I managed to setup user management using devise. 我是红宝石和Rails的新手,到目前为止,我设法使用devise设置了用户管理。 Right now I am trying to integrate support for mobile Android and iOS apps. 现在,我正在尝试集成对移动Android和iOS应用程序的支持。 So far it is possible for them to login and logout and get an authentication token. 到目前为止,他们可以登录和注销并获得身份验证令牌。 But in addition to that I would also like them to be able to register. 但是除此之外,我还希望他们能够注册。

Now, as I understand it I have to do a post to 现在,据我所知,我必须发表

http://localhost:3000/users/sign_up

How does this post look like? 这个帖子看起来如何? And how do I get a JSON response? 以及如何获得JSON响应? I found this on stackoverflow . 我在stackoverflow上发现了这个。

"utf8=✓&authenticity_token=n5vXMnlzrXefnKQEV4SmVM8cFdHDCUxMYWEBMHp9fDw%3D&user[email]=asd%40fasd.org&user[password]=321&user[password_confirmation]=1233&commit=Sign+up"

Unfortunately this does not work - I am getting the message "Bad request". 不幸的是,这不起作用-我收到消息“错误的请求”。 I also do have a couple of questions about this example. 关于这个例子,我也有几个问题。 What is the authenticity_token for? authenticity_token的用途是什么? How do I get one? 我如何得到一个? This is not the devise token authentication I guess as the user is not even in a position to have one at this point. 我猜这不是设备令牌认证,因为用户此时甚至无法拥有一个。

Also, after a successful login I would like to bundle the "registration successful" message with a generated devise authentication token. 另外,在成功登录后,我想将“注册成功”消息与生成的设备认证令牌捆绑在一起。 So I guess I have to somehow extend devise`s existing registration controller. 因此,我想我必须以某种方式扩展devise的现有注册控制器。

Thank you very much in advance! 提前非常感谢您!

Devise already has all this setup. Devise已经具有所有这些设置。 Based on your signup path, I infer that you mounted Devise onto http://localhost:3000/users . 根据您的注册路径,我推断您已将Devise安装到http://localhost:3000/users Devise includes all the controllers and views that are required, including the log in form, the sign up form, the email confirmation form and the password reset forms. Devise包括所需的所有控制器和视图,包括登录表单,注册表单,电子邮件确认表单和密码重置表单。

GET http://localhost:3000/users/sign_up is actually a form for users to signup at. GET http://localhost:3000/users/sign_up实际上是供用户注册的表单。 The form on that page will POST to http://localhost:3000/users/ , which goes to Devise's registration controller's create action. 该页面上的表单将POST到http://localhost:3000/users/ ,该地址转到Devise的注册控制器的create动作。

Assuming there is no action/view already at /users/sign_up , the sign up form should be there, go check if it is there (assuming you set up devise_for correctly in your routes.rb file). 假设/users/sign_up没有任何动作/视图,应该在那里有注册表单,请检查它是否在那里(假设您在routes.rb文件中正确设置了devise_for )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM