Sprankelprachtig aan/afmeldsysteem

user.rb 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  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. sessions = Session.where(user: self)
  21. sessions.update_all(active: false)
  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. if self.person and self.email != self.person.email
  28. errors.add(:email, I18n.t('authentication.user_person_mail_mismatch'))
  29. end
  30. end
  31. end