Class: StandardId::Web::VerifyPhone::StartController

Inherits:
BaseController show all
Defined in:
app/controllers/standard_id/web/verify_phone/start_controller.rb

Constant Summary

Constants included from RateLimitHandling

RateLimitHandling::RATE_LIMIT_STORE

Instance Method Summary collapse

Methods included from StandardId::WebAuthentication

#current_account, #current_scope_names, #current_session, #revoke_current_session!

Methods included from ControllerPolicy

all_controllers, authenticated_controllers, public_controllers, register, registry_snapshot, reset_registry!

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/standard_id/web/verify_phone/start_controller.rb', line 24

def create
  phone = params[:phone_number].to_s.strip
  if phone.blank? || !(phone.match?(/\A\+?[1-9]\d{1,14}\z/))
    flash[:alert] = "Please enter a valid phone number"
    render plain: "invalid phone", status: :unprocessable_content and return
  end

  challenge = StandardId::CodeChallenge.create!(
    realm: "verification",
    channel: "sms",
    target: phone,
    code: generate_otp_code,
    expires_at: 10.minutes.from_now,
    ip_address: StandardId::Utils::IpNormalizer.normalize(request.remote_ip),
    user_agent: request.user_agent
  )

  StandardId.config.passwordless_sms_sender&.call(phone, challenge.code)

  redirect_to standard_id_web., notice: "Verification code sent via SMS", status: :see_other
end

#showObject



20
21
22
# File 'app/controllers/standard_id/web/verify_phone/start_controller.rb', line 20

def show
  render plain: "verify phone start", status: :ok
end