简体   繁体   English

Rails / Devise(Devise令牌身份验证)在解锁帐户后重定向

[英]Rails / Devise (Devise token auth) Redirect upon unlocking account

I'm currently trying to find a way to change my redirection url upon unlocking an account. 我目前正在尝试寻找一种方法来解锁帐户后更改重定向网址。 Currently when an account is locked the user is getting a email to unlock is account but then the te user get redirect on a default url. 当前,当帐户被锁定时,用户会收到一封电子邮件来解锁该帐户,但随后,该用户会重定向到默认URL。 Since my rails project is an api it would be nice to redirect to my front-end 由于我的rails项目是一个api,因此重定向到我的前端会很好

Started GET "/api/auth/unlock?unlock_token=YvR4nNssxhB9h8hvDAse" for 
127.0.0.1 at 2017-12-04 15:28:08 -0500
Processing by Devise::UnlocksController#show as JSON
Parameters: {"unlock_token"=>"YvR4nNssxhB9h8hvDAse"}
User Load (0.8ms)  SELECT  "users".* FROM "users" WHERE 
"users"."unlock_token" = $1 ORDER BY "users"."id" ASC LIMIT $2  
[["unlock_token", 
"6f3c4d7aa5254e143f89cd7f187e22ce56b11e6abe1f5eb252e34d86ac101908"], 
["LIMIT", 1]]
(0.1ms)  BEGIN
SQL (0.7ms)  UPDATE "users" SET "locked_at" = $1, "failed_attempts" = $2, 
"unlock_token" = $3, "updated_at" = $4 WHERE "users"."id" = $5  
[["locked_at", nil], ["failed_attempts", 0], ["unlock_token", nil], 
["updated_at", "2017-12-04 20:28:08.783744"], ["id", 1]]
(3.4ms)  COMMIT
Redirected to http://localhost:3000/api/auth/sign_in
Completed 302 Found in 17ms (ActiveRecord: 5.0ms)


Started GET "/api/auth/sign_in" for 127.0.0.1 at 2017-12-04 15:28:08 
-0500
Processing by DeviseTokenAuth::SessionsController#new as JSON
[active_model_serializers] Rendered ActiveModel::Serializer::Null with 
Hash (0.14ms)
Completed 405 Method Not Allowed in 2ms (Views: 0.9ms | ActiveRecord: 
0.0ms)


Started GET "/api/auth/sign_in" for 127.0.0.1 at 2017-12-04 15:31:26 
-0500
Processing by DeviseTokenAuth::SessionsController#new as JSON
[active_model_serializers] Rendered ActiveModel::Serializer::Null with 
Hash (0.11ms) 
Completed 405 Method Not Allowed in 1ms (Views: 0.7ms | ActiveRecord: 
0.0ms)

To do any customization with Devise, one must override the default controllers by creating a new controller and inheriting from it in your case that would be Devise::UnlocksController 要使用Devise进行任何自定义,您必须通过创建一个新的控制器并在您的情况下继承为Devise :: UnlocksController来继承默认控制器。

For example: CustomUnlocksController < Devise::UnlocksController 例如: CustomUnlocksController < Devise::UnlocksController

https://github.com/plataformatec/devise/blob/master/app/controllers/devise/unlocks_controller.rb https://github.com/plataformatec/devise/blob/master/app/controllers/devise/unlocks_controller.rb

Override after_unlock_path_for to the path which you are going to redirect after. after_unlock_path_for替换为您将在其后重定向的路径。

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

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