module Rack::Reqorder::Monitor::Helpers

Public Instance Methods

authenticate_user!(params) click to toggle source
# File lib/rack/reqorder/monitor/helpers.rb, line 7
def authenticate_user!(params)
  authenticate_user(params) ? true : error!('401 Unauthorized', 401)
end
authorize_user!(headers) click to toggle source
# File lib/rack/reqorder/monitor/helpers.rb, line 3
def authorize_user!(headers)
  authorize_user(headers) ? true : error!('403 Forbidden', 403)
end

Private Instance Methods

authenticate_user(params) click to toggle source
# File lib/rack/reqorder/monitor/helpers.rb, line 25
def authenticate_user(params)
  email = params.user.email
  password = params.user.password

  correct_email = email == Rack::Reqorder.configuration.auth_email
  correct_password = password == Rack::Reqorder.configuration.auth_password

  return (correct_email && correct_password)? true : false
end
authorize_user(headers) click to toggle source

monkeypatch these 2 methods if you want to provide custom authentication/authorization

# File lib/rack/reqorder/monitor/helpers.rb, line 13
def authorize_user(headers)
  token, options = AuthorizationHeader.token_and_options(headers)

  user_email = options.blank?? nil : options[:email]

  correct_email = user_email == Rack::Reqorder.configuration.auth_email
  correct_token = token == user_email_password_md5

  return (correct_email && correct_token) ? true : false
end
user_email_password_md5(user: nil) click to toggle source
# File lib/rack/reqorder/monitor/helpers.rb, line 35
def user_email_password_md5(user: nil)
  #if user.nil?
  Digest::MD5.hexdigest(
    Rack::Reqorder.configuration.auth_email +
    Rack::Reqorder.configuration.auth_password
  )
  #else
  #end
end