而不是檢查實際的錯誤,我是能夠檢查導致它使用@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 }
請注意:主題應該是: Authlogic:如果用戶不是在因爲登錄如何找到該用戶輸入了無效的憑據或者因爲他不活躍。 – Pankaj 2010-07-15 05:16:14