Sprankelprachtig aan/afmeldsysteem

user.rb 858B

123456789101112131415161718192021222324252627282930
  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. private
  18. # Assert that the user's email address is the same as the email address of
  19. # the associated Person.
  20. def email_same_as_person
  21. if self.person and self.email != self.person.email
  22. errors.add(:email, "must be the same as associated person's email")
  23. end
  24. end
  25. end