lib/vidibus/user/extensions/controller.rb in vidibus-user-0.0.10 vs lib/vidibus/user/extensions/controller.rb in vidibus-user-1.0.0
- old
+ new
@@ -1,53 +1,35 @@
+require 'vidibus/user/extensions/helper'
+
module Vidibus
module User
module Extensions
-
- # Contains extensions of ApplicationController.
module Controller
- extend ActiveSupport::Concern
+ include Helper
- included do
- helper_method :warden, :signed_in?, :user_signed_in?, :current_user, :user_session
+ # Authenticates user from single sign on cookie.
+ # Nothing happens if authentication fails.
+ def single_sign_on
+ return if authenticated?
+ warden.authenticate(:single_sign_on)
end
- protected
-
- # Accessor for the warden proxy instance.
- def warden
- request.env["warden"]
+ # Authenticates user either from single sign on cookie
+ # or from email and password params.
+ # Calls failure app if authentication fails.
+ def authenticate!
+ return if authenticated?
+ warden.authenticate!
end
+ alias :signin! :authenticate!
+ alias :authenticate_user! :authenticate!
- # Performs login on Connector service.
- def authenticate_user!
- return if user_signed_in?
- store_location
- warden.authenticate!(:scope => :user)
+ # Performs logout.
+ def logout
+ return unless authenticated?
+ warden.logout
end
-
- # Returns session of currently signed in user.
- def user_session
- current_user and warden.session(:user)
- end
-
- # Returns user currently logged in.
- def current_user
- warden.user(:user)
- end
-
- # Returns true if user is logged in.
- def user_signed_in?
- warden.authenticated?(:user)
- end
- alias_method :signed_in?, :user_signed_in?
-
- private
-
- # Stores current location in session to perform redirect after signin in session
- def store_location
- Rails.logger.error 'store_location: '+request.fullpath
- session[:user_return_to] = request.fullpath
- end
+ alias :signout :logout
end
end
end
end