Skip to content

Instantly share code, notes, and snippets.

@pyaf
Last active March 24, 2017 11:12
Show Gist options
  • Save pyaf/f8362d4677c5f3017c5b731d050f52bb to your computer and use it in GitHub Desktop.
Save pyaf/f8362d4677c5f3017c5b731d050f52bb to your computer and use it in GitHub Desktop.
RegisterView
class RegisterView(SuccessMessageMixin, FormView):
template_name = 'register.html'
form_class = RegisterForm
success_message = "One-Time password sent to your registered mobile number.\
The verification code is valid for 10 minutes."
def form_valid(self, form):
user = form.save()
username = self.request.POST['username']
password = self.request.POST['password1']
user = authenticate(username=username, password=password)
try:
response = send_verfication_code(user)
except Exception as e:
messages.add_message(self.request, messages.ERROR,
'verification code not sent. \n'
'Please re-register.')
return redirect('/register')
data = json.loads(response.text)
print(response.status_code, response.reason)
print(response.text)
print(data['success'])
if data['success'] == False:
messages.add_message(self.request, messages.ERROR,
data['message'])
return redirect('/register')
else:
kwargs = {'user': user}
self.request.method = 'GET'
return PhoneVerificationView(self.request, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment