Sha256: 57691c2dfbe3cdf6af01eb0591b70a23ec346b1e15832a5de59fe9bacf496943

Contents?: true

Size: 860 Bytes

Versions: 3

Compression:

Stored size: 860 Bytes

Contents

module SelfAuthRails
  module ApplicationHelper
    def authenticate_user!
      current_url = request.base_url + request.path

      uri = URI(main_app.root_url)

      new_url = SelfAuthRails::Engine.routes.url_helpers.new_url(host: uri.host, port: uri.port)
      create_url = SelfAuthRails::Engine.routes.url_helpers.create_url(host: uri.host, port: uri.port)
      qr_url = SelfAuthRails::Engine.routes.url_helpers.qr_url(host: uri.host, port: uri.port)
      dl_url = SelfAuthRails::Engine.routes.url_helpers.dl_url(host: uri.host, port: uri.port)

      if [new_url, create_url, qr_url, dl_url].include? current_url
        redirect_to root_url unless current_user.nil?
      else
        redirect_to new_url if current_user.nil?
      end
    end

    def current_user
      SelfAuthRails.session_class.find_by(id: session[:user_id])
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
self-auth-rails-0.1.3 app/helpers/self_auth_rails/application_helper.rb
self-auth-rails-0.1.2 app/helpers/self_auth_rails/application_helper.rb
self-auth-rails-0.1.1 app/helpers/self_auth_rails/application_helper.rb