Sha256: 873da5d4b0f580d8ded7c26c2cfaf254739c3b3c340a50bc79a9d9ad5b792cd1
Contents?: true
Size: 1.92 KB
Versions: 1
Compression:
Stored size: 1.92 KB
Contents
class User < ApplicationRecord has_secure_password generates_token_for :email_verification, expires_in: 2.days { email } generates_token_for :password_reset, expires_in: 20.minutes { password_salt.last(10) } <%- if options.tenantable? %> belongs_to :account <%- end -%> has_many :sessions, dependent: :destroy <%- if two_factor? -%> has_many :recovery_codes, dependent: :destroy <%- end -%> <%- if webauthn? -%> has_many :security_keys, dependent: :destroy <%- end -%> <%- if passwordless? -%> has_many :sign_in_tokens, dependent: :destroy <%- end -%> <%- if options.trackable? -%> has_many :events, dependent: :destroy <%- end -%> validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP } validates :password, allow_nil: true, length: { minimum: 12 } <%- if options.pwned? -%> validates :password, not_pwned: { message: "might easily be guessed" } <%- end -%> normalizes :email, with: -> { _1.strip.downcase } before_validation if: :email_changed?, on: :update do self.verified = false end <%- if two_factor? %> before_validation on: :create do self.otp_secret = ROTP::Base32.random end <%- end -%> <%- if webauthn? %> before_validation on: :create do self.webauthn_id = WebAuthn.generate_user_id end <%- end -%> <%- if options.tenantable? %> before_validation on: :create do self.account = Account.new end <%- end -%> after_update if: :password_digest_previously_changed? do sessions.where.not(id: Current.session).delete_all end <%- if options.trackable? %> after_update 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?, :verified?] do events.create! action: "email_verified" end <%- end -%> end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
authentication-zero-3.0.0.alpha1 | lib/generators/authentication/templates/models/user.rb.tt |