Sha256: 70ceae9173d6c4eb303c3e33e40e523ca782b5ca7ea0bc6e273f02527aad837b
Contents?: true
Size: 1.41 KB
Versions: 6
Compression:
Stored size: 1.41 KB
Contents
require 'public_suffix' module RestPack module Web class Context attr_accessor :domain, :application, :channel, :configurations, :services, :user, :user_id, :request def initialize(env) restpack = env[:restpack] if restpack @request = restpack[:request] @domain = restpack[:domain] @application = restpack[:application] @channel = restpack[:channel] @configurations = restpack[:configurations] @services = restpack[:services] @user = restpack[:user] @user_id = @user[:id] if @user end end def is_authenticated? @user.present? end def get_service(name) @services.find { |s| s[:name] == name.to_s } end def home_domain @application.home_domain || "www.#{root_domain}" end def auth_domain @application.auth_domain || "auth.#{root_domain}" end def root_domain PublicSuffix.parse(@domain.host).domain end def logout_url(next_url = nil) #TODO: GJ: whitelist the next_url next_url ||= "http://#{home_domain}/" "http://#{auth_domain}/auth/logout?next=#{next_url}" end def login_url(provider = :twitter, next_url = nil) next_url ||= "http://#{home_domain}/" "http://#{auth_domain}/auth/#{provider}?next=#{next_url}" end end end end
Version data entries
6 entries across 6 versions & 1 rubygems