def _connect_user(request, facebook, overwrite=True):
 if (not request.user.is_authenticated()):
  raise ValueError('Connect user can only be used on authenticated users')
 if (not facebook.is_authenticated()):
  raise ValueError('Facebook needs to be authenticated for connect flows')
 data = facebook.facebook_profile_data()
 facebook_id = data['id']
 old_connections = _get_old_connections(facebook_id, request.user.id)[:20]
 if (old_connections and (not (request.POST.get('confirm_connect') or request.GET.get('confirm_connect')))):
  raise facebook_exceptions.AlreadyConnectedError(list(old_connections))
 user = _update_user(request.user, facebook, overwrite=overwrite)
 return user

def _connect_user ( request , facebook , overwrite = True ) : if ( not request . user . is_authenticated ( ) ) : raise ValueError ( 'Connect user can only be used on authenticated users' ) if ( not facebook . is_authenticated ( ) ) : raise ValueError ( 'Facebook needs to be authenticated for connect flows' ) data = facebook . facebook_profile_data ( ) facebook_id = data [ 'id' ] old_connections = _get_old_connections ( facebook_id , request . user . id ) [ : 20 ] if ( old_connections and ( not ( request . POST . get ( 'confirm_connect' ) or request . GET . get ( 'confirm_connect' ) ) ) ) : raise facebook_exceptions . AlreadyConnectedError ( list ( old_connections ) ) user = _update_user ( request . user , facebook , overwrite = overwrite ) return user
update the fields on the user model and connects it to the facebook account .