Changeset 362
- Timestamp:
- 04/10/06 08:50:08 (3 years ago)
- Files:
-
- login_engine/trunk/CHANGELOG (modified) (1 diff)
- login_engine/trunk/README (modified) (2 diffs)
- login_engine/trunk/app/views/user/forgot_password.rhtml (modified) (1 diff)
- login_engine/trunk/db/schema.rb (deleted)
- login_engine/trunk/install.rb (copied) (copied from login_engine/branches/rb_1.0/install.rb)
- login_engine/trunk/lib/login_engine/authenticated_system.rb (modified) (1 diff)
- login_engine/trunk/lib/login_engine/authenticated_user.rb (modified) (3 diffs)
- login_engine/trunk/test/functional/user_controller_test.rb (modified) (3 diffs)
- login_engine/trunk/test/test_helper.rb (modified) (1 diff)
- login_engine/trunk/test/unit/user_test.rb (modified) (3 diffs)
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) 2 7 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 17 17 Installing 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. 18 18 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 19 Your 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> 31 32 32 33 === Setup your Rails application … … 294 295 295 296 Currently, 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 300 You 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 353 Of 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 8 8 9 9 <%= 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) %> 11 11 12 12 <div class="button-bar"> login_engine/trunk/lib/login_engine/authenticated_system.rb
r201 r362 55 55 # call overwriteable reaction to unauthorized access 56 56 access_denied 57 return false58 57 end 59 58 login_engine/trunk/lib/login_engine/authenticated_user.rb
r303 r362 21 21 validates_uniqueness_of :login 22 22 validates_uniqueness_of :email 23 validates_format_of :email, :with => /^[^@]+@.+$/ 23 24 24 25 validates_confirmation_of :password, :if => :validate_password? … … 30 31 attr_accessor :password, :password_confirmation 31 32 32 after_save '@new_password = false'33 after_save :falsify_new_password 33 34 after_validation :crypt_password 34 35 35 36 end 36 37 base.extend(ClassMethods) … … 136 137 end 137 138 139 def falsify_new_password 140 @new_password = false 141 true 142 end 143 138 144 def new_security_token(hours = nil) 139 145 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 89 89 assert_match /login:\s+\w+\n/, mail.encoded 90 90 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 94 97 95 98 user = User.find_by_email("newbob@test.com") … … 250 253 assert_equal 1, ActionMailer::Base.deliveries.size 251 254 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" 257 259 assert_session_has_no :user 258 260 259 261 # Advance the time past the delete date 260 262 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}" 262 264 assert_session_has_no :user 263 265 Time.advance_by_days = 0 264 266 265 post :restore_deleted, :user_id => "#{ id}", "key" => "#{key}"267 post :restore_deleted, :user_id => "#{user_id}", "key" => "#{key}" 266 268 assert_session_has :user 267 269 end … … 456 458 mail = ActionMailer::Base.deliveries[0] 457 459 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}" 462 463 assert_session_has :user 463 464 get :logout login_engine/trunk/test/test_helper.rb
r107 r362 1 require File. dirname(__FILE__) + '/../../../../test/test_helper'# the default rails helper1 require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper') # the default rails helper 2 2 3 3 # ensure that the Engines testing enhancements are loaded. 4 require File.join(Engines.config(:root), "engines", "lib", " testing_extensions")4 require File.join(Engines.config(:root), "engines", "lib", "engines", "testing_extensions") 5 5 6 6 require File.dirname(__FILE__) + '/mocks/time' 7 7 require File.dirname(__FILE__) + '/mocks/mail' 8 8 9 # Load the schema - if migrations have been performed, this will be up to date.10 load(File.dirname(__FILE__) + "/../db/schema.rb")11 12 9 # set up the fixtures location 13 10 Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/" login_engine/trunk/test/unit/user_test.rb
r281 r362 35 35 u = User.new 36 36 u.login = "nonbob" 37 u.email = "bobs@email.com" 37 38 38 39 u.change_password("tiny") … … 58 59 u = User.new 59 60 u.change_password("bobs_secure_password") 61 u.email = "bobs@email.com" 60 62 61 63 u.login = "x" … … 90 92 u.login = "nonexistingbob" 91 93 u.change_password("bobs_secure_password") 94 u.email = "bobs@email.com" 92 95 93 96 assert u.save 94 97 95 98 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 97 116 end
