module Flatspace::Helpers::Request

Public Instance Methods

authorized?() click to toggle source

Check if authorized

# File lib/flatspace/request.rb, line 28
def authorized?
  @auth ||= Rack::Auth::Basic::Request.new(request.env)
  @auth.provided? and @auth.basic? and @auth.credentials and @auth.credentials == ['admin', 'test54']
end
e() click to toggle source

Short cut for setting up errors

# File lib/flatspace/request.rb, line 58
def e;@e ||= [];end
f() click to toggle source
# File lib/flatspace/request.rb, line 39
def f;flash;end
go(path, options = {}) click to toggle source

Redirect and optionally set flash

# File lib/flatspace/request.rb, line 44
def go(path, options = {})
  f[:i] = options[:i] if options[:i]
  f[:e] = options[:e] if options[:e]
  redirect(path)
end
green(text) click to toggle source

Colorize input green or red

# File lib/flatspace/request.rb, line 34
def green(text);"\e[33m#{text}\e[0m";end
h(val) click to toggle source
# File lib/flatspace/request.rb, line 41
def h(val);halt(val);end
login() click to toggle source

Require login

# File lib/flatspace/request.rb, line 8
def login
  return if s[:u]
  path = request.path.split('?')[0]
  return if %w[/ /login /docs].find{|r| path.start_with?(r)}
  redirect('/login')
end
now(view, options = {}) click to toggle source

Like above, but sets flash.now and halts with template

# File lib/flatspace/request.rb, line 51
def now(view, options = {})
  f.now[:i] = options[:i] if options[:i]
  f.now[:e] = options[:e] if options[:e]
  h erb(view)
end
p() click to toggle source

Flash and halt short cuts

# File lib/flatspace/request.rb, line 38
def p;@p||=params.strip;end
password_valid?() click to toggle source

Password valid?

# File lib/flatspace/request.rb, line 16
def password_valid?
  @profile and (@profile[:md5] == Digest::MD5.hexdigest(p[:password] + @profile[:salt]))
end
protect!() click to toggle source

Basic auth

# File lib/flatspace/request.rb, line 21
def protect!
  return if authorized?
  headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"'
  halt 401, "Not authorized\n"
end
red(text) click to toggle source
# File lib/flatspace/request.rb, line 35
def red(text);"\e[31m#{text}\e[0m";end
s() click to toggle source
# File lib/flatspace/request.rb, line 40
def s;session;end