Class: Unidom::Visitor::Password
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Unidom::Visitor::Password
- Includes:
- Common::Concerns::ModelExtension, Concerns::AsCredential
- Defined in:
- app/models/unidom/visitor/password.rb
Overview
Password 是密码。
Instance Method Summary collapse
- #change_to(new_password) ⇒ Object
- #clear_text ⇒ Object
- #clear_text=(password) ⇒ Object
- #generate_pepper_content ⇒ Object
- #matched?(password) ⇒ Boolean
Instance Method Details
#change_to(new_password) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/unidom/visitor/password.rb', line 41 def change_to(new_password) visitor = authenticating.visitor soft_destroy authenticating.soft_destroy password = self.class.new clear_text: new_password, opened_at: Time.now if password.save #Unidom::Visitor::Authenticating.authenticate visitor, password Unidom::Visitor::Authenticating.authenticate! visitor, with: password else nil end end |
#clear_text ⇒ Object
20 21 22 |
# File 'app/models/unidom/visitor/password.rb', line 20 def clear_text @clear_text end |
#clear_text=(password) ⇒ Object
24 25 26 27 28 |
# File 'app/models/unidom/visitor/password.rb', line 24 def clear_text=(password) @clear_text = password generate_pepper_content self.hashed_content = hash password end |
#generate_pepper_content ⇒ Object
16 17 18 |
# File 'app/models/unidom/visitor/password.rb', line 16 def generate_pepper_content self.pepper_content = self.pepper_content||SecureRandom.hex(self.class.columns_hash['pepper_content'].limit/2) end |
#matched?(password) ⇒ Boolean
30 31 32 |
# File 'app/models/unidom/visitor/password.rb', line 30 def matched?(password) hash(password)==self.hashed_content end |