Class: Ditty::Identity
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Ditty::Identity
- Includes:
- Base, OmniAuth::Identity::Model
- Defined in:
- lib/ditty/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.
Methods included from Base
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
14 15 16 |
# File 'lib/ditty/models/identity.rb', line 14 def password @password end |
#password_confirmation ⇒ Object
Returns the value of attribute password_confirmation.
14 15 16 |
# File 'lib/ditty/models/identity.rb', line 14 def password_confirmation @password_confirmation end |
Class Method Details
.locate(conditions) ⇒ Object
19 20 21 |
# File 'lib/ditty/models/identity.rb', line 19 def self.locate(conditions) where(conditions).first end |
Instance Method Details
#authenticate(unencrypted) ⇒ Object
23 24 25 26 27 |
# File 'lib/ditty/models/identity.rb', line 23 def authenticate(unencrypted) return false if crypted_password.blank? self if ::BCrypt::Password.new(crypted_password) == unencrypted end |
#before_save ⇒ Object
Callbacks
68 69 70 71 |
# File 'lib/ditty/models/identity.rb', line 68 def before_save super encrypt_password unless password == '' || password.nil? end |
#info ⇒ Object
Return whatever we want to pass to the omniauth hash here
34 35 36 37 38 |
# File 'lib/ditty/models/identity.rb', line 34 def info { email: username } end |
#persisted? ⇒ Boolean
29 30 31 |
# File 'lib/ditty/models/identity.rb', line 29 def persisted? !new? && @destroyed != true end |
#validate ⇒ Object
Validation
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ditty/models/identity.rb', line 41 def validate super 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_format( # 1 Uppercase # 1 lowercase # 1 Special Character # 1 Number # At least 8 characters %r[\A(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#&$*)(}{%^=_+|\\:";'<>,.\-\/?\[\]])(?=.*[0-9]).{8,}\Z], :password, message: 'is not strong enough' ) end errors.add(:password_confirmation, 'must match password') if !password.blank? && password != password_confirmation end |