I making django webapp. on that webapp user can register with there email or phone number sometime user enter mobile number with country code and sometime user not enter country code that time i need get user ip address and find the country code and send that number to twilio lookup API and verify before send sms code.
What is the best way to do this one
def clean_email_or_phone(self):
bad_domains = ['']
email_or_phone = self.cleaned_data['email_or_phone']
if "@" in email_or_phone:
try:
validate_email(email_or_phone)
email_domain = self.cleaned_data['email_or_phone'].split('@')[1]
if email_domain in bad_domains:
raise forms.ValidationError(validators.FREE_EMAIL)
except forms.ValidationError:
raise forms.ValidationError(validators.FREE_EMAIL)
if User.objects.filter(email=email_or_phone).exists():
raise forms.ValidationError(validators.DUPLICATE_EMAIL)
else:
return email_or_phone
else part will mobile number verification
Thanks