Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.conf import settings
- from django.contrib.auth import authenticate, login
- from django.contrib.auth.models import User
- from registration.backends.default import DefaultBackend
- from registration.signals import user_registered
- import commonware.log
- log = commonware.log.getLogger(__name__)
- class ExistingUserBackend(DefaultBackend):
- def post_registration_redirect(self, request, user):
- """
- Return the name of the URL to redirect to after successful
- user registration.
- """
- return ('account:registration_complete', (), {})
- def post_activation_redirect(self, request, user):
- """
- Return the name of the URL to redirect to after successful
- account activation.
- """
- return ('account:registration_activation_complete', (), {})
- def register(self, request, **kwargs):
- if (request.user.is_authenticated() and
- request.user.get_profile().is_registered()):
- log.info("User %s is already authenticating -- not registering",
- request.user)
- return request.user
- email, password = kwargs['email'], kwargs['password1']
- log.info("Registering new user with email %s", email)
- user = User.objects.get_or_create(email=email,
- first_name=kwargs.get('first_name'),
- last_name=kwargs.get('last_name'))
- user.set_password(password)
- user.save()
- user = authenticate(username=user.username, password=password)
- login(request, user)
- user_registered.send(sender=self.__class__, user=user, request=request)
- return user
- def registration_allowed(self, request):
- allowed = getattr(settings, 'REGISTRATION_OPEN', True)
- if not allowed:
- return False
- if not getattr(settings, 'LIMITED_REGISTRATION', False):
- return True
- return self.check_access_token(request)
- def check_access_token(self, request):
- access_token = request.session.get('access_token', None)
- if access_token:
- # do what you need to do to validate the access token, return
- # True?False
- pass
Add Comment
Please, Sign In to add comment