Advertisement
Guest User

Untitled

a guest
Jun 11th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. class SignupForm(authtoolsforms.UserCreationForm):
  2.  
  3. def __init__(self, *args, **kwargs):
  4. super(SignupForm, self).__init__(*args, **kwargs)
  5. self.helper = FormHelper()
  6. self.fields["email"].widget.input_type = "email" # ugly hack
  7. company_name = forms.CharField()
  8.  
  9. self.helper.layout = Layout(
  10. Field('email', placeholder="Enter Email", autofocus=""),
  11. Field('name', placeholder="Enter Full Name"),
  12. Field('company_name', placeholder="Company Name"),
  13. Field('password1', placeholder="Enter Password"),
  14. Field('password2', placeholder="Re-enter Password"),
  15. Submit('sign_up', 'Sign up', css_class="btn-warning"),
  16. )
  17.  
  18. class SignUpView(bracesviews.AnonymousRequiredMixin,
  19. bracesviews.FormValidMessageMixin,
  20. generic.CreateView):
  21. form_class = forms.SignupForm
  22. model = User
  23. template_name = 'accounts/signup.html'
  24. success_url = reverse_lazy('home')
  25. form_valid_message = "You're signed up!"
  26.  
  27. def form_valid(self, form):
  28. r = super(SignUpView, self).form_valid(form)
  29. username = form.cleaned_data["email"]
  30. password = form.cleaned_data["password1"]
  31. user = auth.authenticate(email=username, password=password)
  32. auth.login(self.request, user)
  33. return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement