lib/models/phone.rb in devise_phone-0.1.21 vs lib/models/phone.rb in devise_phone-0.1.22

- old
+ new

@@ -7,26 +7,32 @@ included do # before_create :set_unverified_phone_attributes, :if => :phone_verification_needed? # after_create :private_generate_verification_code_and_send_sms, :if => :phone_verification_needed? # before_save :remember_old_phone_number - after_save :set_unverified_phone_attributes, :if => :regenerate_phone_verification_needed? + before_save :set_unverified_phone_attributes, :if => :regenerate_phone_verification_needed? end def generate_verification_code_and_send_sms(phone_number) - if(phone_verification_needed?) - private_generate_verification_code_and_send_sms(phone_number) - end - # self.save! + if(phone_verification_needed?) + private_generate_verification_code_and_send_sms(phone_number) + else + "Phone number #{phone_number} is already verified" end + # self.save! + end def verify_phone_number_with_code_entered(code_entered) - if phone_verification_needed? && (code_entered == self.phone_verification_code) - mark_phone_as_verified - true + if phone_verification_needed? + if code_entered == self.phone_verification_code + mark_phone_as_verified + nil + else + "Code entered does not match phone verification code in the database" + end else - false + "Phone number #{self.phone_number} is already verified" end end private @@ -46,37 +52,36 @@ self.phone_verified_at = DateTime.now end # check if phone verification is needed and set errors here def phone_verification_needed? - # if phone_number.blank? - # self.errors.add(:phone_verification_code, :empty_phone_number_field) - # false - # els if phone_number_verified - self.errors.add(:phone_verification_code, :phone_verification_not_needed) false else true end end def regenerate_phone_verification_needed? if phone_number.present? if phone_number_changed? + puts "yes regenerate phone code" true else + puts "no regenerate phone code" false end # self.errors.add(:phone_verification_code, :empty_phone_number_field) # false else + puts "noo regenerate phone code" false end end # set attributes to user indicating the phone number is unverified def set_unverified_phone_attributes + puts "setting phone unverified" self.phone_number_verified = false self.phone_verification_code_sent_at = DateTime.now self.phone_verified_at = nil # removes all white spaces, hyphens, and parenthesis # if self.phone_number