Module: Wristband::UserExtensions::InstanceMethods
- Defined in:
- lib/wristband/user_extensions.rb
Instance Method Summary collapse
- #encrypt_password ⇒ Object
- #encrypted_password=(value) ⇒ Object
- #has_authority_to?(action, options = { }) ⇒ Boolean
- #has_objections_to?(action, options = { }) ⇒ Boolean
- #initialize_salt ⇒ Object
- #initialize_token ⇒ Object
- #matches_legacy_password?(string) ⇒ Boolean
- #password_match?(password_attempt) ⇒ Boolean
- #reset_perishable_token! ⇒ Object
Instance Method Details
#encrypt_password ⇒ Object
56 57 58 59 60 |
# File 'lib/wristband/user_extensions.rb', line 56 def encrypt_password return if self.password.blank? initialize_salt if new_record? self.send("#{self.class.wristband[:password_column]}=", Wristband::Support.encrypt_with_salt(self.password, self.password_salt, self.class.wristband[:encryption_type])) end |
#encrypted_password=(value) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/wristband/user_extensions.rb', line 86 def encrypted_password=(value) if (value != read_attribute(:encrypted_password)) initialize_token end write_attribute(:encrypted_password, value) end |
#has_authority_to?(action, options = { }) ⇒ Boolean
40 41 42 |
# File 'lib/wristband/user_extensions.rb', line 40 def (action, = { }) self.class.wristband[:authority_class].new(self, action, ).allowed_to? end |
#has_objections_to?(action, options = { }) ⇒ Boolean
44 45 46 |
# File 'lib/wristband/user_extensions.rb', line 44 def has_objections_to?(action, = { }) self.class.wristband[:authority_class].new(self, action, ).denied_for_reasons end |
#initialize_salt ⇒ Object
48 49 50 |
# File 'lib/wristband/user_extensions.rb', line 48 def initialize_salt self.password_salt = Wristband::Support.random_salt(nil, self.class.wristband[:encryption_type]) end |
#initialize_token ⇒ Object
52 53 54 |
# File 'lib/wristband/user_extensions.rb', line 52 def initialize_token self.session_token = Wristband::Support.random_salt(16, self.class.wristband[:encryption_type]) end |
#matches_legacy_password?(string) ⇒ Boolean
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/wristband/user_extensions.rb', line 75 def matches_legacy_password?(string) return unless self.class.wristband[:legacy_password][:column_name].present? && self.send(self.class.wristband[:legacy_password][:column_name]).present? case self.class.wristband[:legacy_password][:encryption] when :md5 self.send("#{self.class.wristband[:legacy_password][:column_name]}") == Digest::MD5.hexdigest(string) else false end end |
#password_match?(password_attempt) ⇒ Boolean
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/wristband/user_extensions.rb', line 62 def password_match?(password_attempt) if matches_legacy_password?(password_attempt) self.password = password_attempt initialize_salt encrypt_password self.send("#{self.class.wristband[:legacy_password][:column_name]}=", nil) self.save else current_pwd = self.send(self.class.wristband[:password_column]) Wristband::Support.matches?(password_attempt, current_pwd, self.password_salt, self.class.wristband[:encryption_type]) end end |
#reset_perishable_token! ⇒ Object
93 94 95 |
# File 'lib/wristband/user_extensions.rb', line 93 def reset_perishable_token! update_attribute(:perishable_token, Wristband::Support.random_salt(nil, self.class.wristband[:encryption_type]).gsub(/[^A-Za-z0-9]/,'')) end |