Пример #1
0
def _register_user(request, facebook, profile_callback=None,
                   remove_old_connections=False):
    '''
    Creates a new user and authenticates
    The registration form handles the registration and validation
    Other data on the user profile is updates afterwards

    if remove_old_connections = True we will disconnect old
    profiles from their facebook flow
    '''
    if not facebook.is_authenticated():
        raise ValueError(
            'Facebook needs to be authenticated for connect flows')

    # get the backend on new registration systems, or none
    # if we are on an older version
    backend = get_registration_backend()
    logger.info('running backend %s for registration', backend)

    # gets the form class specified in FACEBOOK_REGISTRATION_FORM
    form_class = get_form_class(backend, request)

    facebook_data = facebook.facebook_registration_data()

    data = request.POST.copy()
    for k, v in facebook_data.items():
        if not data.get(k):
            data[k] = v
    if remove_old_connections:
        _remove_old_connections(facebook_data['facebook_id'])

    if request.REQUEST.get('force_registration_hard'):
        data['email'] = data['email'].replace(
            '@', '+test%s@' % randint(0, 1000000000))

    form = form_class(data=data, files=request.FILES,
                      initial={'ip': request.META['REMOTE_ADDR']})

    if not form.is_valid():
        # show errors in sentry
        form_errors = form.errors
        error = facebook_exceptions.IncompleteProfileError(
            'Facebook signup incomplete')
        error.form = form
        raise error

    try:
        # for new registration systems use the backends methods of saving
        new_user = None
        if backend:
            new_user = backend.register(request,
                                        form=form, **form.cleaned_data)
        # fall back to the form approach
        if new_user is None:
            raise ValueError(
                'new_user is None, note that backward compatability for the older versions of django registration has been dropped.')
    except IntegrityError, e:
        # this happens when users click multiple times, the first request registers
        # the second one raises an error
        raise facebook_exceptions.AlreadyRegistered(e)
Пример #2
0
def _register_user(request, facebook, profile_callback=None,
                   remove_old_connections=False):
    '''
    Creates a new user and authenticates
    The registration form handles the registration and validation
    Other data on the user profile is updates afterwards

    if remove_old_connections = True we will disconnect old
    profiles from their facebook flow
    '''
    if not facebook.is_authenticated():
        raise ValueError(
            'Facebook needs to be authenticated for connect flows')

    # get the backend on new registration systems, or none
    # if we are on an older version
    backend = get_registration_backend()
    logger.info('running backend %s for registration', backend)

    # gets the form class specified in FACEBOOK_REGISTRATION_FORM
    form_class = get_form_class(backend, request)

    facebook_data = facebook.facebook_registration_data()

    data = request.POST.copy()
    for k, v in facebook_data.items():
        if not data.get(k):
            data[k] = v
    if remove_old_connections:
        _remove_old_connections(facebook_data['facebook_id'])

    if request.REQUEST.get('force_registration_hard'):
        data['email'] = data['email'].replace(
            '@', '+test%s@' % randint(0, 1000000000))

    form = form_class(data=data, files=request.FILES,
                      initial={'ip': request.META['REMOTE_ADDR']})

    if not form.is_valid():
        # show errors in sentry
        form_errors = form.errors
        error = facebook_exceptions.IncompleteProfileError(
            'Facebook signup incomplete')
        error.form = form
        raise error

    try:
        # for new registration systems use the backends methods of saving
        new_user = None
        if backend:
            new_user = backend.register(request,
                                        form=form, **form.cleaned_data)
        # fall back to the form approach
        if new_user is None:
            raise ValueError(
                'new_user is None, note that backward compatability for the older versions of django registration has been dropped.')
    except IntegrityError, e:
        # this happens when users click multiple times, the first request registers
        # the second one raises an error
        raise facebook_exceptions.AlreadyRegistered(e)
Пример #3
0
def _register_user(request, facebook, profile_callback=None):
    '''
    Creates a new user and authenticates
    The registration form handles the registration and validation
    Other data on the user profile is updates afterwards
    '''
    if not facebook.is_authenticated():
        raise ValueError(
            'Facebook needs to be authenticated for connect flows')

    #get the backend on new registration systems, or none if we are on an older version
    backend = get_registration_backend()

    #gets the form class specified in FACEBOOK_REGISTRATION_FORM
    form_class = get_form_class(backend, request)

    facebook_data = facebook.facebook_registration_data()

    data = request.POST.copy()
    for k, v in facebook_data.items():
        if not data.get(k):
            data[k] = v

    if request.REQUEST.get('force_registration_hard'):
        data['email'] = data['email'].replace('@', '+%s@' % randint(0, 100000))

    form = form_class(data=data,
                      files=request.FILES,
                      initial={'ip': request.META['REMOTE_ADDR']})

    if not form.is_valid():
        error = facebook_exceptions.IncompleteProfileError(
            'Facebook data %s '
            'gave error %s' % (facebook_data, form.errors))
        error.form = form
        raise error

    #for new registration systems use the backends methods of saving
    if backend:
        new_user = backend.register(request, **form.cleaned_data)
    else:
        # For backward compatibility, if django-registration form is used
        try:
            new_user = form.save(profile_callback=profile_callback)
        except TypeError:
            new_user = form.save()

    signals.facebook_user_registered.send(sender=get_profile_class(),
                                          user=new_user,
                                          facebook_data=facebook_data)

    #update some extra data not yet done by the form
    new_user = _update_user(new_user, facebook)

    # IS this the correct way for django 1.3? seems to require the backend
    # attribute for some reason
    new_user.backend = 'django_facebook.auth_backends.FacebookBackend'
    auth.login(request, new_user)

    return new_user
Пример #4
0
def _register_user(request, facebook, profile_callback=None):
    '''
    Creates a new user and authenticates
    The registration form handles the registration and validation
    Other data on the user profile is updates afterwards
    '''
    if not facebook.is_authenticated():
        raise ValueError('Facebook needs to be authenticated for connect flows')
    
    
    
    #get the backend on new registration systems, or none if we are on an older version
    backend = get_registration_backend()

    #gets the form class specified in FACEBOOK_REGISTRATION_FORM
    form_class = get_form_class(backend, request)

    facebook_data = facebook.facebook_registration_data()

    data = request.POST.copy()
    for k, v in facebook_data.items():
        if not data.get(k):
            data[k] = v

    if request.REQUEST.get('force_registration_hard'):
        data['email'] = data['email'].replace('@', '+%s@' % randint(0, 100000))

    form = form_class(data=data, files=request.FILES,
        initial={'ip': request.META['REMOTE_ADDR']})

    if not form.is_valid():
        error = facebook_exceptions.IncompleteProfileError('Facebook data %s '
            'gave error %s' % (facebook_data, form.errors))
        error.form = form
        raise error

    #for new registration systems use the backends methods of saving
    if backend:
        new_user = backend.register(request, **form.cleaned_data)
    else:
        # For backward compatibility, if django-registration form is used
        try:
            new_user = form.save(profile_callback=profile_callback)
        except TypeError:
            new_user = form.save()
    
    signals.facebook_user_registered.send(sender=get_profile_class(),
        user=new_user, facebook_data=facebook_data)
    
    #update some extra data not yet done by the form
    new_user = _update_user(new_user, facebook)

    # IS this the correct way for django 1.3? seems to require the backend
    # attribute for some reason
    new_user.backend = 'django_facebook.auth_backends.FacebookBackend'
    auth.login(request, new_user)

    return new_user
Пример #5
0
def _register_user(request, facebook, profile_callback=None, remove_old_connections=False):
    """
    Creates a new user and authenticates
    The registration form handles the registration and validation
    Other data on the user profile is updates afterwards

    if remove_old_connections = True we will disconnect old
    profiles from their facebook flow
    """
    if not facebook.is_authenticated():
        raise ValueError("Facebook needs to be authenticated for connect flows")

    # get the backend on new registration systems, or none
    # if we are on an older version
    backend = get_registration_backend()
    logger.info("running backend %s for registration", backend)

    # gets the form class specified in FACEBOOK_REGISTRATION_FORM
    form_class = get_form_class(backend, request)

    facebook_data = facebook.facebook_registration_data()

    data = request.POST.copy()
    for k, v in facebook_data.items():
        if not data.get(k):
            data[k] = v
    if remove_old_connections:
        _remove_old_connections(facebook_data["facebook_id"])

    if request.REQUEST.get("force_registration_hard"):
        data["email"] = data["email"].replace("@", "+test%s@" % randint(0, 1000000000))

    form = form_class(data=data, files=request.FILES, initial={"ip": request.META["REMOTE_ADDR"]})

    if not form.is_valid():
        error_message_format = u"Facebook data %s gave error %s"
        error_message = error_message_format % (facebook_data, form.errors)
        error = facebook_exceptions.IncompleteProfileError(error_message)
        error.form = form
        raise error

    try:
        # for new registration systems use the backends methods of saving
        new_user = None
        if backend:
            new_user = backend.register(request, **form.cleaned_data)
        # fall back to the form approach
        if not new_user:
            # For backward compatibility, if django-registration form is used
            try:
                new_user = form.save(profile_callback=profile_callback)
            except TypeError:
                new_user = form.save()
    except IntegrityError, e:
        # this happens when users click multiple times, the first request registers
        # the second one raises an error
        logger.warn("IntegrityError in _register_user")
        raise facebook_exceptions.AlreadyRegistered(e)
Пример #6
0
def _register_user(request, facebook, profile_callback=None, remove_old_connections=False):
    """
    Creates a new user and authenticates
    The registration form handles the registration and validation
    Other data on the user profile is updates afterwards

    if remove_old_connections = True we will disconnect old
    profiles from their facebook flow
    """
    if not facebook.is_authenticated():
        raise ValueError("Facebook needs to be authenticated for connect flows")

    # get the backend on new registration systems, or none
    # if we are on an older version
    backend = get_registration_backend()
    logger.info("running backend %s for registration", backend)

    # gets the form class specified in FACEBOOK_REGISTRATION_FORM
    form_class = get_form_class(backend, request)

    facebook_data = facebook.facebook_registration_data()

    data = request.POST.copy()
    for k, v in facebook_data.items():
        if not data.get(k):
            data[k] = v
    if remove_old_connections:
        _remove_old_connections(facebook_data["facebook_id"])

    if request.REQUEST.get("force_registration_hard"):
        data["email"] = data["email"].replace("@", "+test%s@" % randint(0, 1000000000))

    form = form_class(data=data, files=request.FILES, initial={"ip": request.META["REMOTE_ADDR"]})

    if not form.is_valid():
        error_message_format = u"Facebook data %s gave error %s"
        error_message = error_message_format % (facebook_data, form.errors)
        error = facebook_exceptions.IncompleteProfileError(error_message)
        error.form = form
        raise error

    # for new registration systems use the backends methods of saving
    new_user = None
    if backend:
        new_user = backend.register(request, **form.cleaned_data)
    # fall back to the form approach
    if not new_user:
        # For backward compatibility, if django-registration form is used
        try:
            new_user = form.save(profile_callback=profile_callback)
        except TypeError:
            new_user = form.save()

    signals.facebook_user_registered.send(sender=auth.models.User, user=new_user, facebook_data=facebook_data)

    # update some extra data not yet done by the form
    new_user = _update_user(new_user, facebook)

    # IS this the correct way for django 1.3? seems to require the backend
    # attribute for some reason
    new_user.backend = "django_facebook.auth_backends.FacebookBackend"
    auth.login(request, new_user)

    return new_user
Пример #7
0
def _register_user(request, facebook, profile_callback=None,
                   remove_old_connections=False):
    '''
    Creates a new user and authenticates
    The registration form handles the registration and validation
    Other data on the user profile is updates afterwards

    if remove_old_connections = True we will disconnect old
    profiles from their facebook flow
    '''
    if not facebook.is_authenticated():
        raise ValueError(
            'Facebook needs to be authenticated for connect flows')

    # get the backend on new registration systems, or none
    # if we are on an older version
    backend = get_registration_backend()
    logger.info('running backend %s for registration', backend)

    # gets the form class specified in FACEBOOK_REGISTRATION_FORM
    form_class = get_form_class(backend, request)
    print("0")

    facebook_data = facebook.facebook_registration_data()
    print("1")
    data = request.POST.copy()
    print("2")

    for k, v in facebook_data.items():
        if not data.get(k):
            data[k] = v
    print("3")

    if remove_old_connections:
        _remove_old_connections(facebook_data['facebook_id'])
    print("4")

    if request.REQUEST.get('force_registration_hard'):
        data['email'] = data['email'].replace(
            '@', '+test%s@' % randint(0, 1000000000))
    print("debug facebook data ", facebook_data, " data ", data)
    try:
        form = form_class(data=data, files=request.FILES,
                          initial={'ip': request.META['REMOTE_ADDR']})
        if not form.is_valid():
            # show errors in sentry
            form_errors = form.errors
            error = facebook_exceptions.IncompleteProfileError(
                'Facebook signup incomplete')
            error.form = form
            raise error

    except facebook_exceptions.AlreadyRegistered:
        print("re raised!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") # TODO
        raise facebook_exceptions.AlreadyRegistered(_("This email address is already in use. Please supply a different email address."))
    print("debug33", data["facebook_id"])
    print("debug34", form.cleaned_data)

    try:
        # for new registration systems use the backends methods of saving
        new_user = None
        if backend:
            new_user = backend.register(request,
                                        form=form, **form.cleaned_data)
        # fall back to the form approach
        if new_user is None:
            raise ValueError(
                'new_user is None, note that backward compatability for the older versions of django registration has been dropped.')
    except IntegrityError as e:
        # this happens when users click multiple times, the first request registers
        # the second one raises an error
        raise facebook_exceptions.AlreadyRegistered(e)

    # update some extra data not yet done by the form
    print("debu4", new_user.facebook_id)
    new_user = _update_user(new_user, facebook)
    print("debu5", new_user.facebook_id)

    new_user.facebook_id = data["facebook_id"]
    new_user.raw_data = data
    new_user.save()

    signals.facebook_user_registered.send(sender=get_user_model(),
                                          user=new_user, facebook_data=facebook_data, request=request, converter=facebook)
    # IS this the correct way for django 1.3? seems to require the backend
    # attribute for some reason
    new_user.backend = 'django_facebook.auth_backends.FacebookBackend'
    auth.login(request, new_user)

    return new_user
Пример #8
0
def _register_user(request, facebook, profile_callback=None,
                   remove_old_connections=False):
    '''
    Creates a new user and authenticates
    The registration form handles the registration and validation
    Other data on the user profile is updates afterwards

    if remove_old_connections = True we will disconnect old
    profiles from their facebook flow
    '''
    if not facebook.is_authenticated():
        raise ValueError(
            'Facebook needs to be authenticated for connect flows')

    # get the backend on new registration systems, or none
    # if we are on an older version
    backend = get_registration_backend()
    logger.info('running backend %s for registration', backend)

    # gets the form class specified in FACEBOOK_REGISTRATION_FORM
    form_class = get_form_class(backend, request)

    facebook_data = facebook.facebook_registration_data()

    data = request.POST.copy()
    logger.info('data for registration form %s', data)
    for k, v in facebook_data.items():
        if not data.get(k):
            data[k] = v
    if remove_old_connections:
        _remove_old_connections(facebook_data['facebook_id'])

    if request.REQUEST.get('force_registration_hard'):
        data['email'] = data['email'].replace(
            '@', '+test%s@' % randint(0, 1000000000))

    form = form_class(data=data, files=request.FILES,
                      initial={'ip': request.META['REMOTE_ADDR']})

    # BONGOMAGIC-1005 We need to attach facebook user profile to the already registered users
    # We don't want to create new one and show form error
    email = data['email']
    existing_users = get_user_model().objects.filter(email=email)
    logger.info("RU01 found users with email %s : %s " % (email, existing_users))
    existing_user = None
    new_user = None
    for _existing_user in existing_users:
        if not _existing_user.is_client() and not _existing_user.is_subclient():
            existing_user = _existing_user
            break
    logger.info("RU02 Possible to attach fb profile to user %s " % existing_user)
    if existing_user:
        new_fb_profile = FacebookUserProfile.objects.create(user=existing_user)
        logger.info("RU03 Created new fb profile %s " % new_fb_profile)
        new_user = existing_user

    if not existing_user:
        logger.info("RU04 No existing user, need to create one")
        if not form.is_valid():
            # show errors in sentry
            form_errors = form.errors
            error = facebook_exceptions.IncompleteProfileError(
                'Facebook signup incomplete')
            error.form = form
            raise error
        try:
            # for new registration systems use the backends methods of saving
            if backend:
                new_user = backend.register(request,
                                            form=form, **form.cleaned_data)
            # fall back to the form approach
            if new_user is None:
                raise ValueError(
                    'new_user is None, note that backward compatability for the older versions of django registration has been dropped.')
        except IntegrityError, e:
            # this happens when users click multiple times, the first request registers
            # the second one raises an error
            raise facebook_exceptions.AlreadyRegistered(e)

        signals.facebook_user_registered.send(sender=get_user_model(),
                                              user=new_user, facebook_data=facebook_data, request=request)
Пример #9
0
def _register_user(request, facebook, profile_callback=None,
                   remove_old_connections=False,graph = None):
    '''
    Creates a new user and authenticates
    The registration form handles the registration and validation
    Other data on the user profile is updates afterwards

    if remove_old_connections = True we will disconnect old
    profiles from their facebook flow
    '''
    if not facebook.is_authenticated():
        raise ValueError(
            'Facebook needs to be authenticated for connect flows')

    # get the backend on new registration systems, or none
    # if we are on an older version
    backend = get_registration_backend()
    logger.info('running backend %s for registration', backend)

    # gets the form class specified in FACEBOOK_REGISTRATION_FORM
    form_class = get_form_class(backend, request)
    # print form_class

    facebook_data = facebook.facebook_registration_data()

    data = request.POST.copy()
    for k, v in facebook_data.items():
        if not data.get(k):
            data[k] = v
    if graph:
            try:
                from meetme.users.tasks import get_facebook_email
                data['email'] = get_facebook_email(graph.access_token)['email']
            except:
                data['email']= create_random_username()
    if remove_old_connections:
        _remove_old_connections(facebook_data['facebook_id'])

    if request.REQUEST.get('force_registration_hard'):
        data['email'] = data['email'].replace(
            '@', '+test%s@' % randint(0, 1000000000))

    form = form_class(data=data, files=request.FILES,
                      initial={'ip': request.META['REMOTE_ADDR']})
    # print form

    if not form.is_valid():
        print "Form is invalid"
        # show errors in sentry
        form_errors = form.errors
        error = facebook_exceptions.IncompleteProfileError(
            'Facebook signup incomplete')
        error.form = form
        raise error

    try:
        # for new registration systems use the backends methods of saving
        new_user = None
        if backend:
            new_user = backend.register(request,
                                        form=form, **form.cleaned_data)
        # fall back to the form approach
        if new_user is None:
            raise ValueError(
                'new_user is None, note that backward compatability for the older versions of django registration has been dropped.')
    except IntegrityError as e:
        # this happens when users click multiple times, the first request registers
        # the second one raises an error
        raise facebook_exceptions.AlreadyRegistered(e)

    # update some extra data not yet done by the form
    new_user = _update_user(new_user, facebook)

    signals.facebook_user_registered.send(sender=get_user_model(),
                                          user=new_user, facebook_data=facebook_data, request=request, converter=facebook)
    # IS this the correct way for django 1.3? seems to require the backend
    # attribute for some reason
    new_user.backend = 'django_facebook.auth_backends.FacebookBackend'
    auth.login(request, new_user)

    return new_user
Пример #10
0
def _register_user(request, facebook, profile_callback=None,
                   remove_old_connections=False):
    '''
    Creates a new user and authenticates
    The registration form handles the registration and validation
    Other data on the user profile is updates afterwards

    if remove_old_connections = True we will disconnect old
    profiles from their facebook flow
    '''
    if not facebook.is_authenticated():
        raise ValueError(
            'Facebook needs to be authenticated for connect flows')

    # get the backend on new registration systems, or none
    # if we are on an older version
    backend = get_registration_backend()
    logger.info('running backend %s for registration', backend)

    # gets the form class specified in FACEBOOK_REGISTRATION_FORM
    form_class = get_form_class(backend, request)

    facebook_data = facebook.facebook_registration_data()

    data = request.POST.copy()
    for k, v in facebook_data.items():
        if not data.get(k):
            data[k] = v
    if remove_old_connections:
        _remove_old_connections(facebook_data['facebook_id'])

    if request.REQUEST.get('force_registration_hard'):
        data['email'] = data['email'].replace(
            '@', '+test%s@' % randint(0, 1000000000))
    #checking for storing local image
    if facebook_settings.FACEBOOK_STORE_LOCAL_IMAGE:
        form = form_class(data=data, files=request.FILES,
                          initial={'ip': request.META['REMOTE_ADDR']})
    else:
        form = form_class(data=data,
                            initial={'ip': request.META['REMOTE_ADDR']})
        
    if not form.is_valid():
        error_message_format = u'Facebook data %s gave error %s'
        error_message = error_message_format % (facebook_data, form.errors)
        error = facebook_exceptions.IncompleteProfileError(error_message)
        error.form = form
        raise error

    try:
        #for new registration systems use the backends methods of saving
        new_user = None
        if backend:
            new_user = backend.register(request, **form.cleaned_data)
        #fall back to the form approach
        if new_user is None:
            # For backward compatibility, if django-registration form is used
            try:
                new_user = form.save(profile_callback=profile_callback)
            except TypeError:
                new_user = form.save()
    except IntegrityError, e:
        #this happens when users click multiple times, the first request registers
        #the second one raises an error
        raise facebook_exceptions.AlreadyRegistered(e)