summaryrefslogtreecommitdiff
path: root/users/app/controllers
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-05-16 08:42:36 +0200
committerAzul <azul@leap.se>2014-05-16 08:42:36 +0200
commit8fbbb8717f0578536b97c2dc0883c632f120e976 (patch)
tree17aeb2b48ada703ac916a9a65fbf3c75a5dadb86 /users/app/controllers
parent81555ec6244ed76f92e3629880f68104b8705817 (diff)
parenta4f7a410c536d88c91c834cab6ee950c71005ddd (diff)
Merge remote-tracking branch 'origin/develop'
Conflicts: app/assets/javascripts/srp test/nagios/soledad_sync.py test/nagios/webapp_login.py
Diffstat (limited to 'users/app/controllers')
-rw-r--r--users/app/controllers/.gitkeep0
-rw-r--r--users/app/controllers/account_settings_controller.rb0
-rw-r--r--users/app/controllers/controller_extension/authentication.rb68
-rw-r--r--users/app/controllers/controller_extension/token_authentication.rb23
-rw-r--r--users/app/controllers/keys_controller.rb18
-rw-r--r--users/app/controllers/sessions_controller.rb27
-rw-r--r--users/app/controllers/users_base_controller.rb18
-rw-r--r--users/app/controllers/users_controller.rb68
-rw-r--r--users/app/controllers/v1/sessions_controller.rb44
-rw-r--r--users/app/controllers/v1/users_controller.rb32
-rw-r--r--users/app/controllers/webfinger_controller.rb19
11 files changed, 0 insertions, 317 deletions
diff --git a/users/app/controllers/.gitkeep b/users/app/controllers/.gitkeep
deleted file mode 100644
index e69de29..0000000
--- a/users/app/controllers/.gitkeep
+++ /dev/null
diff --git a/users/app/controllers/account_settings_controller.rb b/users/app/controllers/account_settings_controller.rb
deleted file mode 100644
index e69de29..0000000
--- a/users/app/controllers/account_settings_controller.rb
+++ /dev/null
diff --git a/users/app/controllers/controller_extension/authentication.rb b/users/app/controllers/controller_extension/authentication.rb
deleted file mode 100644
index d831fbe..0000000
--- a/users/app/controllers/controller_extension/authentication.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-module ControllerExtension::Authentication
- extend ActiveSupport::Concern
-
- private
-
- included do
- helper_method :current_user, :logged_in?, :admin?
- end
-
- def current_user
- @current_user ||= token_authenticate || warden.user
- end
-
- def logged_in?
- !!current_user
- end
-
- def authorize
- access_denied unless logged_in?
- end
-
- def access_denied
- respond_to do |format|
- format.html do
- if logged_in?
- redirect_to home_url, :alert => t(:not_authorized)
- else
- redirect_to login_url, :alert => t(:not_authorized_login)
- end
- end
- format.json do
- render :json => {'error' => t(:not_authorized)}, status: :unprocessable_entity
- end
- end
- end
-
- def admin?
- current_user && current_user.is_admin?
- end
-
- def authorize_admin
- access_denied unless admin?
- end
-
- def authentication_errors
- return unless attempted_login?
- errors = get_warden_errors
- errors.inject({}) do |translated,err|
- translated[err.first] = I18n.t(err.last)
- translated
- end
- end
-
- def get_warden_errors
- if strategy = warden.winning_strategy
- message = strategy.message
- # in case we get back the default message to fail!
- message.respond_to?(:inject) ? message : { base: message }
- else
- { login: :all_strategies_failed }
- end
- end
-
- def attempted_login?
- request.env['warden.options'] &&
- request.env['warden.options'][:attempted_path]
- end
-end
diff --git a/users/app/controllers/controller_extension/token_authentication.rb b/users/app/controllers/controller_extension/token_authentication.rb
deleted file mode 100644
index 530294a..0000000
--- a/users/app/controllers/controller_extension/token_authentication.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-module ControllerExtension::TokenAuthentication
- extend ActiveSupport::Concern
-
- def token_authenticate
- authenticate_with_http_token do |token_id, options|
- @token = Token.find(token_id)
- end
- @token.authenticate if @token
- end
-
- def logout
- super
- clear_token
- end
-
- def clear_token
- authenticate_with_http_token do |token_id, options|
- @token = Token.find(token_id)
- @token.destroy if @token
- end
- end
-end
-
diff --git a/users/app/controllers/keys_controller.rb b/users/app/controllers/keys_controller.rb
deleted file mode 100644
index fb28901..0000000
--- a/users/app/controllers/keys_controller.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-class KeysController < ApplicationController
-
- #
- # Render the user's key as plain text, without a layout.
- #
- # We will show blank page if user doesn't have key (which shouldn't generally occur)
- # and a 404 error if user doesn't exist
- #
- def show
- user = User.find_by_login(params[:login])
- if user
- render text: user.public_key, content_type: 'text/text'
- else
- raise ActionController::RoutingError.new('Not Found')
- end
- end
-
-end
diff --git a/users/app/controllers/sessions_controller.rb b/users/app/controllers/sessions_controller.rb
deleted file mode 100644
index 0195f30..0000000
--- a/users/app/controllers/sessions_controller.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-class SessionsController < ApplicationController
-
- def new
- redirect_to home_url if logged_in?
- @session = Session.new
- if authentication_errors
- @errors = authentication_errors
- render :status => 422
- end
- end
-
- def destroy
- logout
- redirect_to home_url
- end
-
- #
- # this is a bad hack, but user_url(user) is not available
- # also, this doesn't work because the redirect happens as a PUT. no idea why.
- #
- #Warden::Manager.after_authentication do |user, auth, opts|
- # response = Rack::Response.new
- # response.redirect "/users/#{user.id}"
- # throw :warden, response.finish
- #end
-
-end
diff --git a/users/app/controllers/users_base_controller.rb b/users/app/controllers/users_base_controller.rb
deleted file mode 100644
index 9becf0d..0000000
--- a/users/app/controllers/users_base_controller.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# common base class for all user related controllers
-#
-
-class UsersBaseController < ApplicationController
-
- protected
-
- def fetch_user
- @user = User.find(params[:user_id] || params[:id])
- if !@user && admin?
- redirect_to users_url, :alert => t(:no_such_thing, :thing => 'user')
- elsif !admin? && @user != current_user
- access_denied
- end
- end
-
-end
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb
deleted file mode 100644
index a5461cd..0000000
--- a/users/app/controllers/users_controller.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# This is an HTML-only controller. For the JSON-only controller, see v1/users_controller.rb
-#
-
-class UsersController < UsersBaseController
-
- before_filter :authorize, :only => [:show, :edit, :update, :destroy]
- before_filter :fetch_user, :only => [:show, :edit, :update, :destroy, :deactivate, :enable]
- before_filter :authorize_admin, :only => [:index, :deactivate, :enable]
-
- respond_to :html
-
- def index
- if params[:query]
- if @user = User.find_by_login(params[:query])
- redirect_to @user
- return
- else
- @users = User.by_login.startkey(params[:query]).endkey(params[:query].succ)
- end
- else
- @users = User.by_created_at.descending
- end
- @users = @users.limit(100)
- end
-
- def new
- @user = User.new
- end
-
- def show
- end
-
- def edit
- end
-
- ## added so updating service level works, but not sure we will actually want this. also not sure that this is place to prevent user from updating own effective service level, but here as placeholder:
- def update
- @user.update_attributes(params[:user]) unless (!admin? and params[:user][:effective_service_level])
- respond_with @user
- end
-
- def deactivate
- @user.enabled = false
- @user.save
- respond_with @user
- end
-
- def enable
- @user.enabled = true
- @user.save
- respond_with @user
- end
-
- def destroy
- @user.account.destroy
- flash[:notice] = I18n.t(:account_destroyed)
- # admins can destroy other users
- if @user != current_user
- redirect_to users_url
- else
- # let's remove the invalid session
- logout
- redirect_to bye_url
- end
- end
-
-end
diff --git a/users/app/controllers/v1/sessions_controller.rb b/users/app/controllers/v1/sessions_controller.rb
deleted file mode 100644
index eb6c322..0000000
--- a/users/app/controllers/v1/sessions_controller.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-module V1
- class SessionsController < ApplicationController
-
- skip_before_filter :verify_authenticity_token
-
- def new
- @session = Session.new
- if authentication_errors
- @errors = authentication_errors
- render :status => 422
- end
- end
-
- def create
- logout if logged_in?
- if params['A']
- authenticate!
- else
- @user = User.find_by_login(params['login'])
- render :json => {salt: @user.salt}
- end
- end
-
- def update
- authenticate!
- @token = Token.create(:user_id => current_user.id)
- session[:token] = @token.id
- render :json => login_response
- end
-
- def destroy
- logout
- head :no_content
- end
-
- protected
-
- def login_response
- handshake = session.delete(:handshake) || {}
- handshake.to_hash.merge(:id => current_user.id, :token => @token.id)
- end
-
- end
-end
diff --git a/users/app/controllers/v1/users_controller.rb b/users/app/controllers/v1/users_controller.rb
deleted file mode 100644
index 0903888..0000000
--- a/users/app/controllers/v1/users_controller.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-module V1
- class UsersController < UsersBaseController
-
- skip_before_filter :verify_authenticity_token
- before_filter :fetch_user, :only => [:update]
- before_filter :authorize, :only => [:update]
- before_filter :authorize_admin, :only => [:index]
-
- respond_to :json
-
- # used for autocomplete for admins in the web ui
- def index
- if params[:query]
- @users = User.by_login.startkey(params[:query]).endkey(params[:query].succ)
- respond_with @users.map(&:login).sort
- else
- render :json => {'error' => 'query required', 'status' => :unprocessable_entity}
- end
- end
-
- def create
- @user = Account.create(params[:user])
- respond_with @user # return ID instead?
- end
-
- def update
- @user.account.update params[:user]
- respond_with @user
- end
-
- end
-end
diff --git a/users/app/controllers/webfinger_controller.rb b/users/app/controllers/webfinger_controller.rb
deleted file mode 100644
index 8872802..0000000
--- a/users/app/controllers/webfinger_controller.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-class WebfingerController < ApplicationController
-
- respond_to :xml, :json
- layout false
-
- def host_meta
- @host_meta = Webfinger::HostMetaPresenter.new(request)
- respond_with @host_meta
- end
-
- def search
- username = params[:q].split('@')[0].to_s.downcase
- user = User.find_by_login(username)
- raise RECORD_NOT_FOUND, 'User not found' unless user.present?
- @presenter = Webfinger::UserPresenter.new(user, request)
- respond_with @presenter
- end
-
-end