Sha256: 7fea19a87088697a08cf07939cf0c0b7f8a053256e1670f70149a5ee15b390bb
Contents?: true
Size: 1.36 KB
Versions: 3
Compression:
Stored size: 1.36 KB
Contents
class <%= class_name %> < ApplicationRecord has_secure_password has_many :sessions, dependent: :destroy <% if options.trackable? -%> has_many :events, dependent: :destroy <% end -%> validates :email, presence: true, uniqueness: true validates_format_of :email, with: /\A[^@\s]+@[^@\s]+\z/ validates_length_of :password, minimum: 12, allow_blank: true validates_format_of :password, with: /(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])/, allow_blank: true, message: "might easily be guessed" <% if options.pwned? -%> validates :password, not_pwned: { message: "might easily be guessed" } <% end -%> before_validation do self.email = email.downcase.strip end before_validation if: :email_changed? do self.verified = false end after_update if: :password_digest_previously_changed? do sessions.where.not(id: Current.session).destroy_all end after_save_commit if: :email_previously_changed? do IdentityMailer.with(user: self).email_verify_confirmation.deliver_later end <% if options.trackable? %> after_save_commit if: :email_previously_changed? do events.create! action: "email_verification_requested" end after_update if: :password_digest_previously_changed? do events.create! action: "password_changed" end after_update if: :verified_previously_changed? do events.create! action: "email_verified" if verified? end <% end -%> end
Version data entries
3 entries across 3 versions & 1 rubygems