Module: Users::PhoneAuthenticate

Included in:
User
Defined in:
lib/users/phone_authenticate.rb

Overview

This module provides methods for sending and verifying OTPs (One-Time Passwords) via phone numbers. It includes methods to send an OTP to a user’s phone number and to authenticate the user by verifying the OTP.

Instance Method Summary collapse

Instance Method Details

#authenticate_by_phone(otp) ⇒ User, false

This method authenticates the user by verifying the provided OTP. It uses the Otp::Verify service to check if the OTP is valid.

Parameters:

  • otp (String)

    The one-time password to verify.

Returns:

  • (User, false)

    Returns the user if authentication is successful, otherwise returns false.



17
18
19
20
21
22
23
24
# File 'lib/users/phone_authenticate.rb', line 17

def authenticate_by_phone(otp)
  if Otp::Verify.new(self, otp).authenticate
    # @type [User]
    self
  else
    false
  end
end

#send_otp(phone_number) ⇒ UserVerification

This method sends an OTP to the specified phone number. It uses the Otp::Send service to handle the OTP sending process.

Parameters:

  • phone_number (String)

    The phone number to which the OTP will be sent.

Returns:

  • (UserVerification)

    Returns the user verification record if the OTP is sent successfully.



9
10
11
# File 'lib/users/phone_authenticate.rb', line 9

def send_otp(phone_number)
  Otp::Send.new(self, phone_number).call
end