require "uri" module Composable module Pwdless module Form class Authentication < Composable::Form::Command attribute :email validates :email, presence: true validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }, if: :email? def save # We don't want the code in the verification, otherwise the user will # set it on the subsequent request, which would undermine the whole thing. Form::Verification.new(salt: salt, data: email) end private delegate :code, :salt, to: :secret def secret @secret ||= Pwdless::Secret.create!(data: email) end end end end end