module J1App::Helpers
Public Instance Methods
authenticate!(*args)
click to toggle source
# File lib/j1_app/j1_auth_manager/helpers.rb, line 26 def authenticate!(*args) warden.authenticate!(*args) end
authenticated?(*args)
click to toggle source
# File lib/j1_app/j1_auth_manager/helpers.rb, line 30 def authenticated?(*args) warden.authenticated?(*args) end
authentication_enabled?()
click to toggle source
# File lib/j1_app/j1_auth_manager/helpers.rb, line 18 def authentication_enabled? return J1App.auth? end
category_whitelisted?(*args)
click to toggle source
# 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
has_umlaut?(str)
click to toggle source
# File lib/j1_app/j1_auth_manager/helpers.rb, line 55 def has_umlaut? (str) !!(str =~ /[öäüÖÄÜß]/) end
log_info!(*args)
click to toggle source
# File lib/j1_app/j1_auth_manager/helpers.rb, line 59 def log_info! (*args) scope, func, text, details = *args if details.nil? message = sprintf( "[%-20s] [%-20s] %s", "#{scope} ", "#{func}", "#{text}" ) else message = sprintf( "[%-20s] [%-20s] %s: %s", "#{scope} ", "#{func}", "#{text}", "#{details}" ) end logger.info "#{message}" end
logout!()
click to toggle source
# File lib/j1_app/j1_auth_manager/helpers.rb, line 51 def logout! warden.logout end
merge(input, hash)
click to toggle source
merge: merge two hashes (input <- hash) Example: {% assign nav_bar_options = nav_bar_default | merge: nav_bar_config %}
# File lib/j1_app/j1_auth_manager/helpers.rb, line 89 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)
click to toggle source
# 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)
click to toggle source
# 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?()
click to toggle source
# 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)
click to toggle source
readCookie: Example:
# File lib/j1_app/j1_auth_manager/helpers.rb, line 130 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)
click to toggle source
# 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
warden()
click to toggle source
# File lib/j1_app/j1_auth_manager/helpers.rb, line 22 def warden env['warden'] end
writeCookie(name, data)
click to toggle source
writeCookie: Example:
# File lib/j1_app/j1_auth_manager/helpers.rb, line 114 def writeCookie(name, data) session_encoded = Base64.encode64(data) response.set_cookie( name, domain: false, value: session_encoded.to_s, path: '/' ) end