Changeset 127

Show
Ignore:
Timestamp:
11/21/05 02:29:53 (3 years ago)
Author:
lazyatom
Message:

Updated login engine to 0.1.5

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/login_engine/README

    r95 r127  
    9191=== Create the DB schema 
    9292 
    93 After you have done the modifications the the ApplicationController and its helper, you can import the user model into the database. An ActiveRecord schema.rb file is provided in login_engine/db/schema.rb. You should check that this file isn't going to interfere with anything in your application. You can set the table name used by adding 
     93After you have done the modifications the the ApplicationController and its helper, you can import the user model into the database. An ActiveRecord schema.rb file is provided in login_engine/db/schema.rb, along with migration information in login_engine/db/migrate/.  
     94 
     95You *MUST* check that these files aren't going to interfere with anything in your application.  
     96 
     97You can change the table name used by adding 
    9498 
    9599  module LoginEngine 
     
    100104  end 
    101105 
    102 To the LoginEngine configuration in <tt>environment.rb</tt>. Then run from the root of your project: 
    103  
    104   rake import_login_engine_schema 
     106...to the LoginEngine configuration in <tt>environment.rb</tt>. Then run from the root of your project: 
     107 
     108  rake engine_migrate ENGINE=login 
    105109 
    106110to import the schema into your database. 
     
    115119... somewhere in the <head> section of your HTML layout file. 
    116120 
     121== Integrate flash messages into your layout 
     122 
     123LoginEngine does not display any flash messages in the views it contains, and thus you must display them yourself. This allows you to integrate any flash messages into your existing layout. LoginEngine adheres to the emerging flash usage standard, namely: 
     124 
     125* :warning - warning (failure) messages 
     126* :notice - success messages 
     127* :message - neutral (reminder, informational) messages 
     128 
     129This gives you the flexibility to theme the different message classes separately. In your layout you should check for and display flash[:warning], flash[:notice] and flash[:message]. For example: 
     130 
     131  <% for name in [:notice, :warning, :message] %> 
     132    <% if flash[name] %> 
     133      <%= "<div id=\"#{name}\">#{flash[name]}</div>" %> 
     134    <% end %> 
     135  <% end %> 
     136 
     137Alternately, you could look at using the flash helper plugin (available from https://opensvn.csie.org/traccgi/flash_helper_plugin/trac.cgi/), which supports the same naming convention. 
    117138 
    118139 
  • plugins/login_engine/app/controllers/user_controller.rb

    r96 r127  
    3939      User.transaction(@user) do 
    4040        @user.new_password = true 
    41         unless LoginEngine.config(:use_email_notification) 
     41        unless LoginEngine.config(:use_email_notification) and LoginEngine.config(:confirm_account) 
    4242          @user.verified = 1 
    4343        end 
    4444        if @user.save 
    4545          key = @user.generate_security_token 
    46           url = url_for(:action => 'home', 'user[id]' => @user.id, :key => key) 
     46          url = url_for(:action => 'home', :user_id => @user.id, :key => key) 
    4747          flash[:notice] = 'Signup successful! Please log in.' 
    48           if LoginEngine.config(:use_email_notification) 
     48          if LoginEngine.config(:use_email_notification) and LoginEngine.config(:confirm_account) 
    4949            UserNotify.deliver_signup(@user, params[:user][:password], url) 
    5050            flash[:notice] << ' Please check your registered email account to verify your account registration and continue with the login.' 
     
    5656      flash.now[:notice] = nil 
    5757      flash.now[:warning] = 'Error creating account: confirmation email not sent' 
     58      logger.error "Unable to send confirmation E-Mail:" 
    5859      logger.error e 
    5960    end 
     
    127128        User.transaction(user) do 
    128129          key = user.generate_security_token 
    129           url = url_for(:action => 'change_password', 'user[id]' => user.id, :key => key) 
     130          url = url_for(:action => 'change_password', :user_id => user.id, :key => key) 
    130131          UserNotify.deliver_forgot_password(user, url) 
    131132          flash[:notice] = "Instructions on resetting your password have been emailed to #{params[:user][:email]}" 
     
    181182            key = user.set_delete_after 
    182183            if LoginEngine.config(:use_email_notification) 
    183               url = url_for(:action => 'restore_deleted', 'user[id]' => user.id, :key => key) 
     184              url = url_for(:action => 'restore_deleted', :user_id => user.id, :key => key) 
    184185              UserNotify.deliver_pending_delete(user, url) 
    185186            end 
  • plugins/login_engine/lib/login_engine.rb

    r66 r127  
    5656  config :use_email_notification, true 
    5757 
     58  # Controls whether accounts must be confirmed after signing up 
     59  # ONLY if this and use_email_notification are both true 
     60  config :confirm_account, true 
     61 
    5862end 
  • plugins/login_engine/lib/login_engine/authenticated_system.rb

    r96 r127  
    9696 
    9797      # If not, is the user being authenticated by a token? 
    98       return false if not params[:user] 
    99       id = params[:user][:id] 
     98      id = params[:user_id] 
    10099      key = params[:key] 
    101100      if id and key 
  • plugins/login_engine/lib/login_engine/authenticated_user.rb

    r62 r127  
    3838     
    3939      def authenticate(login, pass) 
    40         u = find_first(["login = ? AND verified = 1 AND deleted = 0", login]) 
     40        u = find(:first, :conditions => ["login = ? AND verified = 1 AND deleted = 0", login]) 
    4141        return nil if u.nil? 
    42         find_first(["login = ? AND salted_password = ? AND verified = 1", login, AuthenticatedUser.salted_password(u.salt, AuthenticatedUser.hashed(pass))]) 
     42        find(:first, :conditions => ["login = ? AND salted_password = ? AND verified = 1", login, AuthenticatedUser.salted_password(u.salt, AuthenticatedUser.hashed(pass))]) 
    4343      end 
    4444 
     
    4646        # Allow logins for deleted accounts, but only via this method (and 
    4747        # not the regular authenticate call) 
    48         u = find_first(["id = ? AND security_token = ?", id, token]) 
     48        u = find(:first, :conditions => ["id = ? AND security_token = ?", id, token]) 
    4949        return nil if u.nil? or u.token_expired? 
    5050        return nil if false == u.update_expiry 
  • plugins/login_engine/test/functional/user_controller_test.rb

    r88 r127  
    11require File.dirname(__FILE__) + '/../test_helper' 
    22require_dependency 'user_controller' 
    3 require 'breakpoint' 
    43 
    54 
     
    98class UserControllerTest < Test::Unit::TestCase 
    109   
    11   fixtures LoginEngine.config(:user_table).to_sym 
     10  # load the fixture into the developer-specified table using the custom 
     11  # 'fixture' method. 
     12  fixture :users, :table_name => LoginEngine.config(:user_table), :class_name => "User" 
    1213   
    1314  def setup 
     
    4849    assert_response 302  # redirect 
    4950    assert_session_has :user 
    50     assert_equal fixture_object(LoginEngine.config(:user_table).to_sym, :bob), session[:user] 
     51    assert_equal users(:bob), session[:user] 
    5152     
    5253    assert_redirect_url "http://#{@request.host}/bogus/location" 
     
    8788    assert_match /login:\s+\w+\n/, mail.encoded 
    8889    assert_match /password:\s+\w+\n/, mail.encoded 
    89     mail.encoded =~ /key=(.*?)"/ 
    90     key = $1 
     90    mail.encoded =~ /user_id=(.*?)&key=(.*?)"/ 
     91    user_id = $1 
     92    key = $2 
    9193 
    9294    user = User.find_by_email("newbob@test.com") 
     
    9698    # First past the expiration. 
    9799    Time.advance_by_days = 1 
    98     get :home, :user=> { "id" => "#{user.id}" }, "key" => "#{key}" 
     100    get :home, :user_id => "#{user_id}", :key => "#{key}" 
    99101    Time.advance_by_days = 0 
    100102    user = User.find_by_email("newbob@test.com") 
     
    102104 
    103105    # Then a bogus key. 
    104     get :home, :user=> { "id" => "#{user.id}" }, "key" => "boguskey" 
     106    get :home, :user_id => "#{user_id}", :key => "boguskey" 
    105107    user = User.find_by_email("newbob@test.com") 
    106108    assert_equal 0, user.verified 
    107109 
    108110    # Now the real one. 
    109     get :home, :user=> { "id" => "#{user.id}" }, "key" => "#{key}" 
     111    get :home, :user_id => "#{user_id}", :key => "#{key}" 
    110112    user = User.find_by_email("newbob@test.com") 
    111113    assert_equal 1, user.verified 
     
    247249    assert_equal 1, ActionMailer::Base.deliveries.size 
    248250    mail = ActionMailer::Base.deliveries[0] 
    249     mail.encoded =~ /user\[id\]=(.*?)&key=(.*?)"/ 
     251    mail.encoded =~ /user_id=(.*?)&key=(.*?)"/ 
    250252    id = $1 
    251253    key = $2 
    252254     
    253     post :restore_deleted, :user => { "id" => "#{id}" }, "key" => "badkey" 
     255    post :restore_deleted, :user_id => "#{id}", "key" => "badkey" 
    254256    assert_session_has_no :user 
    255257 
    256258    # Advance the time past the delete date 
    257259    Time.advance_by_days = LoginEngine.config :delayed_delete_days 
    258     post :restore_deleted, :user => { "id" => "#{id}" }, "key" => "#{key}" 
     260    post :restore_deleted, :user_id => "#{id}", "key" => "#{key}" 
    259261    assert_session_has_no :user 
    260262    Time.advance_by_days = 0 
    261263 
    262     post :restore_deleted, :user => { "id" => "#{id}" }, "key" => "#{key}" 
     264    post :restore_deleted, :user_id => "#{id}", "key" => "#{key}" 
    263265    assert_session_has :user       
    264266  end 
     
    342344    post :change_password, :user => { :password => "changed_password", :password_confirmation => "changed_password" } 
    343345     
    344     assert_success 
     346    assert_redirected_to :action => "change_password" 
    345347 
    346348    post :login, :user => { :login => "bob", :password => "changed_password" } 
     
    453455        mail = ActionMailer::Base.deliveries[0] 
    454456        assert_equal "bob@test.com", mail.to_addrs[0].to_s 
    455         mail.encoded =~ /user\[id\]=(.*?)&key=(.*?)"/ 
     457        mail.encoded =~ /user_id=(.*?)&key=(.*?)"/ 
    456458        id = $1 
    457459        key = $2 
    458         post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}", :id => "#{id}" }, :key => "#{key}" 
     460        post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}"}, :user_id => "#{id}", :key => "#{key}" 
    459461        assert_session_has :user 
    460462        get :logout 
  • plugins/login_engine/test/test_helper.rb

    r83 r127  
    11require File.dirname(__FILE__) + '/../../../../test/test_helper' # the default rails helper 
     2 
     3# ensure that the Engines testing enhancements are loaded. 
     4require File.join(Engines.config(:root), "engines", "lib", "testing_extensions") 
    25 
    36require File.dirname(__FILE__) + '/mocks/time' 
    47require File.dirname(__FILE__) + '/mocks/mail' 
    58 
    6 # TODO: Add check for database-specific sql files instead 
     9# Load the schema - if migrations have been performed, this will be up to date. 
    710load(File.dirname(__FILE__) + "/../db/schema.rb") 
    811 
     
    1013Test::Unit::TestCase.fixture_path = File.dirname(__FILE__)  + "/fixtures/" 
    1114$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path) 
    12  
    13  
    14 # declare mappings between your fixtures templates and the actual table names used. 
    15 Test::Unit::TestCase.set_fixtures_table(:users, LoginEngine.config(:user_table)) 
  • plugins/login_engine/test/unit/user_test.rb

    r89 r127  
    11require File.dirname(__FILE__) + '/../test_helper' 
     2class UserTest < Test::Unit::TestCase 
    23 
    3 class UserTest < Test::Unit::TestCase 
    4    
    5   fixtures LoginEngine.config(:user_table).to_sym 
     4  # load the fixture into the developer-specified table using the custom 
     5  # 'fixture' method. 
     6  fixture :users, :table_name => LoginEngine.config(:user_table), :class_name => "User" 
    67  
    78  def setup 
     
    1011     
    1112  def test_auth    
    12     assert_equal fixture_object(LoginEngine.config(:user_table), :bob), User.authenticate("bob", "atest")     
     13    assert_equal users(:bob), User.authenticate("bob", "atest")     
    1314    assert_nil User.authenticate("nonbob", "atest") 
    1415  end 
     
    1718  def test_passwordchange 
    1819         
    19     fixture_object(LoginEngine.config(:user_table), :longbob).change_password("nonbobpasswd") 
    20     fixture_object(LoginEngine.config(:user_table), :longbob).save 
    21     assert_equal fixture_object(LoginEngine.config(:user_table), :longbob), User.authenticate("longbob", "nonbobpasswd") 
     20    users(:longbob).change_password("nonbobpasswd") 
     21    users(:longbob).save 
     22    assert_equal users(:longbob), User.authenticate("longbob", "nonbobpasswd") 
    2223    assert_nil User.authenticate("longbob", "alongtest") 
    23     fixture_object(LoginEngine.config(:user_table), :longbob).change_password("alongtest") 
    24     fixture_object(LoginEngine.config(:user_table), :longbob).save 
    25     assert_equal fixture_object(LoginEngine.config(:user_table), :longbob), User.authenticate("longbob", "alongtest") 
     24    users(:longbob).change_password("alongtest") 
     25    users(:longbob).save 
     26    assert_equal users(:longbob), User.authenticate("longbob", "alongtest") 
    2627    assert_nil User.authenticate("longbob", "nonbobpasswd") 
    2728