Module: Auth1::SessionsHelper

Defined in:
app/helpers/auth1/sessions_helper.rb

Instance Method Summary collapse

Instance Method Details

#login_button(name = 'Login', options = nil, html_options = nil, &block) ⇒ Object



5
6
7
8
9
10
# File 'app/helpers/auth1/sessions_helper.rb', line 5

def (name = 'Login', options = nil, html_options = nil, &block)
  options ||= '/auth/auth0'
  html_options ||= {}
  html_options[:method] = :post
  button_to(name, options, html_options, &block)
end


31
32
33
34
35
36
# File 'app/helpers/auth1/sessions_helper.rb', line 31

def (name = 'Login', options = nil, html_options = nil, &block)
  options ||= '/auth/auth0'
  html_options ||= {}
  html_options[:method] = :post
  link_to(name, options, html_options, &block)
end

#login_or_logout_button(name = %w[Login Logout],, options = [nil, nil], html_options = [nil, nil], &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/auth1/sessions_helper.rb', line 19

def (name = %w[Login Logout], options = [nil, nil], html_options = [nil, nil], &block)
  if user_signed_in?
    logout_html_options = html_options[1] || {}
    logout_html_options[:method] = :get
    logout_button(name[1], options[1], logout_html_options, &block)
  else
     = html_options[0] || {}
    [:method] = :post
    (name[0], options[0], , &block)
  end
end


45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/auth1/sessions_helper.rb', line 45

def (name = %w[Login Logout], options = [nil, nil], html_options = [nil, nil], &block)
  if user_signed_in?
    logout_html_options = html_options[1] || {}
    logout_html_options[:method] = :get
    logout_link(name[1], options[1], logout_html_options, &block)
  else
     = html_options[0] || {}
    [:method] = :post
    (name[0], options[0], , &block)
  end
end

#logout_button(name = 'Logout', options = nil, html_options = nil, &block) ⇒ Object



12
13
14
15
16
17
# File 'app/helpers/auth1/sessions_helper.rb', line 12

def logout_button(name = 'Logout', options = nil, html_options = nil, &block)
  options ||= auth1.logout_path
  html_options ||= {}
  html_options[:method] = :get
  button_to(name, options, html_options, &block)
end


38
39
40
41
42
43
# File 'app/helpers/auth1/sessions_helper.rb', line 38

def logout_link(name = 'Logout', options = nil, html_options = nil, &block)
  options ||= auth1.logout_path
  html_options ||= {}
  html_options[:method] = :get
  link_to(name, options, html_options, &block)
end

#user_signed_in?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/helpers/auth1/sessions_helper.rb', line 57

def user_signed_in?
  session['userinfo'].present?
end