Sprankelprachtig aan/afmeldsysteem

token.rb 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. class Token < ApplicationRecord
  2. # A Token contains some information that can be used as an alternative way to
  3. # authenticate a user, typically instead of a username/password combination.
  4. #
  5. # At least the following types of tokens will exist:
  6. # - Account confirmation tokens, sent to the user when their account is
  7. # created (to verify their email address)
  8. # - Password reset tokens
  9. # - API authentication tokens
  10. #
  11. # @!attribute token
  12. # @return [String]
  13. # a unique token, that allows the holder to perform some action.
  14. #
  15. # @!attribute expires
  16. # @return [DateTime]
  17. # when the token will expire (and will no longer be usable).
  18. #
  19. # @!attribute tokentype
  20. # @return [String]
  21. # what action the token allows the holder to perform. Use the hash
  22. # Token::TYPES instead of comparing directly!
  23. #
  24. # @!attribute user
  25. # @return [User]
  26. # what user the token allows the holder to authenticate as.
  27. TYPES = {
  28. password_reset: 'pw_reset',
  29. account_confirmation: 'confirm',
  30. api_authentication: 'api'
  31. }
  32. validates :token, uniqueness: true, presence: true
  33. validates :user, presence: true
  34. belongs_to :user
  35. end