Class: PhoneVerificationForGuestService
- Inherits:
-
PhoneVerificationService
- Object
- ApplicationService
- PhoneVerificationService
- PhoneVerificationForGuestService
- Defined in:
- app/services/phone_verification_for_guest_service.rb
Overview
Guest otp request and verification
Instance Attribute Summary
Attributes inherited from PhoneVerificationService
#expiry_time, #first_request, #session, #verification_code
Attributes inherited from ApplicationService
Instance Method Summary collapse
-
#initialize(phone, verification_code = nil, **options) ⇒ PhoneVerificationForGuestService
constructor
A new instance of PhoneVerificationForGuestService.
- #request_code ⇒ Object
- #verify ⇒ Object
Methods inherited from PhoneVerificationService
#build_otp_record, #generated_code, #get_domain_name, #match?, #otp_time_update, #phone_data_temp, #request_data_otp, #send_sms, #send_sms_otp, #user_verification_enabled?
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Methods inherited from ApplicationService
Constructor Details
#initialize(phone, verification_code = nil, **options) ⇒ PhoneVerificationForGuestService
Returns a new instance of PhoneVerificationForGuestService.
3 4 5 6 7 8 9 10 11 |
# File 'app/services/phone_verification_for_guest_service.rb', line 3 def initialize(phone, verification_code = nil, **) @ph = Phonelib.parse(phone) @phone = "#{@ph.country_code}#{@ph.raw_national}" @verification_code = verification_code.to_i session = [:session] expiry_time = .fetch(:expiry_time, 183.seconds) first_request = .fetch(:first_request, false) super(@phone, @verification_code, session: session, expiry_time: expiry_time, first_request: first_request) end |
Instance Method Details
#request_code ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/phone_verification_for_guest_service.rb', line 13 def request_code errors.clear if phone_data_temp.present? && phone_data_temp[:is_verified] raise InvalidPhoneVerification, 'Phone number has been verified' end if @ph.country_code != '66' || !user_verification_enabled? raise InvalidPhoneVerification, 'Phone number has been verified' end build_otp_record if errors.present? ServiceResult.new errors: errors, message: else ServiceResult.new data: phone_data_temp end rescue InvalidPhoneVerification => e errors.add :base, e. ServiceResult.new errors: errors, message: end |
#verify ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/phone_verification_for_guest_service.rb', line 35 def verify errors.clear raise InvalidPhoneVerification, 'Failed to verify phone number' if phone_data_temp.nil? raise InvalidPhoneVerification, 'Verification code is wrong' unless match? phone_data_temp(true, phone_data_temp[:code]) if errors.present? ServiceResult.new errors: errors, message: else ServiceResult.new data: phone_data_temp end rescue InvalidPhoneVerification => e errors.add :base, e. ServiceResult.new errors: errors, message: end |