send OTP using sms to verify phone number upon first time registerationn using Django and Twilio
Budget: $10 – $40 USD
I have a Django web app. I made registration form that is working with no issue. I want to add to it the OTP code to verify the entered phone number for only one time when the user register for the first time. (no need for login or out). So user can not sign up unless entered the sms code then the account will be created. I have my own registeration code that I do not want to change. Now, when the user fill in the form, the form will be submitted through ajax request. If there are errors, the errors will show up for user to correct them. If the form is valid, then sms will be sent to the entered phone and a new page with have the field for getting the sent code.
I want some body help me to finish the code as follow:
1- Write a custom code to generate the OTP and send it using twilio (the account is ready and tested)
2- Save the generated code in session alongside with other user model that have been validated
3- If the user submit the code form with correct OTP the account will be created and user will be active
4- If the user fail, there will be a button to send a new code if the user chose to. However, the user will be allowed to try only 3 times, if does not success, the user will be prevented from register for next 12 hours
5- If user success the account is created and user is active
NO plugin is allowed
HERE IS THE VIEW FUNCTION FOR REGISTERATION:
def LMRegisterSubmitForm(request):
if request.method == 'POST' and request.is_ajax:
form = LMUserRegisterForm(request.POST or None)
if form.is_valid():
user = form.save(commit=False)
# deactive user untill click the url sent to a user email
user.is_active = False
user.is_staff = False
user.is_superuser = False
password = form.cleaned_data['password']
user.set_password(password)
# user.save()
# save new registered user's data into session
request.session['new_user_info'] = user
# to register new password into user pass word record model
# password_log = PasswordLog()
# password_log.user = user
# password_log.password = user.password
# password_log.save()
# send sms to the phone
data = {
'success': 'تم إنشاء الحساب بنجاح.',
}
data = json.dumps(data, indent=4, sort_keys=False, default=str)
return JsonResponse(data, safe=False)
else:
errors = dict(form.errors)
data = {
'fail': 'لقد تعذر تسجيل حسابك، هناك بعض الأخطاء بالحقول المدخلة. يرجى تعديلها والمحاولة من جديد',
'errors': errors,
}
data = json.dumps(data, indent=4, sort_keys=False, default=str)
return JsonResponse(data, safe=False)
else:
return redirect("register")
I want some body help me to finish the code as follow:
1- Write a custom code to generate the OTP and send it using twilio (the account is ready and tested)
2- Save the generated code in session alongside with other user model that have been validated
3- If the user submit the code form with correct OTP the account will be created and user will be active
4- If the user fail, there will be a button to send a new code if the user chose to. However, the user will be allowed to try only 3 times, if does not success, the user will be prevented from register for next 12 hours
5- If user success the account is created and user is active
NO plugin is allowed
HERE IS THE VIEW FUNCTION FOR REGISTERATION:
def LMRegisterSubmitForm(request):
if request.method == 'POST' and request.is_ajax:
form = LMUserRegisterForm(request.POST or None)
if form.is_valid():
user = form.save(commit=False)
# deactive user untill click the url sent to a user email
user.is_active = False
user.is_staff = False
user.is_superuser = False
password = form.cleaned_data['password']
user.set_password(password)
# user.save()
# save new registered user's data into session
request.session['new_user_info'] = user
# to register new password into user pass word record model
# password_log = PasswordLog()
# password_log.user = user
# password_log.password = user.password
# password_log.save()
# send sms to the phone
data = {
'success': 'تم إنشاء الحساب بنجاح.',
}
data = json.dumps(data, indent=4, sort_keys=False, default=str)
return JsonResponse(data, safe=False)
else:
errors = dict(form.errors)
data = {
'fail': 'لقد تعذر تسجيل حسابك، هناك بعض الأخطاء بالحقول المدخلة. يرجى تعديلها والمحاولة من جديد',
'errors': errors,
}
data = json.dumps(data, indent=4, sort_keys=False, default=str)
return JsonResponse(data, safe=False)
else:
return redirect("register")