Module: Sorcery::Model::TemporaryToken::ClassMethods

Defined in:
lib/sorcery/model/temporary_token.rb

Instance Method Summary collapse

Instance Method Details

#load_from_token(token, token_attr_name, token_expiration_date_attr = nil, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sorcery/model/temporary_token.rb', line 21

def load_from_token(token, token_attr_name, token_expiration_date_attr = nil, &block)
  return token_response(failure: :invalid_token, &block) if token.blank?

  user = sorcery_adapter.find_by_token(token_attr_name, token)

  return token_response(failure: :user_not_found, &block) unless user

  unless check_expiration_date(user, token_expiration_date_attr)
    return token_response(user: user, failure: :token_expired, &block)
  end

  token_response(user: user, return_value: user, &block)
end