Reduce ABC complexity...but not really

This commit is contained in:
Andrew Tomaka 2016-10-11 00:33:44 -04:00
parent 18e383b75e
commit e15f9d84ba
2 changed files with 10 additions and 6 deletions

View file

@ -1,3 +1,4 @@
[![travis status](https://api.travis-ci.org/atomaka/link-share.png)](https://travis-ci.org/atomaka/link-share) [![travis status](https://api.travis-ci.org/atomaka/link-share.png)](https://travis-ci.org/atomaka/link-share)
[![codebeat badge](https://codebeat.co/badges/7a333669-bde0-48aa-ad92-483c4c0c4275)](https://codebeat.co/projects/github-com-atomaka-link-share)
# link-share # link-share

View file

@ -7,14 +7,17 @@ helpers do
def authorized? def authorized?
@auth ||= Rack::Auth::Basic::Request.new(request.env) @auth ||= Rack::Auth::Basic::Request.new(request.env)
return unless @auth.provided? and @auth.basic? return unless @auth.provided? && @auth.basic?
username, password = @auth.credentials authenticate?(@auth.credentials)
user_exists?(username) && settings.users[username] == password
end end
def user_exists?(username) def authenticate?(credentials)
settings.users.keys.include?(username) username, password = credentials
users.keys.include?(username) && users[username] == password
end
def users
settings.users
end end
end end