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

时间:2017-12-04 20:55:46

标签: ruby-on-rails ruby redirect devise

我正在尝试在解锁帐户时找到更改重定向网址的方法。目前,当帐户被锁定时,用户正在获取要解锁的电子邮件是帐户,但是te用户将获得默认URL上的重定向。由于我的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)

1 个答案:

答案 0 :(得分:0)

要使用Devise进行任何自定义,必须通过创建一个新的控制器来覆盖默认控制器,并在你的情况下从它继承Devise :: UnlocksController

例如: CustomUnlocksController < Devise::UnlocksController

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

after_unlock_path_for覆盖到您要重定向的路径。