Module: Auth::Behavior::Core::PasswordMethods
- Defined in:
- lib/auth/behavior/core/password_methods.rb
Class Method Summary collapse
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #encrypt(p) ⇒ Object
- #expired? ⇒ Boolean
- #matches?(phrase) ⇒ Boolean
- #reset_perishable_token ⇒ Object
- #reset_persistence_token ⇒ Object
- #reset_single_access_token ⇒ Object
- #secret_confirmation_with_encryption=(phrase) ⇒ Object
- #secret_with_encryption=(phrase) ⇒ Object
- #unencrypted_secret ⇒ Object
Class Method Details
.included(base) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/auth/behavior/core/password_methods.rb', line 2 def self.included(base) # so apparently dynamic methods haven't been generated by AR yet, so this stuff's been moved to # #after_initialize. Less than ideal but whatever. # base.send(:alias_method_chain, :secret=, :encryption) # base.send(:alias_method_chain, :secret_confirmation=, :encryption) end |
Instance Method Details
#after_initialize ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/auth/behavior/core/password_methods.rb', line 9 def after_initialize # FIXME: HACK - see self.included(base) if attributes.keys.include?('secret') self.secret # uh, makes AR define the method, I guess? This feels clunky... end class << self alias_method_chain :secret=, :encryption alias_method_chain :secret_confirmation=, :encryption end end |
#encrypt(p) ⇒ Object
26 27 28 29 |
# File 'lib/auth/behavior/core/password_methods.rb', line 26 def encrypt(p) self.salt ||= Auth::Token.new.to_s Auth.encryptor.encrypt(p, salt) end |
#expired? ⇒ Boolean
22 23 24 |
# File 'lib/auth/behavior/core/password_methods.rb', line 22 def expired? authenticatable.password_expired? end |
#matches?(phrase) ⇒ Boolean
31 32 33 |
# File 'lib/auth/behavior/core/password_methods.rb', line 31 def matches?(phrase) Auth.encryptor.matches?(secret, phrase, salt) end |
#reset_perishable_token ⇒ Object
43 44 45 |
# File 'lib/auth/behavior/core/password_methods.rb', line 43 def reset_perishable_token self.perishable_token = Auth::Token.new.to_s end |
#reset_persistence_token ⇒ Object
35 36 37 |
# File 'lib/auth/behavior/core/password_methods.rb', line 35 def reset_persistence_token self.persistence_token = Auth::Token.new.to_s end |
#reset_single_access_token ⇒ Object
39 40 41 |
# File 'lib/auth/behavior/core/password_methods.rb', line 39 def reset_single_access_token self.single_access_token = Auth::Token.new.to_s end |
#secret_confirmation_with_encryption=(phrase) ⇒ Object
57 58 59 60 |
# File 'lib/auth/behavior/core/password_methods.rb', line 57 def secret_confirmation_with_encryption=(phrase) encrypted_phrase = phrase.blank? ? phrase : encrypt(phrase) self.secret_confirmation_without_encryption = encrypted_phrase end |
#secret_with_encryption=(phrase) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/auth/behavior/core/password_methods.rb', line 47 def secret_with_encryption=(phrase) @unencrypted_secret = phrase encrypted_phrase = phrase.blank? ? phrase : encrypt(phrase) self.secret_without_encryption = encrypted_phrase reset_persistence_token reset_single_access_token unless single_access_token # don't reset after it has a value reset_perishable_token return encrypted_phrase end |
#unencrypted_secret ⇒ Object
62 63 64 |
# File 'lib/auth/behavior/core/password_methods.rb', line 62 def unencrypted_secret @unencrypted_secret end |