From e15f9d84ba3c14bb8750d43120c971ec119adabe Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 11 Oct 2016 00:33:44 -0400 Subject: [PATCH] Reduce ABC complexity...but not really --- README.md | 1 + helpers/application_helper.rb | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0b4c2dd..42f38f9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/helpers/application_helper.rb b/helpers/application_helper.rb index 678ba9d..779e390 100644 --- a/helpers/application_helper.rb +++ b/helpers/application_helper.rb @@ -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