Created
March 29, 2011 23:59
-
-
Save peplin/893608 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment