Sha256: 7ee27ce335e1564314e314a95caeb9809584078c764e204de6506a3418bb9799
Contents?: true
Size: 1.56 KB
Versions: 6
Compression:
Stored size: 1.56 KB
Contents
# frozen_string_literal: true module Spree class User < Spree::Base include UserMethods devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :encryptable devise :confirmable if Spree::Auth::Config[:confirmable] if defined?(Spree::SoftDeletable) include Spree::SoftDeletable else acts_as_paranoid include Spree::ParanoiaDeprecations include Discard::Model self.discard_column = :deleted_at end after_destroy :scramble_email_and_password after_discard :scramble_email_and_password def password=(new_password) generate_spree_api_key if new_password.present? && spree_api_key.present? super end before_validation :set_login scope :admin, -> { includes(:spree_roles).where("#{Role.table_name}.name" => "admin") } def self.admin_created? User.admin.count > 0 end def admin? has_spree_role?('admin') end def confirmed? !!confirmed_at end protected def password_required? !persisted? || password.present? || password_confirmation.present? end private def set_login # for now force login to be same as email, eventually we will make this configurable, etc. self.login ||= email if email end def scramble_email_and_password return true if destroyed? self.email = SecureRandom.uuid + "@example.net" self.login = email self.password = SecureRandom.hex(8) self.password_confirmation = password save end end end
Version data entries
6 entries across 6 versions & 1 rubygems