Changeset 362

Show
Ignore:
Timestamp:
04/10/06 08:50:08 (3 years ago)
Author:
snowblink
Message:

Merged rb_1.0 (r298:361) into trunk
This corresponds to the tagged release 1.0.1

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • login_engine/trunk/CHANGELOG

    r303 r362  
    1 *SVN* 
     1= v1.1.0 
     2 *  Added 'full_name' method to user object 
     3 *  Added 'for' attributes to form_helper labels (Ticket #82) 
     4 *  Default table names now respect any set prefix/suffix from ActiveRecord (Ticket #67) 
     5 *  Removed errant closing DIV tag in views/user/edit.rhtml (Ticket #68) 
     6 *  do_delete_user() should delete the user given as a parameter, not @user (Ticket #65) 
    27 
    3 - Added 'full_name' method to user object 
    4  
    5 --- 
    6 1.0.1 
    7  
    8 - Added 'for' attributes to form_helper labels (Ticket #82) 
    9 - Default table names now respect any set prefix/suffix from ActiveRecord (Ticket #67) 
    10 - Removed errant closing DIV tag in views/user/edit.rhtml (Ticket #68) 
    11 - do_delete_user() should delete the user given as a parameter, not @user (Ticket #65) 
     8= v1.0.1 
     9 * Added CHANGELOG 
     10 * Changed wording for when password forgotten to 'reset', rather than 'retrieve'. (snowblink@gmail.com) 
     11 * Fixed new location of engines testing extensions. (lazyatom@gmail.com) 
     12 * Removed schema.db from Login Engine; migrations should be used instead. (snowblink@gmail.com) 
     13 * Updated User Controller tests to parse the user_id and email out of the URL in the email body. (snowblink@gmail.com) 
     14 * Ticket #89 (lazyatom@gmail.com) User creation halts the after_save callback chain. 
     15 * Ticket #97 (dcorbin@machturtle.com) The forgotten_password view generates invalid HTML 
     16 * Ticket #112 (segabor@gmail.com) Authentication system will break even on successful login 
     17 * Added simple email validation to the User model. (snowblink@gmail.com) 
     18   This should also take care of the unit test failures detailed in Ticket #114 (morris@wolfman.com) 
     19 * Ticket #118 (augustz@augustz.com) SVN source for login_engine not found 
     20 * Ticket #119 (Goynang) Unit tests for engines fail after default install 
     21 * Ticket #126 (lazyatom@gmail.com) Add install.rb to login engine 
  • login_engine/trunk/README

    r298 r362  
    1717Installing the Login Engine is fairly simple. You can use either Rails' own built in plugin manager (since Engines are still plugins), or SVN itself if you are happier with that. 
    1818 
    19 === <tt>script/plugin</tt> 
    20  
    21   $ ruby script/plugin discover 
    22   $ ruby script/plugin install engines 
    23   $ ruby script/plugin install login_engine 
    24  
    25 === SVN 
    26  
    27   $ cd your_app_directory 
    28   % svn co http://opensvn.csie.org/rails_engines/plugins/engines 
    29   % svn co http://opensvn.csie.org/rails_engines/plugins/login_engine 
    30  
     19Your options are: 
     20==== Install as a rails plugin: 
     21      $ ruby script/plugin discover 
     22      $ ruby script/plugin install engines 
     23      $ script/plugin install login_engine 
     24==== Use svn:externals 
     25      $ svn propedit svn:externals vendor/plugins 
     26 
     27      You can choose to use the latest stable release: 
     28          login_engine http://svn.rails-engines.org/plugins/login_engine 
     29 
     30      Or a tagged release (recommended for releases of your code): 
     31          login_engine http://svn.rails-engines.org/logine_engine/tags/<TAGGED_RELEASE> 
    3132 
    3233=== Setup your Rails application 
     
    294295 
    295296Currently, since not all databases appear to support structure cloning, the tests will load the entire schema into your test database, potentially blowing away any other test structures you might have. If this presents an issue for your application, comment out the line in test/test_helper.rb 
     297 
     298= Database Schema Details 
     299 
     300You need a database table corresponding to the User model. This is provided as a Rails Schema file, but the schema is presented below for information. Note the table type for MySQL. Whatever DB you use, it must support transactions. If it does not, the functional tests will not work properly, nor will the application in the face of failures during certain DB creates and updates. 
     301 
     302  mysql syntax: 
     303  CREATE TABLE users ( 
     304    id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 
     305    login VARCHAR(80) NOT NULL, 
     306    salted_password VARCHAR(40) NOT NULL, 
     307    email VARCHAR(60) NOT NULL, 
     308    firstname VARCHAR(40), 
     309    lastname VARCHAR(40), 
     310    salt CHAR(40) NOT NULL, 
     311    verified INT default 0, 
     312    role VARCHAR(40) default NULL, 
     313    security_token CHAR(40) default NULL, 
     314    token_expiry DATETIME default NULL, 
     315    deleted INT default 0, 
     316    delete_after DATETIME default NULL 
     317  ) TYPE=InnoDB DEFAULT CHARSET=utf8; 
     318 
     319  postgres: 
     320  CREATE TABLE "users" ( 
     321    id SERIAL PRIMARY KEY 
     322    login VARCHAR(80) NOT NULL, 
     323    salted_password VARCHAR(40) NOT NULL, 
     324    email VARCHAR(60) NOT NULL, 
     325    firstname VARCHAR(40), 
     326    lastname VARCHAR(40), 
     327    salt CHAR(40) NOT NULL, 
     328    verified INT default 0, 
     329    role VARCHAR(40) default NULL, 
     330    security_token CHAR(40) default NULL, 
     331    token_expiry TIMESTAMP default NULL, 
     332    deleted INT default 0, 
     333    delete_after TIMESTAMP default NULL 
     334  ) WITH OIDS; 
     335 
     336  sqlite: 
     337  CREATE TABLE 'users' ( 
     338    id INTEGER PRIMARY KEY, 
     339    login VARCHAR(80) NOT NULL, 
     340    salted_password VARCHAR(40) NOT NULL, 
     341    email VARCHAR(60) NOT NULL, 
     342    firstname VARCHAR(40), 
     343    lastname VARCHAR(40), 
     344    salt CHAR(40) NOT NULL, 
     345    verified INT default 0, 
     346    role VARCHAR(40) default NULL, 
     347    security_token CHAR(40) default NULL, 
     348    token_expiry DATETIME default NULL, 
     349    deleted INT default 0, 
     350    delete_after DATETIME default NULL 
     351  ); 
     352 
     353Of course your user model can have any amount of extra fields. This is just a starting point. 
  • login_engine/trunk/app/views/user/forgot_password.rhtml

    r44 r362  
    88 
    99    <%= start_form_tag_helper %> 
    10       <%= form_input :text_field, 'Email Address', 'email', :size => 30 %><br/
     10      <label>Email Address:</label> <%= text_field("user", "email", "size" => 30) %
    1111 
    1212      <div class="button-bar"> 
  • login_engine/trunk/lib/login_engine/authenticated_system.rb

    r201 r362  
    5555      # call overwriteable reaction to unauthorized access 
    5656      access_denied 
    57       return false  
    5857    end 
    5958 
  • login_engine/trunk/lib/login_engine/authenticated_user.rb

    r303 r362  
    2121        validates_uniqueness_of :login 
    2222        validates_uniqueness_of :email 
     23        validates_format_of :email, :with => /^[^@]+@.+$/ 
    2324 
    2425        validates_confirmation_of :password, :if => :validate_password? 
     
    3031        attr_accessor :password, :password_confirmation 
    3132       
    32         after_save '@new_password = false' 
     33        after_save :falsify_new_password 
    3334        after_validation :crypt_password 
    34        
     35 
    3536      end 
    3637      base.extend(ClassMethods) 
     
    136137    end 
    137138 
     139    def falsify_new_password 
     140      @new_password = false 
     141      true 
     142    end 
     143 
    138144    def new_security_token(hours = nil) 
    139145      write_attribute('security_token', AuthenticatedUser.hashed(self.salted_password + Time.now.to_i.to_s + rand.to_s)) 
  • login_engine/trunk/test/functional/user_controller_test.rb

    r281 r362  
    8989    assert_match /login:\s+\w+\n/, mail.encoded 
    9090    assert_match /password:\s+\w+\n/, mail.encoded 
    91     mail.encoded =~ /user_id=(.*?)&key=(.*?)"/ 
    92     user_id = $1 
    93     key = $2 
     91    #mail.encoded =~ /user_id=(.*?)&key=(.*?)"/ 
     92    user_id = /user_id=(\d+)/.match(mail.encoded)[1] 
     93    key = /key=([a-z0-9]+)/.match(mail.encoded)[1] 
     94 
     95    assert_not_nil user_id 
     96    assert_not_nil key 
    9497 
    9598    user = User.find_by_email("newbob@test.com") 
     
    250253    assert_equal 1, ActionMailer::Base.deliveries.size 
    251254    mail = ActionMailer::Base.deliveries[0] 
    252     mail.encoded =~ /user_id=(.*?)&key=(.*?)"/ 
    253     id = $1 
    254     key = $2 
    255      
    256     post :restore_deleted, :user_id => "#{id}", "key" => "badkey" 
     255    user_id = /user_id=(\d+)/.match(mail.encoded)[1] 
     256    key = /key=([a-z0-9]+)/.match(mail.encoded)[1] 
     257     
     258    post :restore_deleted, :user_id => "#{user_id}", "key" => "badkey" 
    257259    assert_session_has_no :user 
    258260 
    259261    # Advance the time past the delete date 
    260262    Time.advance_by_days = LoginEngine.config :delayed_delete_days 
    261     post :restore_deleted, :user_id => "#{id}", "key" => "#{key}" 
     263    post :restore_deleted, :user_id => "#{user_id}", "key" => "#{key}" 
    262264    assert_session_has_no :user 
    263265    Time.advance_by_days = 0 
    264266 
    265     post :restore_deleted, :user_id => "#{id}", "key" => "#{key}" 
     267    post :restore_deleted, :user_id => "#{user_id}", "key" => "#{key}" 
    266268    assert_session_has :user       
    267269  end 
     
    456458        mail = ActionMailer::Base.deliveries[0] 
    457459        assert_equal "bob@test.com", mail.to_addrs[0].to_s 
    458         mail.encoded =~ /user_id=(.*?)&key=(.*?)"/ 
    459         id = $1 
    460         key = $2 
    461         post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}"}, :user_id => "#{id}", :key => "#{key}" 
     460        user_id = /user_id=(\d+)/.match(mail.encoded)[1] 
     461        key = /key=([a-z0-9]+)/.match(mail.encoded)[1] 
     462        post :change_password, :user => { :password => "#{password}", :password_confirmation => "#{password}"}, :user_id => "#{user_id}", :key => "#{key}" 
    462463        assert_session_has :user 
    463464        get :logout 
  • login_engine/trunk/test/test_helper.rb

    r107 r362  
    1 require File.dirname(__FILE__) + '/../../../../test/test_helper' # the default rails helper 
     1require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper') # the default rails helper 
    22 
    33# ensure that the Engines testing enhancements are loaded. 
    4 require File.join(Engines.config(:root), "engines", "lib", "testing_extensions") 
     4require File.join(Engines.config(:root), "engines", "lib", "engines", "testing_extensions") 
    55 
    66require File.dirname(__FILE__) + '/mocks/time' 
    77require File.dirname(__FILE__) + '/mocks/mail' 
    88 
    9 # Load the schema - if migrations have been performed, this will be up to date. 
    10 load(File.dirname(__FILE__) + "/../db/schema.rb") 
    11  
    129# set up the fixtures location 
    1310Test::Unit::TestCase.fixture_path = File.dirname(__FILE__)  + "/fixtures/" 
  • login_engine/trunk/test/unit/user_test.rb

    r281 r362  
    3535    u = User.new     
    3636    u.login = "nonbob" 
     37    u.email = "bobs@email.com" 
    3738 
    3839    u.change_password("tiny") 
     
    5859    u = User.new   
    5960    u.change_password("bobs_secure_password") 
     61    u.email = "bobs@email.com" 
    6062 
    6163    u.login = "x" 
     
    9092    u.login = "nonexistingbob" 
    9193    u.change_password("bobs_secure_password") 
     94    u.email = "bobs@email.com" 
    9295       
    9396    assert u.save   
    9497     
    9598  end 
    96    
     99 
     100  def test_email_should_be_nominally_valid 
     101    u = User.new 
     102    u.login = "email_test" 
     103    u.change_password("email_test_password") 
     104 
     105    assert !u.save 
     106    assert u.errors.invalid?('email') 
     107 
     108    u.email = "invalid_email" 
     109    assert !u.save 
     110    assert u.errors.invalid?('email') 
     111 
     112    u.email = "valid@email.com" 
     113    assert u.save 
     114  end 
     115 
    97116end