def create_beta_user(backend,
                     details,
                     response,
                     uid,
                     username,
                     user=None,
                     *args,
                     **kwargs):
    """Create user. Depends on get_username pipeline."""
    if user:
        return {'user': user}
    if not username:
        return None

    if setting('BETA_ENABLE_BETA', True):
        request = kwargs['request']
        invitation_code = request.COOKIES.get('invitation_code', False)
        if not invitation_code:
            return HttpResponseRedirect(setting('BETA_REDIRECT_URL'))
        valid, exists = InvitationCode.validate_code(invitation_code)
        if not valid:
            return HttpResponseRedirect(setting('BETA_REDIRECT_URL'))

    email = details.get('email')
    user = User.objects.create_user(username=username, email=email)
    if setting('BETA_ENABLE_BETA', True):
        invite_used.send(sender=user,
                         user=user,
                         invitation_code=invitation_code)

    return {'user': user, 'is_new': True}
Ejemplo n.º 2
0
def create_beta_user(backend, details, response, uid, username, user=None,
                     *args, **kwargs):
    """Create user. Depends on get_username pipeline."""
    if user:
        return {'user': user}
    if not username:
        return None

    if setting('BETA_ENABLE_BETA', True):
        request = kwargs['request']
        invitation_code = request.COOKIES.get('invitation_code', False)
        if not invitation_code:
            return HttpResponseRedirect(setting('BETA_REDIRECT_URL'))
        valid, exists = InvitationCode.validate_code(invitation_code)
        if not valid:
            return HttpResponseRedirect(setting('BETA_REDIRECT_URL'))

    email = details.get('email')
    user = UserSocialAuth.objects.create_user(username=username, email=email)
    if setting('BETA_ENABLE_BETA', True):
        invite_used.send(sender=user, user=user, invitation_code=invitation_code)

    return {
        'user': user,
        'is_new': True
    }
Ejemplo n.º 3
0
    def process_view(self, request, view_func, view_args, view_kwargs):
        if request.path in self.allow_flatpages or '%s/' % request.path in self.allow_flatpages:
            from django.contrib.flatpages.views import flatpage
            return flatpage(request, request.path_info)

        if not self.enable_beta:
            #Do nothing is beta is not activated
            return

        invitation_code = request.COOKIES.get('invitation_code', '')
        in_beta, exists = InvitationCode.validate_code(invitation_code)
        whitelisted_modules = ['django.contrib.auth.views',
                               'django.contrib.admin.sites',
                               'django.views.static',
                               'django.contrib.staticfiles.views',
                               'hunger.views']

        short_name = view_func.__class__.__name__
        if short_name == 'function':
            short_name = view_func.__name__
        full_view_name = '%s.%s' % (view_func.__module__, short_name)

        #Check modules
        if self.always_allow_modules:
            whitelisted_modules += self.always_allow_modules

        #if view in module then ignore - except if view is signup confirmation
        if '%s' % view_func.__module__ in whitelisted_modules and not full_view_name == self.signup_confirmation_view:
            return

        #Check views
        if full_view_name in self.never_allow_views:
            return HttpResponseRedirect(self.redirect_url)

        if full_view_name in self.always_allow_views:
            return

        if full_view_name == self.signup_confirmation_view:
            #signup completed - deactivate invitation code
            request.session['beta_complete'] = True
            invite_used.send(sender=self.__class__, user=request.user, invitation_code=invitation_code)
            return

        if request.user.is_authenticated() and full_view_name not in self.signup_views:
            # User is logged in, or beta is not active, no need to check anything else.
            return

        if full_view_name in self.signup_views and in_beta:
            #if beta code is valid and trying to register then let them through
            return
        else:
            # next_page = request.META.get('REQUEST_URI')
            next_page = request.path
            if in_beta:
                return HttpResponseRedirect(self.signup_url + '?next=%s' % next_page)
            else:
                return HttpResponseRedirect(self.redirect_url + '?next=%s' % next_page)