簡體   English   中英

設計使用Rails的首次登錄

[英]devise first login with rails

我如何在我的自定義會話控制器上確定該用戶是第一次登錄,我希望能夠創建一個會話並重定向到welcome#index如果是第一次登錄),否則它將被重定向到root_url

我擁有的代碼如下

class MysessionsController < Devise::SessionsController
  def create
    self.resource = warden.authenticate!(auth_options)
    set_flash_message(:notice, :signed_in) if is_navigational_format?
    sign_in(resource_name, resource)
    respond_with resource, :location => after_sign_in_path_for(resource)    
  end
  protected
  def after_sign_up_path_for(resource)
    "http://google.com"

  end 
end

我知道我需要自定義after_sign_up_path_for(resource)到我想要的內容,但是我無法找到如何確定用戶是否已經通過after_sign_up_path_for(resource)登錄了

您應該可以使用:sign_in_count列來執行此:sign_in_count 如果為0,則表示用戶之前未登錄

舉個例子

redirect_to ((current_user.sign_in_count == 0) ? path1 : path2 ) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM