Class: ProxES::Identity
- Includes:
- OmniAuth::Identity::Model
- Defined in:
- lib/proxes/models/identity.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#password_confirmation ⇒ Object
Returns the value of attribute password_confirmation.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate(unencrypted) ⇒ Object
-
#before_save ⇒ Object
Callbacks.
-
#info ⇒ Object
Return whatever we want to pass to the omniauth hash here.
- #persisted? ⇒ Boolean
-
#validate ⇒ Object
Validation.
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
12 13 14 |
# File 'lib/proxes/models/identity.rb', line 12 def password @password end |
#password_confirmation ⇒ Object
Returns the value of attribute password_confirmation.
12 13 14 |
# File 'lib/proxes/models/identity.rb', line 12 def password_confirmation @password_confirmation end |
Class Method Details
.locate(conditions) ⇒ Object
17 18 19 |
# File 'lib/proxes/models/identity.rb', line 17 def self.locate(conditions) where(conditions).first end |
Instance Method Details
#authenticate(unencrypted) ⇒ Object
21 22 23 |
# File 'lib/proxes/models/identity.rb', line 21 def authenticate(unencrypted) self if ::BCrypt::Password.new(crypted_password) == unencrypted end |
#before_save ⇒ Object
Callbacks
54 55 56 |
# File 'lib/proxes/models/identity.rb', line 54 def before_save encrypt_password unless password == '' || password.nil? end |
#info ⇒ Object
Return whatever we want to pass to the omniauth hash here
30 31 32 33 34 |
# File 'lib/proxes/models/identity.rb', line 30 def info { email: username } end |
#persisted? ⇒ Boolean
25 26 27 |
# File 'lib/proxes/models/identity.rb', line 25 def persisted? !new? && @destroyed != true end |
#validate ⇒ Object
Validation
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/proxes/models/identity.rb', line 37 def validate validates_presence :username unless username.blank? validates_unique :username validates_format(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :username) end if password_required validates_presence :password validates_presence :password_confirmation validates_min_length 8, :password end errors.add(:password_confirmation, 'must match password') if !password.blank? && password != password_confirmation end |