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)
[![codebeat badge](https://codebeat.co/badges/7a333669-bde0-48aa-ad92-483c4c0c4275)](https://codebeat.co/projects/github-com-atomaka-link-share)
# link-share

View File

@ -7,14 +7,17 @@ helpers do
def authorized?
@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
user_exists?(username) && settings.users[username] == password
authenticate?(@auth.credentials)
end
def user_exists?(username)
settings.users.keys.include?(username)
def authenticate?(credentials)
username, password = credentials
users.keys.include?(username) && users[username] == password
end
def users
settings.users
end
end