Module: TwilioPhoneVerification::Phonable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/twilio_phone_verification/phonable.rb
Instance Method Summary collapse
- #change_phone_confirmed_at ⇒ Object
- #confirm_phone ⇒ Object
- #confirm_phone_by_code(code) ⇒ Object
- #generate_phone_confirmation_token ⇒ Object
- #phone_confirmed? ⇒ Boolean
- #send_phone_confirmation ⇒ Object
Instance Method Details
#change_phone_confirmed_at ⇒ Object
14 15 16 |
# File 'lib/twilio_phone_verification/phonable.rb', line 14 def change_phone_confirmed_at self.phone_confirmed_at = nil end |
#confirm_phone ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/twilio_phone_verification/phonable.rb', line 46 def confirm_phone if phone_confirmed? errors.add(:phone, "has already been confirmed.") return false end self.phone_confirmed_at = Time.now save end |
#confirm_phone_by_code(code) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/twilio_phone_verification/phonable.rb', line 37 def confirm_phone_by_code(code) if phone_confirmation_token == code.to_s return confirm_phone else errors.add(:code, " is wrong, try again.") return false end end |
#generate_phone_confirmation_token ⇒ Object
55 56 57 58 59 |
# File 'lib/twilio_phone_verification/phonable.rb', line 55 def generate_phone_confirmation_token self.phone_confirmation_token = get_phone_confirmation_token self.phone_confirmation_sent_at = Time.now save end |
#phone_confirmed? ⇒ Boolean
10 11 12 |
# File 'lib/twilio_phone_verification/phonable.rb', line 10 def phone_confirmed? !!phone_confirmed_at end |
#send_phone_confirmation ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/twilio_phone_verification/phonable.rb', line 18 def send_phone_confirmation if phone_confirmed? errors.add(:phone, "has already been confirmed.") return false end if !phone_confirmation_sent_at || Time.now - phone_confirmation_sent_at > phone_confirmation_delay generate_phone_confirmation_token twilio_res = TwilioPhoneVerification::TwilioService.(, phone) unless twilio_res[:success] errors.add(:phone, "Error occured, while sending code. Please try again later.") return false end twilio_res else errors.add(:code, "can be sent once per #{phone_confirmation_delay.to_s} seconds.") return false end end |