Sprankelprachtig aan/afmeldsysteem

user.rb 744B

1234567891011121314151617181920212223242526
  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. has_secure_password
  9. belongs_to :person
  10. validates :person, presence: true
  11. validates :email, uniqueness: true
  12. before_validation :email_same_as_person
  13. private
  14. # Assert that the user's email address is the same as the email address of
  15. # the associated Person.
  16. def email_same_as_person
  17. if self.person and self.email != self.person.email
  18. errors.add(:email, "must be the same as associated person's email")
  19. end
  20. end
  21. end