Sha256: 7084fccd7687e6736d34d9f8a88cd40103afa851b2260d5c2c8846208d7122f2
Contents?: true
Size: 1.32 KB
Versions: 12
Compression:
Stored size: 1.32 KB
Contents
# frozen_string_literal: true require 'devise' module Lcms module Engine class User < ApplicationRecord # Include default devise modules. Others available are: # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable enum role: { admin: 1, user: 0 } validates_presence_of :access_code, on: :create, unless: :admin? validates_presence_of :email, :role validate :access_code_valid?, on: :create, unless: :admin? def full_name [ survey&.fetch('first_name', nil), survey&.fetch('last_name', nil) ].reject(&:blank?).join(' ') end def generate_password pwd = Devise.friendly_token.first(20) self.password = pwd self.password_confirmation = pwd end def name super.presence || full_name end def ready_to_go? admin? || survey.present? end private def access_code_valid? return if AccessCode.by_code(access_code).exists? errors.add :access_code, 'not found' end protected # NOTE: temporary disable confirmable due to issues with server setup def confirmation_required? false end end end end
Version data entries
12 entries across 12 versions & 1 rubygems