Module: Isaca::Rails::Authentication
- Extended by:
- ActiveSupport::Concern
- Included in:
- Controller
- Defined in:
- lib/isaca/rails/authentication.rb
Instance Method Summary collapse
-
#authenticate(username, password) ⇒ Boolean
Method used to to login a user and set the token.
-
#authenticate_isaca_user ⇒ Object
Checks to see if there is a current_isaca_user, if not it redirects to the new_session_path.
-
#current_isaca_user ⇒ ActiveModel::Model|nil
A helper method for referencing the user who is currently logged in.
- #isaca_requires_consent? ⇒ Boolean
-
#isaca_sign_out(**params) ⇒ Object
Destroys the user token and sets the current_isaca_user attribute to nil.
-
#redirect_after_sign_in_or(fallback) ⇒ Object
Helper method to redirect to a saved path or fallback.
-
#redirect_for_consent? ⇒ Boolean
Helper method used to check the conditions for redirecting for consent.
-
#user_signed_in? ⇒ Boolean
Helper method to check and see if the current_isaca_user attribute exists.
Instance Method Details
#authenticate(username, password) ⇒ Boolean
Method used to to login a user and set the token
54 55 56 57 58 59 |
# File 'lib/isaca/rails/authentication.rb', line 54 def authenticate(username, password) session = Isaca::Request::AuthenticateUser.get(username, password) raise Isaca::SessionError.new(session.value) unless session.is_valid? isaca_sign_in(session.value) current_isaca_user.update_attribute(:last_sign_in_at, DateTime.current) end |
#authenticate_isaca_user ⇒ Object
Checks to see if there is a current_isaca_user, if not it redirects to the new_session_path. This method is intended to be used with before_action.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/isaca/rails/authentication.rb', line 17 def authenticate_isaca_user if user_signed_in? if request.path != && session[:after_sign_in_path] = request.fullpath if request.get? && request.format.html? flash.alert = t('isaca.rails.user_consent.consent_required') redirect_to end else session[:after_sign_in_path] = request.fullpath if request.get? flash.alert = t('isaca.rails.sessions.sign_in_required') respond_to do |format| format.html {redirect_to sign_in_path} format.json do render json: {error: t('isaca.rails.sessions.sign_in_required')}.to_json, status: :unauthorized end end end end |
#current_isaca_user ⇒ ActiveModel::Model|nil
A helper method for referencing the user who is currently logged in.
40 41 42 43 44 45 46 |
# File 'lib/isaca/rails/authentication.rb', line 40 def current_isaca_user if @current_isaca_user @current_isaca_user else set_current_isaca_user if end end |
#isaca_requires_consent? ⇒ Boolean
85 86 87 |
# File 'lib/isaca/rails/authentication.rb', line 85 def user_signed_in? && !current_isaca_user.privacy end |
#isaca_sign_out(**params) ⇒ Object
Destroys the user token and sets the current_isaca_user attribute to nil
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/isaca/rails/authentication.rb', line 67 def isaca_sign_out(**params) token = nil params && params[:token] ? (token = params[:token]) : (token = ['Token'] if ) if token && Isaca::Request::LogOut.get(token) .delete('Token', domain: :all) if @current_isaca_user = nil reset_session end end |
#redirect_after_sign_in_or(fallback) ⇒ Object
Helper method to redirect to a saved path or fallback
92 93 94 95 |
# File 'lib/isaca/rails/authentication.rb', line 92 def redirect_after_sign_in_or(fallback) redirect_to(session[:after_sign_in_path] || fallback) session.delete(:after_sign_in_path) end |
#redirect_for_consent? ⇒ Boolean
Helper method used to check the conditions for redirecting for consent
100 101 102 |
# File 'lib/isaca/rails/authentication.rb', line 100 def && Isaca::Rails.configuration. end |
#user_signed_in? ⇒ Boolean
Helper method to check and see if the current_isaca_user attribute exists
81 82 83 |
# File 'lib/isaca/rails/authentication.rb', line 81 def user_signed_in? !current_isaca_user.nil? end |