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
56 57 58 59 60 61 |
# File 'lib/isaca/rails/authentication.rb', line 56 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 != user_consent_path && redirect_for_consent? # session[:after_sign_in_path] = request.fullpath if request.get? && request.format.html? # flash.alert = t('isaca.rails.user_consent.consent_required') # redirect_to user_consent_path # 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 47 48 |
# File 'lib/isaca/rails/authentication.rb', line 40 def current_isaca_user if @current_isaca_user @current_isaca_user else unless session[:user_id].blank? @current_isaca_user = Isaca::Rails.configuration.user_model.find(session[:user_id]) end end end |
#isaca_requires_consent? ⇒ Boolean
87 88 89 |
# File 'lib/isaca/rails/authentication.rb', line 87 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
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/isaca/rails/authentication.rb', line 69 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
94 95 96 97 |
# File 'lib/isaca/rails/authentication.rb', line 94 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
102 103 104 |
# File 'lib/isaca/rails/authentication.rb', line 102 def && Isaca::Rails.configuration. end |
#user_signed_in? ⇒ Boolean
Helper method to check and see if the current_isaca_user attribute exists
83 84 85 |
# File 'lib/isaca/rails/authentication.rb', line 83 def user_signed_in? !current_isaca_user.nil? end |