Last active
March 24, 2017 11:12
-
-
Save pyaf/f8362d4677c5f3017c5b731d050f52bb to your computer and use it in GitHub Desktop.
RegisterView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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