bal*_*anv 9 ruby-on-rails devise
我一直在我的应用程序中使用Devise gem.我能够配置devise sessions_controller来响应来自web和移动API调用的请求.
但现在我想看看我如何使用Devise gem的Forgot Password选项进行Mobile API调用.我可以使用API登录,如下所示
curl -X POST 'http://localhost:3002/users/sign_in.json' -d 'user[email]=balan@test.com&user[password]=123456'
Run Code Online (Sandbox Code Playgroud)
忘记密码可以这样做吗?
bal*_*anv 21
得到了答案.
1)创建一个收到email输入的自定义动作
2)添加以下代码
@user = User.find_by_email("email@email.com")
if @user.present?
@user.send_reset_password_instructions
render :text => "updated"
else
render :text => "no such email"
end
Run Code Online (Sandbox Code Playgroud)
devise 现在支持它。检查以下链接 https://github.com/plataformatec/devise/wiki/API-Mode-Compatibility-Guide
密码重置请求(发布)
curl -X POST \
'http://{{protocol}}{{host}}:{{port}}/{{resource_plural}}/password' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Postman-Token: 406d7e49-7da5-460d-8cc2-1009da8fcb73' \
-H 'cache-control: no-cache' \
-d '{
"user": {
"email": "user@example.com"
}
}'
Run Code Online (Sandbox Code Playgroud)
密码重置确认(补丁)
curl -X PATCH \
'http://{{protocol}}{{host}}:{{port}}/{{resource_plural}}/password' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Postman-Token: f68be2db-1b90-4443-be93-3f012ca4c7dc' \
-H 'cache-control: no-cache' \
-d '{
"user": {
"reset_password_token": "-96mB4zMSjL4t5N6ozGC",
"password": "newpassword",
"password_confirmation": "newpassword"
}
}'
Run Code Online (Sandbox Code Playgroud)