Module: J1App::Helpers

Included in:
AuthManager
Defined in:
lib/j1_app/j1_auth_manager/helpers.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!(*args) ⇒ Object



26
27
28
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 26

def authenticate!(*args)
  warden.authenticate!(*args)
end

#authenticated?(*args) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 30

def authenticated?(*args)
  warden.authenticated?(*args)
end

#authentication_enabled?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 18

def authentication_enabled?
  return J1App.auth?
end

#category_whitelisted?(*args) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 34

def category_whitelisted?(*args)
  whitelist, user  = *args
  return true if whitelist.include? 'all'
  return true if whitelist.include? user
  return false
end

#existsCookie?(name) ⇒ Boolean


existsCookie? 

Example:

Returns:

  • (Boolean)


157
158
159
160
161
162
163
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 157

def existsCookie? (name)
  if env['HTTP_COOKIE'].include? name
    return true
  else
    return false
  end
end

#has_umlaut?(str) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 55

def has_umlaut? (str)
  !!(str =~ /[öäüÖÄÜß]/)
end

#logout!Object



51
52
53
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 51

def logout!
  warden.logout
end

#merge(input, hash) ⇒ Object


merge: merge two hashes (input <- hash)

Example:
 {% assign nav_bar_options = nav_bar_default | merge: nav_bar_config %}



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 99

def merge(input, hash)
  unless input.respond_to?(:to_hash)
    raise ArgumentError.new("merge filter requires hash arguments: arg_input")
  end
  # if hash to merge is NOT a hash or empty return first hash (input)
  unless hash.respond_to?(:to_hash)
    input
  end
  if hash.nil? || hash.empty?
    input
  else
    merged = input.dup
    hash.each do |k, v|
      merged[k] = v
    end
    merged
  end
end

#payment_activated?(payment) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 41

def payment_activated?(payment)
  return true if payment.any?
  return false
end

#payment_valid?(payment_info) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 46

def payment_valid?(payment_info)
  return true if payment_info.nil?
  return false
end

#public_content?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 4

def public_content?
  return true if request.path_info == '/authentication'
  return true if request.path_info == '/info'
  return true if request.path_info == '/redirect_after_callback'
  !!(J1App.public_content && J1App.public_content.match(request.path_info))
end

#readCookie(name) ⇒ Object


readCookie: 

Example:



140
141
142
143
144
145
146
147
148
149
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 140

def readCookie(name)
  if env['HTTP_COOKIE'].include? name
    session_encoded = request.cookies[name]
    session_decoded = Base64.decode64(session_encoded)
    session_data = JSON.parse(session_decoded)
    return session_data
  else
    return {}
  end
end

#redirect_whitelisted?(redirect) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 11

def redirect_whitelisted?(redirect)
  return true if redirect == '/authentication'
  return true if redirect == '/info'
  return true if redirect == '/redirect_after_callback'
  !!(J1App.public_content && J1App.public_content.match(redirect))
end

#wardenObject



22
23
24
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 22

def warden
  env['warden']
end

#writeCookie(name, data) ⇒ Object


writeCookie: 

Example:



124
125
126
127
128
129
130
131
132
# File 'lib/j1_app/j1_auth_manager/helpers.rb', line 124

def writeCookie(name, data)
  session_encoded = Base64.encode64(data)
  response.set_cookie(
      name,
      domain: false,
      value: session_encoded.to_s,
      path: '/'
  )
end