Skip to content

Instantly share code, notes, and snippets.

@pyaf
Last active March 24, 2017 11:22
Show Gist options
  • Save pyaf/99189d33712cbbef64aa2277efce5397 to your computer and use it in GitHub Desktop.
Save pyaf/99189d33712cbbef64aa2277efce5397 to your computer and use it in GitHub Desktop.
PhoneVerificationView
def PhoneVerificationView(request, **kwargs):
template_name = 'phone_confirm.html'
if request.method == "POST":
username = request.POST['username']
user = User.objects.get(username=username)
form = PhoneVerificationForm(request.POST)
if form.is_valid():
verification_code = request.POST['one_time_password']
response = verify_sent_code(verification_code, user)
print(response.text)
data = json.loads(response.text)
if data['success'] == True:
login(request, user)
if user.phone_number_verified is False:
user.phone_number_verified = True
user.save()
return redirect('/dashboard')
else:
messages.add_message(request, messages.ERROR,
data['message'])
return render(request, template_name, {'user':user})
else:
context = {
'user': user,
'form': form,
}
return render(request, template_name, context)
elif request.method == "GET":
try:
user = kwargs['user']
return render(request, template_name, {'user': user})
except:
return HttpResponse("Not Allowed")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment