bookstore/app/models/user.rb

20 lines
578 B
Ruby
Raw Normal View History

2021-03-22 03:16:29 +01:00
# frozen_string_literal: true
2021-03-20 14:23:06 +01:00
class User < ApplicationRecord
2021-03-22 02:25:17 +01:00
has_and_belongs_to_many :books
2021-03-20 14:23:06 +01:00
has_secure_password
2021-03-21 11:12:14 +01:00
has_secure_password :recovery_password, validations: false
2021-03-22 03:16:29 +01:00
enum role: %i[customer admin], _default: :customer
enum status: %i[ready blocked], _default: :ready
2021-03-21 17:02:04 +01:00
validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :role, presence: true
2021-03-21 23:43:09 +01:00
validates :status, presence: true
2021-03-21 20:30:25 +01:00
validates :password, {
presence: true,
length: { minimum: 8 },
2021-03-22 03:16:29 +01:00
if: -> { new_record? || !password.nil? }
2021-03-21 20:30:25 +01:00
}
2021-03-20 14:23:06 +01:00
end