2010-07-07 85 views
0

我正在使用authlogic與rails應用程序進行身份驗證。 用戶重置密碼後,易腐標記將重置。 考慮這種情況。 用戶註冊,他忘記激活帳戶,他也忘記密碼。 所以他重置密碼。由於這個原因,他的激活鏈接不再有效。所以他無法激活他的賬戶。當他嘗試登錄時,他會收到一個錯誤消息,說明帳戶未激活。 用戶卡住了!Authlogic:如何查找用戶是否因爲用戶未登錄而未登錄

我發現什麼解決方案是在每次登錄被阻止時重新發送激活鏈接,因爲帳戶未激活的問題。

現在的問題是,我需要檢查用戶嘗試登錄時出現什麼類型的錯誤,以便我可以重新發送激活電子郵件。

問候, 的Pankaj

+0

請注意:主題應該是: Authlogic:如果用戶不是在因爲登錄如何找到該用戶輸入了無效的憑據或者因爲他不活躍。 – Pankaj 2010-07-15 05:16:14

回答

2

而不是檢查實際的錯誤,我是能夠檢查導致它使用@user_session.attempted_record && [email protected]_session.invalid_password? && [email protected]_session.attempted_record.active?

這裏是我的完整的解決方案,以重發激活郵件(使用matthook's tutorial設置激活後)的條件:

# /app/controllers/users_sessions_controler.rb 
def create 
    @user_session = UserSession.new(params[:user_session]) 
    if @user_session.save 
    redirect_back_or_default root_path 
    elsif @user_session.attempted_record && 
    [email protected]_session.invalid_password? && 
    [email protected]_session.attempted_record.active? 
    flash[:notice] = render_to_string(:partial => 'user_sessions/not_active.erb', :locals => { :user => @user_session.attempted_record }) 
    redirect_to :action => :new 
    else 
    render :action => :new 
    end 
end 

# /app/views/user_sessions/_not_active.erb 
Sorry, before you can sign in you need to confirm your email address. <%= link_to('Resend confirmation email', resend_activation_users_path(:login => user.login)) %> 

# /app/controllers/users_controller.rb 
def resend_activation 
    if params[:login] 
    @user = User.find_by_login params[:login] 
    if @user && [email protected]? 
     @user.deliver_activation_instructions! 
     flash[:notice] = "Please check your e-mail for your account activation instructions!" 
     redirect_to root_path 
    end 
    end 
end 

# /config/routes.rb 
map.resources :users, :collection => { :resend_activation => :get } 
1

使用數據庫來捕捉註冊,激活,復位和其他細節。這樣你就知道需要採取什麼行動了。

0

邁克:

而不是增加新的過濾器,你應該跳過你已經有過濾器在你的application.rb中

做到這一點的方法是:

skip_before_filter :require_user 

我希望這將是有用的人