Module: SelfAuthRails::ApplicationHelper

Defined in:
app/helpers/self_auth_rails/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_user!Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/self_auth_rails/application_helper.rb', line 3

def authenticate_user!
  current_url = URI(request.base_url + request.path).request_uri

  uri = URI(main_app.root_url)

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

  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

#current_userObject



20
21
22
# File 'app/helpers/self_auth_rails/application_helper.rb', line 20

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