Module: Wristband::UserExtensions::InstanceMethods
- Defined in:
- lib/wristband/user_extensions.rb
Instance Method Summary collapse
- #encrypt_password ⇒ 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_hash=(value) ⇒ Object
-
#password_match?(string) ⇒ Boolean
231badb19b93e44f47da1bd64a8147f2.
- #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 initialize_salt if new_record? return if self.password.blank? self.send("#{self.class.wristband[:password_column]}=", Wristband::Support.encrypt_with_salt(self.password, self.password_salt)) 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 end |
#initialize_token ⇒ Object
52 53 54 |
# File 'lib/wristband/user_extensions.rb', line 52 def initialize_token self.remember_token = Wristband::Support.random_salt(16) 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_hash=(value) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/wristband/user_extensions.rb', line 86 def password_hash=(value) if (value != read_attribute(:password_hash)) initialize_token end write_attribute(:password_hash, value) end |
#password_match?(string) ⇒ Boolean
231badb19b93e44f47da1bd64a8147f2
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/wristband/user_extensions.rb', line 63 def password_match?(string) if matches_legacy_password?(string) self.password = string initialize_salt encrypt_password self.send("#{self.class.wristband[:legacy_password][:column_name]}=", nil) self.save else self.send(self.class.wristband[:password_column]) == Wristband::Support.encrypt_with_salt(string, self.password_salt) 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.gsub(/[^A-Za-z0-9]/,'')) end |