Advertisement
Guest User

Untitled

a guest
Jul 28th, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.73 KB | None | 0 0
  1. require 'net/http'
  2. require 'uri'
  3. require 'rest_client'
  4. require 'authentication/make_session'
  5. class HomeController < ApplicationController
  6.    before_filter :init_variables
  7.  
  8.  
  9.  def init_variables
  10.    initialize_variables
  11.  end
  12.  
  13.   def index
  14.       @accept = 'text/plain'
  15.       @content_type = 'text/plain'
  16.       @authorization = session[:auth]
  17.       #get_response_with_auth("http://55.7.28.210:4321/TSI-Dev/")
  18.       RestClient.log = '/home/aroux/workspace/UPM/UPM-workspace/user-profil-manager/mylog.error'
  19.       @responses = RestClient.get "http://55.7.28.210:4321/TSI-Dev/", :accept => @accept, :authorization => @authorization
  20.      
  21.   end
  22.  
  23.  
  24.  
  25.   def get_response_with_auth(url)
  26.       url_parsed = URI.parse(url)
  27.      
  28.       @response = Net::HTTP.start(url_parsed.host, url_parsed.port) {|http|
  29.             @req = http.get('/', {'Authorization' => @authorization, 'Accept' => @accept})
  30.       }
  31.   end
  32.  
  33. end
  34.  
  35.  
  36.  
  37. From Gem authentication :
  38.  
  39.  
  40.   def initialize_variables
  41.     if request.env["HTTP_AUTHORIZATION"].nil?
  42.       if APP_CONFIG['routes_login_path'].nil?
  43.           redirect_to login_path
  44.       else
  45.           redirect_to APP_CONFIG['routes_login_path']
  46.       end
  47.     else
  48.       if !request.env['REMOTE_USER'].nil?
  49.         session[:user]=request.env['REMOTE_USER']
  50.         session[:auth]=request.env["HTTP_AUTHORIZATION"]
  51.       end
  52.     end
  53.   end
  54.  
  55.  
  56.  
  57.  
  58. In the application controller i use :
  59.  
  60.  def is_logged?
  61.   if request.env["HTTP_AUTHORIZATION"].nil? && session[:auth].nil?
  62.        if APP_CONFIG['routes_login_path'].nil?
  63.             redirect_to login_path
  64.        else
  65.             redirect_to APP_CONFIG['routes_login_path']
  66.        end
  67.   end
  68. end
  69.  
  70. To verify if i'm logged (in all of my applications)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement