Class: Passwordless::Session

Inherits:
ApplicationRecord show all
Defined in:
app/models/passwordless/session.rb

Overview

The session responsible for holding the connection between the record trying to log in and the unique tokens.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.validObject



30
31
32
# File 'app/models/passwordless/session.rb', line 30

def self.valid
  available
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/passwordless/session.rb', line 55

def available?
  !expired?
end

#claim!Object



46
47
48
49
# File 'app/models/passwordless/session.rb', line 46

def claim!
  raise Errors::TokenAlreadyClaimedError if claimed?
  touch(:claimed_at)
end

#claimed?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/models/passwordless/session.rb', line 51

def claimed?
  !!claimed_at
end

#expired?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/passwordless/session.rb', line 38

def expired?
  expires_at <= Time.current
end

#timed_out?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/passwordless/session.rb', line 42

def timed_out?
  timeout_at <= Time.current
end