Changeset 3891

Show
Ignore:
Timestamp:
12/31/07 19:50:25 (7 years ago)
Author:
norio_s
Message:

change user auth

Location:
websites/feedlist/app/controllers
Files:
2 modified
1 moved

Legend:

Unmodified
Added
Removed
  • websites/feedlist/app/controllers/application.rb

    r3812 r3891  
    1 # Filters added to this controller apply to all controllers in the application. 
    2 # Likewise, all the methods added will be available for all controllers. 
    3  
    41class ApplicationController < ActionController::Base 
    52  helper :all 
  • websites/feedlist/app/controllers/sessions_controller.rb

    r3812 r3891  
    11# This controller handles the login/logout function of the site.   
    2 class SessionController < ApplicationController 
     2class SessionsController < ApplicationController 
    33  open_id_consumer :required => [:email, :nickname] 
    44 
     
    1313      if params[:remember_me] == "1" 
    1414        self.current_user.remember_me 
    15         cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } 
     15        cookies[:auth_token] = {  
     16          :value   => self.current_user.remember_token, 
     17          :expires => self.current_user.remember_token_expires_at } 
    1618      end 
    1719      redirect_back_or_default('/') 
     
    3638    # will return HTTP_FAILURE or PARSE_ERROR. Let the user know that the URL is unusable. 
    3739    case open_id_response.status 
    38       when OpenID::SUCCESS 
     40      when OpenID::Consumer::SUCCESS 
    3941        # The URL was a valid identity URL. Now we just need to send a redirect 
    4042        # to the server using the redirect_url the library created for us. 
     
    5052  def complete 
    5153    case open_id_response.status 
    52       when OpenID::FAILURE 
     54      when OpenID::Consumer::FAILURE 
    5355        # In the case of failure, if info is non-nil, it is the URL that we were verifying.  
    5456        # We include it in the error message to help the user figure out what happened. 
     
    5961        end 
    6062        flash[:notice] += open_id_response.msg.to_s 
    61       when OpenID::SUCCESS 
     63      when OpenID::Consumer::SUCCESS 
    6264        # Success means that the transaction completed without error. If info is nil,  
    6365        # it means that the user cancelled the verification. 
    6466        flash[:notice] = "You have successfully verified #{open_id_response.identity_url} as your identity." 
    65         if open_id_fields.any? 
    66           @user   = User.find_by_open_id_url(open_id_response.identity_url) 
    67           @user ||= User.new(:open_id_url => open_id_response.identity_url) 
    68           @user.login       = open_id_fields['nickname'] if open_id_fields['nickname'] 
    69           @user.email       = open_id_fields['email']    if open_id_fields['email']           
    70           if @user.save 
    71             self.current_user = @user 
    72             if params[:remember_me] == "1" 
    73               self.current_user.remember_me 
    74               cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } 
    75             end 
    76             flash[:notice] = "You have successfully verified #{open_id_response.identity_url} as your identity." 
    77             return redirect_back_or_default('/') 
    78           else 
    79             flash[:notice] = @user.errors.full_messages.join('<br />') 
    80             render :action => 'new' and return 
     67        @user   = User.find_or_initialize_by_open_id_url(open_id_response.identity_url) 
     68        @user.login ||= open_id_fields['nickname'] || url_to_id(open_id_response.identity_url) 
     69        @user.email ||= open_id_fields['email'] if open_id_fields['email']           
     70        if @user.save 
     71          self.current_user = @user 
     72          if params[:remember_me] == "1" 
     73            self.current_user.remember_me 
     74            cookies[:auth_token] = {  
     75              :value   => self.current_user.remember_token,  
     76              :expires => self.current_user.remember_token_expires_at } 
    8177          end 
     78          flash[:notice] = "You have successfully verified #{open_id_response.identity_url} as your identity. And logged in." 
     79          return redirect_back_or_default('/') 
     80        else 
     81          flash[:notice] = @user.errors.full_messages.join('<br />') 
     82          render :action => 'new' and return 
    8283        end 
    8384      when OpenID::CANCEL 
     
    8889    redirect_to :action => 'new' 
    8990  end 
     91   
     92private 
     93  def url_to_id(url) 
     94    url.gsub(/^https?:\/\/|\/$/, '').gsub(/\.|\//, '-') 
     95  end 
    9096end 
  • websites/feedlist/app/controllers/users_controller.rb

    r3812 r3891  
    11class UsersController < ApplicationController 
    2   # Be sure to include AuthenticationSystem in Application Controller instead 
    3   include AuthenticatedSystem 
    4   # If you want "remember me" functionality, add this before_filter to Application Controller 
    5   before_filter :login_from_cookie 
    6  
    7   # render new.rhtml 
    82  def new 
     3    @user = User.new 
    94  end 
    105 
     
    1813    render :action => 'new' 
    1914  end 
    20  
    2115end