Class: Daidan::User
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Daidan::User
- Includes:
- BCrypt
- Defined in:
- lib/daidan/models/user.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
Instance Method Summary collapse
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
4 5 6 |
# File 'lib/daidan/models/user.rb', line 4 def password @password end |
Instance Method Details
#authenticate(submitted_password) ⇒ Object
24 25 26 |
# File 'lib/daidan/models/user.rb', line 24 def authenticate(submitted_password) Password.new(password_digest) == submitted_password end |
#before_save ⇒ Object
10 11 12 13 |
# File 'lib/daidan/models/user.rb', line 10 def before_save super encrypt_password if password end |
#validate ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/daidan/models/user.rb', line 15 def validate super validates_presence %i[email], message: 'is required' validates_unique :email, message: 'is already taken' validates_format(/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i, :email, message: 'is not a valid email address') errors.add(:password, 'cannot be empty') if new? && !password errors.add(:password, 'must be at least 6 characters') if password && password.length < 6 end |