class SecureUser < ApplicationRecord
  belongs_to :room
  has_many :tasks
  # TODO: fix valid email regex
  VALID_EMAIL_REGEX = /A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
  before_save { self.email = email.downcase }
  
  validates :name,
      presence: true,
      length: { maximum: 12 }
  
  validates :email,
      presence: true,
      length: { maximum: 255 },
      format: { with: VALID_EMAIL_REGEX },
      uniqueness: { case_sensitive: false }
      
  validates :password,
      presence: true,
      length: { minimum: 6 }
      
  has_secure_password
end
