Last active
August 29, 2015 05:13
-
-
Save cmaxw/6ef47281249afb3baac2 to your computer and use it in GitHub Desktop.
012 RailsClips HTTP Basic Authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http_basic_authenticate_with name: "cmaxw", password: "railsclips" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before_filter :check_auth | |
def check_auth | |
authenticate_or_request_with_http_basic do |username,password| | |
resource = User.find_by_email(username) | |
if resource && resource.valid_password?(password) | |
sign_in :user, resource | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before_filter :check_auth | |
def check_auth | |
authenticate_or_request_with_http_basic do |username,password| | |
users = [["cmaxw", "railsclips"], ["dhh", "rails"], ["matz", "minaswan"]] | |
users.include? [username, password] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment