Tôi có ứng dụng đường ray của mình và tôi đang gặp phải vấn đề lớn với sự phát sinh. Tôi có một bộ điều khiển:Tôi làm cách nào để đăng nhập một người dùng?
class Users::SessionsController < Devise::SessionsController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
include Devise::Controllers::InternalHelpers
def new
clean_up_passwords(build_resource)
respond_to do |format|
format.html { render :layout => "sessions" }
format.mobile
end
end
# POST /resource/sign_in
def create
resource = User.find_by_email(params[:user][:email])
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message :notice, :signed_in
sign_in_and_redirect(resource_name, resource)
end
end
Vấn đề là nó không bao giờ đăng nhập người sử dụng trong, nó luôn luôn dừng lại ở dòng này
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
tôi thậm chí đặt tấn logger trong các tập tin đá quý thực tế để xem liệu tôi có thể thấy bất cứ điều gì nhưng không có gì và tôi thực sự không có ý tưởng làm thế nào để sửa lỗi này. Nếu tôi nhận xét dòng này thì người dùng sẽ đăng nhập nhưng không thành công nếu email không nằm trong db và làm việc cho bất kỳ mật khẩu nào (chắc chắn không phải là giải pháp đúng)
Làm cách nào để khắc phục sự cố này?
CẬP NHẬT
làm việc này, nhưng có vẻ rất hackish
# POST /resource/sign_in
def create
resource = User.find_by_email(params[:user][:email])
redirect_to(new_user_session_path, :notice => 'Invalid Email Address or Password. Password is case sensitive.') and return if resource.encrypted_password.blank?
bcrypt = BCrypt::Password.new(resource.encrypted_password)
password = BCrypt::Engine.hash_secret("#{params[:user][:password]}#{resource.class.pepper}", bcrypt.salt)
valid = Devise.secure_compare(password, resource.encrypted_password)
# resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
if valid
set_flash_message :notice, :signed_in
sign_in_and_redirect(resource_name, resource)
else
redirect_to(new_user_session_path, :notice => 'Invalid Email Address or Password. Password is case sensitive.') and return
end
end
này ghi chúng vào bất kể ngay cả khi mật khẩu là sai hay không – Trace
Kiểm tra ' user.valid_password? (params [: password]) 'trước tiên, sau đó. –
Tôi đã thử chính xác như thế này nhưng có số lượng sai các đối số (2 cho 0). bất kỳ ý tưởng? – ishwr