user1470511
user1470511

Reputation: 349

Rails 3 Password Protect Single View

I have gone through and looked at a bunch of screen casts (http://railscasts.com/episodes/270-authentication-in-rails-3-1) and tutorials (http://ruby.railstutorial.org/chapters/modeling-and-viewing-users-two?version=2.3#sec:secure_passwords) but I can't seem to find or apply what I am learning to create a single view password protected.

As of now I am generating a random password and showing it to the user to go back and view a file they have uploaded (generated using SecureRandom.hex). However, I know that using http_basic doesn't seem to work when I restrict it only to the show view and method in my controller : http_basic_authenticate_with :password => :passcode, :only => :show

I know that line of code does not work because :passcode does not reference the individual files password that was created.

Also, I know that http_basic_authenticate_with is not the way it should be done for secure passwords, so how would you go about this using has_secure_password etc?

Upvotes: 0

Views: 1339

Answers (1)

squiter
squiter

Reputation: 5761

You can try to encapsulate the http_basic_authenticate_with :password => :passcode in a method in your controller, and call the before_filter to call that method.
Something like that:

before_filter :restrict, :only => :show

def show
end

def restrict
  http_basic_authenticate_with :password => :passcode
end

Upvotes: 0

Related Questions