Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Custom registration back-end which auto-activates new user accounts
- without the need for a confirmation email.
- """
- # Library imports
- from django.contrib.auth import authenticate, login
- from django.contrib.sites.models import RequestSite
- from django.contrib.sites.models import Site
- from django.core.urlresolvers import reverse
- from registration import signals
- from registration.backends.default import DefaultBackend
- from registration.models import RegistrationProfile
- class AutoActivateBackend(DefaultBackend):
- """
- Over-rides DefaultBackend to stop confirmation emails being sent.
- """
- def register(self, request, **kwargs):
- """
- Suppresses the activation email, and makes the user active immediately
- """
- username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
- if Site._meta.installed: # pylint: disable-msg=W0212
- site = Site.objects.get_current()
- else:
- site = RequestSite(request)
- new_user = RegistrationProfile.objects.create_inactive_user(username, email,
- password, site,
- send_email=False)
- new_user.is_active = True
- new_user.save()
- signals.user_registered.send(sender=self.__class__,
- user=new_user,
- request=request)
- # Auto-login the new user.
- if new_user.is_authenticated():
- new_user = authenticate(username=username, password=password)
- if new_user is not None:
- login(request, new_user)
- return new_user
- def post_registration_redirect(self, request, user):
- """
- Logs the user in automatically, and redirects them to the welcome page
- """
- return (reverse('app_registration.views.forward'), (), {})
Add Comment
Please, Sign In to add comment