bookstore/app/models/user.rb
2021-03-22 03:16:29 +01:00

19 lines
578 B
Ruby

# frozen_string_literal: true
class User < ApplicationRecord
has_and_belongs_to_many :books
has_secure_password
has_secure_password :recovery_password, validations: false
enum role: %i[customer admin], _default: :customer
enum status: %i[ready blocked], _default: :ready
validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :role, presence: true
validates :status, presence: true
validates :password, {
presence: true,
length: { minimum: 8 },
if: -> { new_record? || !password.nil? }
}
end