class RestPack::Web::Context
Attributes
account[RW]
application[RW]
domain[RW]
user[RW]
Public Class Methods
new(env)
click to toggle source
# File lib/restpack_web/context.rb, line 5 def initialize(env) restpack = env['restpack'] if restpack @domain = restpack[:domain] @application = restpack[:application] @user = restpack[:user] @account = restpack[:account] end end
Public Instance Methods
account_id()
click to toggle source
# File lib/restpack_web/context.rb, line 24 def account_id authenticated? ? @account[:id] : nil end
application_id()
click to toggle source
# File lib/restpack_web/context.rb, line 28 def application_id @application[:id] end
auth_domain()
click to toggle source
# File lib/restpack_web/context.rb, line 40 def auth_domain "auth.#{@domain[:identifier]}" end
authenticated?()
click to toggle source
# File lib/restpack_web/context.rb, line 16 def authenticated? !@user.nil? end
debug_info()
click to toggle source
# File lib/restpack_web/context.rb, line 53 def debug_info "todo" end
domain_id()
click to toggle source
# File lib/restpack_web/context.rb, line 32 def domain_id @domain[:id] end
home_domain()
click to toggle source
# File lib/restpack_web/context.rb, line 36 def home_domain "www.#{@domain[:identifier]}" end
login_url(provider = :twitter, next_url = nil)
click to toggle source
# File lib/restpack_web/context.rb, line 49 def login_url(provider = :twitter, next_url = nil) auth_url("/auth/#{provider}", next_url) end
logout_url(next_url = nil)
click to toggle source
# File lib/restpack_web/context.rb, line 44 def logout_url(next_url = nil) next_url ||= "http://#{home_domain}/" auth_url('/auth/logout', next_url) end
user_id()
click to toggle source
# File lib/restpack_web/context.rb, line 20 def user_id authenticated? ? @user[:id] : nil end
Private Instance Methods
auth_url(path, next_url = nil)
click to toggle source
# File lib/restpack_web/context.rb, line 59 def auth_url(path, next_url = nil) #TODO: GJ: whitelist the next_url? #TODO: GJ: URI encode next_url? port = RestPack::Web.config.authentication_port port_part = port ? ":#{port}" : "" next_part = next_url ? "?next=#{next_url}" : "" "http://#{auth_domain}#{port_part}#{path}#{next_part}" end