Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8033: open_id_cleanup.diff

File open_id_cleanup.diff, 4.3 kB (added by monki, 1 year ago)

Fix/cleanup. (I needed to upgrade rubygems, but it should use the new non-deprecated includes)

  • test/open_id_authentication_test.rb

    old new  
    2828  end 
    2929 
    3030  def test_authentication_should_fail_when_the_identity_server_times_out 
    31     @controller.stubs(:open_id_consumer).returns(stub(:begin => Proc.new { raise Timeout::Error })) 
     31    @controller.stubs(:open_id_consumer).returns(stub(:begin => Proc.new { raise(Timeout::Error, "Identity server timed out") })) 
    3232 
    3333    @controller.send(:authenticate_with_open_id, "http://someone.example.com") do |result, identity_url| 
    3434      assert result.missing? 
  • lib/open_id_authentication.rb

    old new  
    4040    def message 
    4141      ERROR_MESSAGES[@code] 
    4242    end 
     43     
     44    attr_reader :code 
    4345  end 
    4446 
    4547  def self.normalize_url(url) 
  • README

    old new  
    4545app/views/sessions/new.erb 
    4646 
    4747  <% form_tag(session_url) do %> 
     48    <p style="color: red"><%= flash[:error] %></ 
     49   
    4850    <p> 
    4951      <label for="name">Username:</label> 
    5052      <%= text_field_tag "name" %> 
     
    6567    </p> 
    6668 
    6769    <p> 
    68       <%= submit_tag 'Sign in', :disable_with => "Signing in&hellip;" %> 
     70      <%= submit_tag 'Sign in', :disable_with => "Signing in..." %> 
    6971    </p> 
    7072  <% end %> 
    7173 
     
    8284 
    8385    protected 
    8486      def password_authentication(name, password) 
    85         if @current_user = @account.users.authenticate(params[:name], params[:password]) 
     87        if @current_user = User.authenticate(params[:name], params[:password]) 
    8688          successful_login 
    8789        else 
    8890          failed_login "Sorry, that username/password doesn't work" 
     
    9193 
    9294      def open_id_authentication 
    9395        authenticate_with_open_id do |result, identity_url| 
    94           case result 
     96          case result.code 
    9597          when :missing 
    9698            failed_login "Sorry, the OpenID server couldn't be found" 
    9799          when :canceled 
     
    99101          when :failed 
    100102            failed_login "Sorry, the OpenID verification failed" 
    101103          when :successful 
    102             if @current_user = @account.users.find_by_identity_url(identity_url) 
     104            if @current_user = User.find_by_identity_url(identity_url) 
    103105              successful_login 
    104106            else 
    105               failed_login "Sorry, no user by that identity URL exists (#{identity_url})") 
     107              failed_login "Sorry, no user by that identity URL exists (#{identity_url})" 
    106108            end 
    107109          end 
    108110        end 
     
    128130 
    129131    def open_id_authentication 
    130132      authenticate_with_open_id do |result, identity_url| 
    131         if result.successful? && @current_user = @account.users.find_by_identity_url(identity_url) 
     133        if result.successful? && @current_user = User.find_by_identity_url(identity_url) 
    132134          successful_login 
    133135        else 
    134           failed_login(result.message || "Sorry, no user by that identity URL exists (#{identity_url})") 
     136          failed_login(result.message || "Sorry, no user by that identity URL exists (#{identity_url})" 
    135137        end 
    136138      end 
    137139    end 
     
    149151        # Be sure to yield registration, a third argument in the #authenticate_with_open_id block. 
    150152        authenticate_with_open_id(identity_url,  
    151153            :required => [ :nickname, :email ], 
    152             :optional => :fullname) do |status, identity_url, registration| 
    153           case status 
     154            :optional => :fullname) do |result, identity_url, registration| 
     155          case result.code 
    154156          when :missing 
    155157            failed_login "Sorry, the OpenID server couldn't be found" 
    156158          when :canceled 
     
    158160          when :failed 
    159161            failed_login "Sorry, the OpenID verification failed" 
    160162          when :successful 
    161             if @current_user = @account.users.find_by_identity_url(identity_url) 
     163            if @current_user = User.find_by_identity_url(identity_url) 
    162164              assign_registration_attributes!(registration) 
    163165 
    164166              if current_user.save