<commit_before>class User < ActiveRecord::Base

  attr_accessor :stripe_token, :old_password_valid, :update_auth_token,
                :password_reset, :coupon_code, :is_trialing, :coupon_valid

  has_secure_password

  store_accessor :settings,
                 :entry_sort,
                 :previous_read_count,
                 :starred_feed_enabled,
                 :precache_images,
                 :show_unread_count,
                 :sticky_view_inline,
                 :mark_as_read_confirmation,
                 :font_size,
                 :font,
                 :entry_width,
                 :apple_push_notification_device_token,
                 :mark_as_read_push_view,
                 :keep_unread_entries,
                 :receipt_info,
                 :theme,
                 :favicon_hash,
                 :entries_display,
                 :entries_feed,
                 :entries_time,
                 :entries_body,
                 :entries_image,
                 :ui_typeface,
                 :update_message_seen,
                 :hide_recently_read,
                 :hide_updated,
                 :view_mode,
                 :disable_image_proxy

  has_one :coupon
  has_many :subscriptions, dependent: :delete_all
  has_many :feeds, through: :subscriptions
  has_many :entries, through: :feeds
  has_many :imports, dependent: :destroy
  has_many :billing_events, as: :billable, dependent: :delete_all
  has_many :taggings, dependent: :delete_all
  has_many :tags, through: :taggings
  has_many :sharing_services, dependent: :delete_all
  has_many :supported_sharing_services, dependent: :delete_all
  has_many :unread_entries, dependent: :delete_all
  has_many :starred_entries, dependent: :delete_all
  has_many :saved_searches, dependent: :delete_all
  has_many :actions, dependent: :destroy
  has_many :recently_read_entries, dependent: :delete_all
  has_many :updated_entries, dependent: :delete_all
  has_many :devices, dependent: :delete_all
  has_many :in_app_purchases
  belongs_to :plan

  accepts_nested_attributes_for :sharing_services,
                                allow_destroy: true,
                                reject_if: -> attributes { attributes['label'].blank? || attributes['url'].blank? }


  after_initialize :set_defaults, if: :new_record?

  before_save :update_billing, unless: -> user { user.admin || !ENV['STRIPE_API_KEY'] }
  before_save :strip_email
  before_save :activate_subscriptions
  before_save { reset_auth_token }

  before_create { generate_token(:starred_token) }
  before_create { generate_token(:inbound_email_token, 4) }
  before_create { generate_token(:newsletter_token, 4) }

  after_create { schedule_trial_jobs }

  before_destroy :cancel_billing, unless: -> user { user.admin }
  before_destroy :create_deleted_user
  before_destroy :record_stats

  validate :changed_password, on: :update, unless: -> user { user.password_reset }
  validate :coupon_code_valid, on: :create, if: -> user { user.coupon_code }
  validate :plan_type_valid, on: :update
  validate :trial_plan_valid

  validates_presence_of :email
  validates_uniqueness_of :email, case_sensitive: false
  validates_presence_of :password, on: :create

  def set_defaults
    self.expires_at = Feedbin::Application.config.trial_days.days.from_now
    self.update_auth_token = true<commit_msg>Misc updates.<commit_after>class User < ActiveRecord::Base

  attr_accessor :stripe_token, :old_password_valid, :update_auth_token,
                :password_reset, :coupon_code, :is_trialing, :coupon_valid

  has_secure_password

  store_accessor :settings,
                 :entry_sort,
                 :previous_read_count,
                 :starred_feed_enabled,
                 :precache_images,
                 :show_unread_count,
                 :sticky_view_inline,
                 :mark_as_read_confirmation,
                 :font_size,
                 :font,
                 :entry_width,
                 :apple_push_notification_device_token,
                 :mark_as_read_push_view,
                 :keep_unread_entries,
                 :receipt_info,
                 :theme,
                 :favicon_hash,
                 :entries_display,
                 :entries_feed,
                 :entries_time,
                 :entries_body,
                 :entries_image,
                 :ui_typeface,
                 :update_message_seen,
                 :hide_recently_read,
                 :hide_updated,
                 :view_mode,
                 :disable_image_proxy

  has_one :coupon
  has_many :subscriptions, dependent: :delete_all
  has_many :feeds, through: :subscriptions
  has_many :entries, through: :feeds
  has_many :imports, dependent: :destroy
  has_many :billing_events, as: :billable, dependent: :delete_all
  has_many :taggings, dependent: :delete_all
  has_many :tags, through: :taggings
  has_many :sharing_services, dependent: :delete_all
  has_many :supported_sharing_services, dependent: :delete_all
  has_many :unread_entries, dependent: :delete_all
  has_many :starred_entries, dependent: :delete_all
  has_many :saved_searches, dependent: :delete_all
  has_many :actions, dependent: :destroy
  has_many :recently_read_entries, dependent: :delete_all
  has_many :updated_entries, dependent: :delete_all
  has_many :devices, dependent: :delete_all
  has_many :in_app_purchases
  belongs_to :plan

  accepts_nested_attributes_for :sharing_services,
                                allow_destroy: true,
                                reject_if: -> attributes { attributes['label'].blank? || attributes['url'].blank? }


  after_initialize :set_defaults, if: :new_record?

  before_save :update_billing, unless: -> { !ENV['STRIPE_API_KEY'] }
  before_save :strip_email
  before_save :activate_subscriptions
  before_save { reset_auth_token }

  before_create { generate_token(:starred_token) }
  before_create { generate_token(:inbound_email_token, 4) }
  before_create { generate_token(:newsletter_token, 4) }

  after_create { schedule_trial_jobs }

  before_destroy :cancel_billing, unless: -> { !ENV['STRIPE_API_KEY'] }
  before_destroy :create_deleted_user
  before_destroy :record_stats

  validate :changed_password, on: :update, unless: -> user { user.password_reset }
  validate :coupon_code_valid, on: :create, if: -> user { user.coupon_code }
  validate :plan_type_valid, on: :update
  validate :trial_plan_valid

  validates_presence_of :email
  validates_uniqueness_of :email, case_sensitive: false
  validates_presence_of :password, on: :create

  def set_defaults
    self.expires_at = Feedbin::Application.config.trial_days.days.from_now
    self.update_auth_token = true
{'fraction_non_alphanumeric': 0.07940298507462687, 'fraction_numerical': 0.0005970149253731343, 'mean_word_length': 2.792303338992643, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2083813', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1987, 'n_words': 381}