Rails / Deanise(设计令牌Auth)在解锁帐户时重定向



我目前正在尝试找到一种在解锁帐户时更改重定向URL的方法。当前,当一个帐户被锁定时,用户正在收到一封电子邮件以解锁为帐户,但是TE用户会在默认URL上重定向。由于我的铁轨项目是一个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)

才能使用Devise进行任何自定义,必须通过创建新的控制器并在您的情况下从其内继承来覆盖默认控制器:: unlockscontroller

例如: CustomUnlocksController < Devise::UnlocksController

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

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

最新更新