Module: Keymail::Authentication

Defined in:
app/models/keymail/authentication.rb

Class Method Summary collapse

Class Method Details

.request(email) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
10
# File 'app/models/keymail/authentication.rb', line 3

def self.request(email)
  raise ArgumentError, 'Email cannot be nil' if email.nil?

  token = Token.create!(email: email, expires_at: Keymail.config.expiration_time.since)
  AuthMailer.(token).deliver

  token
end

.verify_url_key(url_key) ⇒ Object



12
13
14
15
16
17
18
19
# File 'app/models/keymail/authentication.rb', line 12

def self.verify_url_key(url_key)
  token = find_and_destroy_token(url_key)

  return Failure.new if token.nil?
  return Expired.new(token) if token.expired?

  Success.new(token)
end