用令牌设计

时间:2018-02-28 16:49:25

标签: ruby-on-rails devise token

我正在尝试通过令牌进行身份验证,如下所示: https://gist.github.com/josevalim/fb706b1e933ef01e4fb6

class ApprovalsController < ApplicationController
  before_action :authenticate_user_by_token!, only: [:approve]
  before_action :authenticate_user!

  def index
   @approvals = Approval.find_to_approve current_user
  end

  def approve
    approval = Approval.find(params[:id])
    approval.approve!
    ApprovalMailer.send_pdf(approval.id, current_user.id).deliver
    flash[:success] = "Approval request was approved"
debugger #here I have current_user and user_signed_in? is true
    redirect_to approvals_path
  end

  def authenticate_user_by_token!
    user_email = params[:user_email].presence
    user = user_email && User.find_by_email(user_email)

    if user && Devise.secure_compare(user.authentication_token, params[:user_token])
      sign_in user, store: false
      user.renew_authentication_token!
    end
  end
end

我已登录,approve方法已成功运行,但在方法approvals_path的最后一行重定向到approve后,它将转到登录页面You need to sign in before continuing

为什么?

由于

0 个答案:

没有答案