Sprankelprachtig aan/afmeldsysteem

session.rb 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  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 self.new_token
  24. SecureRandom.urlsafe_base64
  25. end
  26. # @return [String] a BCrypt digest of the given string.
  27. def self.digest(string)
  28. cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
  29. BCrypt::Password.create(string, cost: cost)
  30. end
  31. end