Module: AuthLh::AuthManagement

Defined in:
lib/auth_lh/auth_management.rb

Instance Method Summary collapse

Instance Method Details

#change_password_urlObject



58
59
60
# File 'lib/auth_lh/auth_management.rb', line 58

def change_password_url
  @auth_api.change_password_url(request.original_url)
end

#check_access_grantsObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/auth_lh/auth_management.rb', line 42

def check_access_grants
  if current_user
    if !current_user.can_access?(params[:controller], params[:action])
      if request.xhr?
        render status: :forbidden
      else
        render file: 'public/403.html', layout: false
      end
    end
  end
end

#check_local_accessObject



32
33
34
35
36
37
38
39
40
# File 'lib/auth_lh/auth_management.rb', line 32

def check_local_access
  if current_user
    allowed_shop_codes = current_user.allowed_local_shop_codes(current_shop.try(:code))

    if !allowed_shop_codes.include?(local_shop.code)
      render file: 'public/403.html', layout: false
    end
  end
end

#current_shopObject



28
29
30
# File 'lib/auth_lh/auth_management.rb', line 28

def current_shop
  @current_shop
end

#current_userObject



16
17
18
# File 'lib/auth_lh/auth_management.rb', line 16

def current_user
  @current_user
end

#logout_urlObject



54
55
56
# File 'lib/auth_lh/auth_management.rb', line 54

def logout_url
  @auth_api.logout_url(request.protocol + request.host_with_port)
end

#set_current_shopObject



20
21
22
23
24
25
26
# File 'lib/auth_lh/auth_management.rb', line 20

def set_current_shop
  if request.local?
    @current_shop = @local_shop
  else
    @current_shop = @auth_api.get_current_shop(request.remote_ip)
  end
end

#set_current_userObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/auth_lh/auth_management.rb', line 3

def set_current_user
  session_response = @auth_api.get_current_user(cookies[:session_token], request.remote_ip, request.original_url)

  if session_response.user
    @current_user = ::User.find_or_create_by(login: session_response.user.)
    @current_user.auth_user = session_response.user
  end

  if session_response.destination_url.present?
    redirect_to session_response.destination_url
  end
end