Module: QAuthRubyClient::SessionsHelper
- Defined in:
- app/helpers/q_auth_ruby_client/sessions_helper.rb
Instance Method Summary collapse
-
#current_user ⇒ Object
This method is widely used to create the @current_user object from the session This method will return @current_user if it already exists which will save queries when called multiple times.
-
#default_redirect_url_after_sign_in ⇒ Object
Returns the default URL to which the system should redirect the user after successful authentication.
-
#default_redirect_url_after_sign_out ⇒ Object
Returns the default URL to which the system should redirect after the user successfully logout.
- #redirect_to_sign_in_page ⇒ Object
- #redirect_url_after_sign_in ⇒ Object
-
#require_admin ⇒ Object
This method is usually used as a before filter from admin controllers to ensure that the logged in user is an admin.
-
#require_super_admin ⇒ Object
This method is usually used as a before filter from admin controllers to ensure that the logged in user is a super admin.
-
#require_user ⇒ Object
This method is usually used as a before filter to secure some of the actions which requires the user to be signed in.
- #update_user_profile_data_and_auth_token ⇒ Object
Instance Method Details
#current_user ⇒ Object
This method is widely used to create the @current_user object from the session This method will return @current_user if it already exists which will save queries when called multiple times
37 38 39 40 41 42 |
# File 'app/helpers/q_auth_ruby_client/sessions_helper.rb', line 37 def current_user session[:qarc] = "true" return @current_user if @current_user # Check if the user exists with the auth token present in session @current_user = QAuthRubyClient::User.where("q_auth_uid = ?", session[:id]).first end |
#default_redirect_url_after_sign_in ⇒ Object
Returns the default URL to which the system should redirect the user after successful authentication
5 6 7 |
# File 'app/helpers/q_auth_ruby_client/sessions_helper.rb', line 5 def default_redirect_url_after_sign_in QAuthRubyClient.configuration.default_redirect_url_after_sign_in end |
#default_redirect_url_after_sign_out ⇒ Object
Returns the default URL to which the system should redirect after the user successfully logout
10 11 12 |
# File 'app/helpers/q_auth_ruby_client/sessions_helper.rb', line 10 def default_redirect_url_after_sign_out QAuthRubyClient.configuration.default_redirect_url_after_sign_out end |
#redirect_to_sign_in_page ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/q_auth_ruby_client/sessions_helper.rb', line 18 def redirect_to_sign_in_page respond_to do |format| format.html { redirect_to q_auth_ruby_client.sign_in_path } format.json { render json: {heading: @heading, alert: @alert} } format.js { render(:partial => 'sessions/redirect.js.erb', :handlers => [:erb], :formats => [:js]) } end end |
#redirect_url_after_sign_in ⇒ Object
14 15 16 |
# File 'app/helpers/q_auth_ruby_client/sessions_helper.rb', line 14 def redirect_url_after_sign_in params[:redirect_back_url] || default_redirect_url_after_sign_in end |
#require_admin ⇒ Object
This method is usually used as a before filter from admin controllers to ensure that the logged in user is an admin
63 64 65 66 67 68 69 |
# File 'app/helpers/q_auth_ruby_client/sessions_helper.rb', line 63 def require_admin unless @current_user.is_admin? (I18n.t("authentication.permission_denied_heading"), I18n.t("authentication.permission_denied_message"), :error) redirect_to_sign_in_page return end end |
#require_super_admin ⇒ Object
This method is usually used as a before filter from admin controllers to ensure that the logged in user is a super admin
72 73 74 75 76 77 |
# File 'app/helpers/q_auth_ruby_client/sessions_helper.rb', line 72 def require_super_admin unless @current_user.is_super_admin? (I18n.t("authentication.permission_denied_heading"), I18n.t("authentication.permission_denied_message"), :error) redirect_to_sign_in_page end end |
#require_user ⇒ Object
This method is usually used as a before filter to secure some of the actions which requires the user to be signed in.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/helpers/q_auth_ruby_client/sessions_helper.rb', line 45 def require_user current_user if @current_user if @current_user.token_expired? @current_user = nil session.delete(:id) (I18n.t("authentication.session_expired_heading"), I18n.t("authentication.session_expired_message"), :error) redirect_to_sign_in_page return end else (I18n.t("authentication.permission_denied_heading"), I18n.t("authentication.permission_denied_message"), :error) redirect_to_sign_in_page return end end |
#update_user_profile_data_and_auth_token ⇒ Object
28 29 30 31 32 33 |
# File 'app/helpers/q_auth_ruby_client/sessions_helper.rb', line 28 def update_user_profile_data_and_auth_token # Store the user object and Redirect to the Q-Auth sign in page with required params params_hsh = {client_app: QAuthRubyClient.configuration.q_app_name, redirect_back_url: create_session_url} url = add_query_params(QAuthRubyClient.configuration.q_auth_url, params_hsh) redirect_to url end |