9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/controllers/standard_id/web/verify_phone/start_controller.rb', line 9
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: request.remote_ip,
user_agent: request.user_agent
)
StandardId.config.passwordless_sms_sender&.call(phone, challenge.code)
redirect_to standard_id_web.login_path, notice: "Verification code sent via SMS", status: :see_other
end
|