diff options
-rw-r--r-- | app/controllers/controller_extension/authentication.rb | 12 | ||||
-rw-r--r-- | app/models/unauthenticated_user.rb | 7 | ||||
-rw-r--r-- | config/defaults.yml | 1 |
3 files changed, 17 insertions, 3 deletions
diff --git a/app/controllers/controller_extension/authentication.rb b/app/controllers/controller_extension/authentication.rb index 03d3989..2bc0aee 100644 --- a/app/controllers/controller_extension/authentication.rb +++ b/app/controllers/controller_extension/authentication.rb @@ -8,11 +8,11 @@ module ControllerExtension::Authentication end def current_user - @current_user ||= token_authenticate || warden.user + @current_user ||= token_authenticate || warden.user || unauthenticated end def logged_in? - !!current_user + current_user.is_a? User end def require_login @@ -42,7 +42,7 @@ module ControllerExtension::Authentication end def admin? - current_user && current_user.is_admin? + current_user.is_admin? end def require_admin @@ -72,4 +72,10 @@ module ControllerExtension::Authentication request.env['warden.options'] && request.env['warden.options'][:attempted_path] end + + protected + + def unauthenticated + UnauthenticatedUser.new + end end diff --git a/app/models/unauthenticated_user.rb b/app/models/unauthenticated_user.rb index 0fc17d2..ba6470a 100644 --- a/app/models/unauthenticated_user.rb +++ b/app/models/unauthenticated_user.rb @@ -3,4 +3,11 @@ class UnauthenticatedUser < Object # will probably want something here to return service level as APP_CONFIG[:service_levels][0] but not sure how will be accessing. + def is_admin? + false + end + + def effective_service_level + ServiceLevel.new id: APP_CONFIG[:unauthenticated_service_level] + end end diff --git a/config/defaults.yml b/config/defaults.yml index e7d0f5e..47c3ad7 100644 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -67,6 +67,7 @@ service_levels: &service_levels USD: 10 EUR: 10 default_service_level: 1 + unauthenticated_service_level: 0 development: <<: *downloads |