Guest User

Untitled

a guest
Jul 18th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Custom registration back-end which auto-activates new user accounts
  4. without the need for a confirmation email.
  5.  
  6. """
  7.  
  8. # Library imports
  9. from django.contrib.auth import authenticate, login
  10. from django.contrib.sites.models import RequestSite
  11. from django.contrib.sites.models import Site
  12. from django.core.urlresolvers import reverse
  13. from registration import signals
  14. from registration.backends.default import DefaultBackend
  15. from registration.models import RegistrationProfile
  16.  
  17. class AutoActivateBackend(DefaultBackend):
  18. """
  19. Over-rides DefaultBackend to stop confirmation emails being sent.
  20.  
  21. """
  22.  
  23. def register(self, request, **kwargs):
  24. """
  25. Suppresses the activation email, and makes the user active immediately
  26.  
  27. """
  28. username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
  29. if Site._meta.installed: # pylint: disable-msg=W0212
  30. site = Site.objects.get_current()
  31. else:
  32. site = RequestSite(request)
  33. new_user = RegistrationProfile.objects.create_inactive_user(username, email,
  34. password, site,
  35. send_email=False)
  36. new_user.is_active = True
  37. new_user.save()
  38. signals.user_registered.send(sender=self.__class__,
  39. user=new_user,
  40. request=request)
  41.  
  42. # Auto-login the new user.
  43. if new_user.is_authenticated():
  44. new_user = authenticate(username=username, password=password)
  45. if new_user is not None:
  46. login(request, new_user)
  47.  
  48. return new_user
  49.  
  50. def post_registration_redirect(self, request, user):
  51. """
  52. Logs the user in automatically, and redirects them to the welcome page
  53.  
  54. """
  55. return (reverse('app_registration.views.forward'), (), {})
Add Comment
Please, Sign In to add comment