summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/controller_extension/authentication.rb12
-rw-r--r--app/controllers/v1/certs_controller.rb38
-rw-r--r--app/controllers/v1/messages_controller.rb5
-rw-r--r--app/controllers/v1/services_controller.rb8
4 files changed, 23 insertions, 40 deletions
diff --git a/app/controllers/controller_extension/authentication.rb b/app/controllers/controller_extension/authentication.rb
index 03d3989..1f73f38 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 || anonymous
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 anonymous
+ AnonymousUser.new
+ end
end
diff --git a/app/controllers/v1/certs_controller.rb b/app/controllers/v1/certs_controller.rb
index 64cfa7f..73409ef 100644
--- a/app/controllers/v1/certs_controller.rb
+++ b/app/controllers/v1/certs_controller.rb
@@ -4,7 +4,7 @@ class V1::CertsController < ApplicationController
# GET /cert
def show
- @cert = ClientCertificate.new(:prefix => certificate_prefix)
+ @cert = ClientCertificate.new(:prefix => service_level.cert_prefix)
render text: @cert.to_s, content_type: 'text/plain'
end
@@ -13,38 +13,8 @@ class V1::CertsController < ApplicationController
def anonymous_certs_allowed?
APP_CONFIG[:allow_anonymous_certs]
end
- #
- # this is some temporary logic until we store the service level in the user db.
- #
- # better logic might look like this:
- #
- # if logged_in?
- # service_level = user.service_level
- # elsif allow_anonymous?
- # service_level = service_levels[:anonymous]
- # else
- # service_level = nil
- # end
- #
- # if service_level.bandwidth == 'limited' && allow_limited?
- # prefix = limited
- # elsif allow_unlimited?
- # prefix = unlimited
- # else
- # prefix = nil
- # end
- #
- def certificate_prefix
- if logged_in?
- if APP_CONFIG[:allow_unlimited_certs]
- APP_CONFIG[:unlimited_cert_prefix]
- elsif APP_CONFIG[:allow_limited_certs]
- APP_CONFIG[:limited_cert_prefix]
- end
- elsif !APP_CONFIG[:allow_limited_certs]
- APP_CONFIG[:unlimited_cert_prefix]
- else
- APP_CONFIG[:limited_cert_prefix]
- end
+
+ def service_level
+ current_user.effective_service_level
end
end
diff --git a/app/controllers/v1/messages_controller.rb b/app/controllers/v1/messages_controller.rb
index f71d0f1..85156b7 100644
--- a/app/controllers/v1/messages_controller.rb
+++ b/app/controllers/v1/messages_controller.rb
@@ -7,12 +7,11 @@ module V1
respond_to :json
def index
- render json: (current_user ? current_user.messages : [] )
+ render json: current_user.messages
end
def update
- message = Message.find(params[:id])
- if (message and current_user)
+ if message = Message.find(params[:id])
message.mark_as_read_by(current_user)
message.save
render json: true
diff --git a/app/controllers/v1/services_controller.rb b/app/controllers/v1/services_controller.rb
new file mode 100644
index 0000000..594940e
--- /dev/null
+++ b/app/controllers/v1/services_controller.rb
@@ -0,0 +1,8 @@
+class V1::ServicesController < ApplicationController
+
+ respond_to :json
+
+ def show
+ respond_with current_user.effective_service_level
+ end
+end