Changeset 449
- Timestamp:
- 08/24/06 05:25:17 (2 years ago)
- Files:
-
- login_engine/trunk/app/models/password.rb (added)
- login_engine/trunk/db/migrate/002_add_password_table.rb (added)
- login_engine/trunk/lib/login_engine.rb (modified) (1 diff)
- login_engine/trunk/lib/login_engine/authenticated_user.rb (modified) (3 diffs)
- login_engine/trunk/test/unit/user_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
login_engine/trunk/lib/login_engine.rb
r446 r449 52 52 if ActiveRecord::Base.pluralize_table_names 53 53 config :user_table, "users" 54 config :password_table, "passwords" 54 55 else 55 56 config :user_table, "user" 57 config :password_table, "password" 56 58 end 59 60 # password expiry time in days 61 # 0 means it will not expire 62 config :password_expiry, 0 57 63 58 64 # controls whether or not email is used login_engine/trunk/lib/login_engine/authenticated_user.rb
r446 r449 31 31 attr_accessor :password, :password_confirmation 32 32 33 after_save : falsify_new_password33 after_save :copy_password_to_password_table, :falsify_new_password 34 34 after_validation :crypt_password 35 36 has_many :passwords, :order => 'created_at DESC' 35 37 36 38 end … … 126 128 "#{self.firstname} #{self.lastname}" 127 129 end 130 131 # some systems want to expire a user's password after a certain period 132 # If password expiry set to 0, then passwords don't expire 133 def password_expired? 134 if LoginEngine.config(:password_expiry) == 0 135 return false 136 else 137 return LoginEngine.config(:password_expiry).days.ago > self.passwords.first.created_at 138 end 139 end 128 140 129 141 protected … … 146 158 end 147 159 160 def copy_password_to_password_table 161 if @new_password 162 Password.create(:user_id => id, 163 :salt => salt, 164 :salted_password => salted_password) 165 end 166 true 167 end 168 169 148 170 def new_security_token(hours = nil) 149 171 write_attribute('security_token', AuthenticatedUser.hashed(self.salted_password + Time.now.to_i.to_s + rand.to_s)) login_engine/trunk/test/unit/user_test.rb
r446 r449 135 135 end 136 136 137 def test_password_expiry 138 u = User.new 139 u.login = 'password_test' 140 u.email = 'bobs@email.com' 141 u.change_password("password1", "password1") 142 assert u.save 143 assert 1, u.passwords.length 144 assert !u.password_expired?, "Password expired when it has just been created" 145 146 LoginEngine::CONFIG[:password_expiry]=1 147 u.passwords.first.created_at = 1.day.ago 148 u.passwords.first.save 149 assert u.password_expired?, "Password should have expired" 150 151 152 end 137 153 end
