Sha256: 79794d37851b0f9d46b95c4530165dd9f4736ede65aa87ec60c12969d4cde321

Contents?: true

Size: 792 Bytes

Versions: 1

Compression:

Stored size: 792 Bytes

Contents

class <%= class_name %> < ApplicationRecord
  has_secure_password :password
  has_secure_token :session_token

  validates :email, presence: true, uniqueness: true
  validates :email, format: { with: /\A[^@\s]+@[^@\s]+\z/ }
  validates_length_of :password, minimum: 8, allow_blank: true

  before_validation do
    self.email = email.downcase.strip
  end

  after_update_commit do
    if self.email_previously_changed?
      EmailMailer.with(change: self.email_previous_change).changed.deliver_later
    end
  end

  after_update_commit do
    if self.password_digest_previously_changed?
      PasswordMailer.with(<%= singular_table_name %>: self).changed.deliver_later
    end
  end

  def as_json(options = {})
    super(options.merge(except: [:password_digest, :session_token]))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authentication-zero-0.0.15 lib/generators/authentication/templates/models/resource.rb.tt