Sprankelprachtig aan/afmeldsysteem

user.rb 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. # A User contains the login information for a single Person, and allows the
  2. # user to log in by creating Sessions.
  3. class User < ApplicationRecord
  4. # @!attribute email
  5. # @return [String]
  6. # the user's email address. Should be the same as the associated Person's
  7. # email address.
  8. #
  9. # @!attribute confirmed
  10. # @return [Boolean]
  11. # whether or not this account has been activated yet.
  12. has_secure_password
  13. belongs_to :person
  14. validates :person, presence: true
  15. validates :email, uniqueness: true
  16. before_validation :email_same_as_person
  17. # Set all sessions associated with this User to inactive, for instance after
  18. # a password change, or when the user selects this options in the Settings.
  19. def logout_all_sessions!
  20. Session.where(user: self)
  21. .update_all(active: false) # rubocop:disable Rails/SkipsModelValidations
  22. end
  23. private
  24. # Assert that the user's email address is the same as the email address of
  25. # the associated Person.
  26. def email_same_as_person
  27. errors.add(:email, I18n.t('authentication.user_person_mail_mismatch')) if person && (email != person.email)
  28. end
  29. end