Sprankelprachtig aan/afmeldsysteem

session.rb 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. # A Session contains the information about a logged-in user.
  2. class Session < ApplicationRecord
  3. # @!attribute ip
  4. # @return [String]
  5. # the IP address of the client that started the session.
  6. #
  7. # @!attribute expires
  8. # @return [TimeWithZone]
  9. # when the user must be logged out.
  10. #
  11. # @!attribute remember_digest
  12. # @return [String]
  13. # a salted hash of the user's remember token. This token may be used if
  14. # the user continues a session by using the 'remember me' option.
  15. #
  16. # @!attribute active
  17. # @return [Boolean]
  18. # whether or not the session may still be used to authenticate.
  19. # Inactive sessions may be retained for logging, but must not allow a user
  20. # to continue using the system.
  21. belongs_to :user
  22. # @return [String] a new random token.
  23. def Session.new_token
  24. SecureRandom.urlsafe_base64
  25. end
  26. # @return [String] a BCrypt digest of the given string.
  27. def Session.digest(string)
  28. cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
  29. BCrypt::Engine.cost
  30. BCrypt::Password.create(string, cost: cost)
  31. end
  32. end