Class: Daidan::User

Inherits:
Sequel::Model
  • Object
show all
Includes:
BCrypt
Defined in:
lib/daidan/models/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

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()
  Password.new(password_digest) == 
end

#before_saveObject



10
11
12
13
# File 'lib/daidan/models/user.rb', line 10

def before_save
  super
  encrypt_password if password
end

#validateObject



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