#NEWLINE# def _register_user( request , facebook , profile_callback = None , remove_old_connections = False ) : #NEWLINE# #INDENT# '\n    Creates a new user and authenticates\n    The registration form handles the registration and validation\n    Other data on the user profile is updates afterwards\n\n    if remove_old_connections = True we will disconnect old\n    profiles from their facebook flow\n    ' #NEWLINE# if ( not facebook . is_authenticated ( ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Facebook needs to be authenticated for connect flows' ) #NEWLINE# #UNINDENT# backend = get_registration_backend ( ) #NEWLINE# logger . info ( 'running backend %s for registration' , backend ) #NEWLINE# form_class = get_form_class ( backend , request ) #NEWLINE# facebook_data = facebook . facebook_registration_data ( ) #NEWLINE# data = request . POST . copy ( ) #NEWLINE# for ( k , v ) in facebook_data . items ( ) : #NEWLINE# #INDENT# if ( not data . get ( k ) ) : #NEWLINE# #INDENT# data [ k ] = v #NEWLINE# #UNINDENT# #UNINDENT# if remove_old_connections : #NEWLINE# #INDENT# _remove_old_connections ( facebook_data [ 'facebook_id' ] ) #NEWLINE# #UNINDENT# if ( request . POST . get ( 'force_registration_hard' ) or request . GET . get ( 'force_registration_hard' ) ) : #NEWLINE# #INDENT# data [ 'email' ] = data [ 'email' ] . replace ( '@' , ( '+test%s@' % randint ( 0 , 1000000000 ) ) ) #NEWLINE# #UNINDENT# form = form_class ( data = data , files = request . FILES , initial = { #NEWLINE# #INDENT# 'ip' : request . META [ 'REMOTE_ADDR' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( not form . is_valid ( ) ) : #NEWLINE# #INDENT# form_errors = form . errors #NEWLINE# error = facebook_exceptions . IncompleteProfileError ( 'Facebook signup incomplete' ) #NEWLINE# error . form = form #NEWLINE# raise error #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# new_user = None #NEWLINE# if backend : #NEWLINE# #INDENT# new_user = backend . register ( request , form = form , ** form . cleaned_data ) #NEWLINE# #UNINDENT# if ( new_user is None ) : #NEWLINE# #INDENT# raise ValueError ( 'new_user is None, note that backward compatability for the older versions of django registration has been dropped.' ) #NEWLINE# #UNINDENT# #UNINDENT# except IntegrityError as e : #NEWLINE# #INDENT# raise facebook_exceptions . AlreadyRegistered ( e ) #NEWLINE# #UNINDENT# new_user = _update_user ( new_user , facebook ) #NEWLINE# signals . facebook_user_registered . send ( sender = get_user_model ( ) , user = new_user , facebook_data = facebook_data , request = request , converter = facebook ) #NEWLINE# new_user . backend = 'django_facebook.auth_backends.FacebookBackend' #NEWLINE# auth . login ( request , new_user ) #NEWLINE# return new_user