def update_user_details(backend, details, response, user, is_new=False, *args, **kwargs): """Update user details using data from provider.""" changed = False # flag to track changes for name, value in details.iteritems(): # do not update username, it was already generated # do not update configured fields if user already existed if name in (USERNAME, "id", "pk") or (not is_new and name in setting("SOCIAL_AUTH_PROTECTED_USER_FIELDS", [])): continue if value and value != getattr(user, name, None): setattr(user, name, value) changed = True # Fire a pre-update signal sending current backend instance, # user instance (created or retrieved from database), service # response and processed details. # # Also fire socialauth_registered signal for newly registered # users. # # Signal handlers must return True or False to signal instance # changes. Send method returns a list of tuples with receiver # and it's response. signal_response = lambda (receiver, response): response signal_kwargs = {"sender": backend.__class__, "user": user, "response": response, "details": details} changed |= any(filter(signal_response, pre_update.send(**signal_kwargs))) # Fire socialauth_registered signal on new user registration if is_new: changed |= any(filter(signal_response, socialauth_registered.send(**signal_kwargs))) if changed: user.save()
def update_user_details(backend, details, response, user, is_new=False, *args, **kwargs): """Update user details using data from provider.""" changed = False # flag to track changes warn_setting('SOCIAL_AUTH_CHANGE_SIGNAL_ONLY', 'update_user_details') # check if values update should be left to signals handlers only if not setting('SOCIAL_AUTH_CHANGE_SIGNAL_ONLY'): for name, value in details.iteritems(): # do not update username, it was already generated # do not update configured fields if user already existed if name in (USERNAME, 'id', 'pk') or (not is_new and name in setting( 'SOCIAL_AUTH_PROTECTED_USER_FIELDS', [])): continue if value and value != getattr(user, name, None): setattr(user, name, value) changed = True # Fire a pre-update signal sending current backend instance, # user instance (created or retrieved from database), service # response and processed details. # # Also fire socialauth_registered signal for newly registered # users. # # Signal handlers must return True or False to signal instance # changes. Send method returns a list of tuples with receiver # and it's response. signal_response = lambda (receiver, response): response signal_kwargs = { 'sender': backend.__class__, 'user': user, 'response': response, 'details': details } changed |= any(filter(signal_response, pre_update.send(**signal_kwargs))) # Fire socialauth_registered signal on new user registration if is_new: changed |= any( filter(signal_response, socialauth_registered.send(**signal_kwargs))) if changed: user.save()
def update_user_details(backend, details, response, user, is_new=False, *args, **kwargs): """Update user details using data from provider.""" # we don't want to change anything unless the user is new if not is_new: return changed = False # flag to track changes for name, value in details.iteritems(): # do not update username, it was already generated if name == USERNAME: continue if value and value != getattr(user, name, None): setattr(user, name, value) changed = True # Fire a pre-update signal sending current backend instance, # user instance (created or retrieved from database), service # response and processed details. # # Also fire socialauth_registered signal for newly registered # users. # # Signal handlers must return True or False to signal instance # changes. Send method returns a list of tuples with receiver # and it's response. signal_response = lambda (receiver, response): response signal_kwargs = { 'sender': backend.__class__, 'user': user, 'response': response, 'details': details } changed |= any(filter(signal_response, pre_update.send(**signal_kwargs))) # Fire socialauth_registered signal on new user registration if is_new: changed |= any( filter(signal_response, socialauth_registered.send(**signal_kwargs))) if changed: user.save()
def update_user_details(backend, details, response, user, is_new=False, *args, **kwargs): """Update user details using data from provider.""" changed = False # flag to track changes warn_setting('SOCIAL_AUTH_CHANGE_SIGNAL_ONLY', 'update_user_details') # check if values update should be left to signals handlers only if not setting('SOCIAL_AUTH_CHANGE_SIGNAL_ONLY'): do_not_update_email = setting('SOCIAL_AUTH_DO_NOT_UPDATE_EMAIL') == True for name, value in details.iteritems(): # do not update username, it was already generated if name in (USERNAME, 'id', 'pk'): continue if do_not_update_email and name == 'email' and not user.email: continue if value and value != getattr(user, name, None): setattr(user, name, value) changed = True # Fire a pre-update signal sending current backend instance, # user instance (created or retrieved from database), service # response and processed details. # # Also fire socialauth_registered signal for newly registered # users. # # Signal handlers must return True or False to signal instance # changes. Send method returns a list of tuples with receiver # and it's response. signal_response = lambda (receiver, response): response signal_kwargs = {'sender': backend.__class__, 'user': user, 'response': response, 'details': details} changed |= any(filter(signal_response, pre_update.send(**signal_kwargs))) # Fire socialauth_registered signal on new user registration if is_new: changed |= any(filter(signal_response, socialauth_registered.send(**signal_kwargs))) if changed: user.save()
def update_user_details(backend, details, response, user, is_new=False, *args, **kwargs): """Override of social_auth method, to prevent details from getting updated.""" LOGGER.debug("socialprofile.models.update_user_details") changed = False # flag to track changes signal_response = lambda (receiver, response): response signal_kwargs = {'sender': backend.__class__, 'user': user, 'response': response, 'details': details} changed |= any(filter(signal_response, pre_update.send(**signal_kwargs))) # Fire socialauth_registered signal on new user registration if is_new: changed |= any(filter(signal_response, socialauth_registered.send(**signal_kwargs))) if changed: user.save()
def update_user_details(self, user, response, details, is_new=False): """Update user details with (maybe) new data. Username is not changed if associating a new credential.""" changed = False # flag to track changes # check if values update should be left to signals handlers only if not getattr(settings, 'SOCIAL_AUTH_CHANGE_SIGNAL_ONLY', False): for name, value in details.iteritems(): # do not update username, it was already generated by # self.username(...) and loaded in given instance if name != USERNAME and value and value != getattr( user, name, value): setattr(user, name, value) changed = True # Fire a pre-update signal sending current backend instance, # user instance (created or retrieved from database), service # response and processed details. # # Also fire socialauth_registered signal for newly registered # users. # # Signal handlers must return True or False to signal instance # changes. Send method returns a list of tuples with receiver # and it's response. signal_response = lambda (receiver, response): response kwargs = { 'sender': self.__class__, 'user': user, 'response': response, 'details': details } changed |= any(filter(signal_response, pre_update.send(**kwargs))) # Fire socialauth_registered signal on new user registration if is_new: changed |= any( filter(signal_response, socialauth_registered.send(**kwargs))) if changed: user.save()
def update_user_details(self, user, response, details, is_new=False): """Update user details with (maybe) new data. Username is not changed if associating a new credential.""" changed = False # flag to track changes # check if values update should be left to signals handlers only if not CHANGE_SIGNAL_ONLY: logger.debug('Updating user details for user %s', user, extra=dict(data=details)) for name, value in details.iteritems(): # do not update username, it was already generated by # self.username(...) and loaded in given instance if name != USERNAME and value and value != getattr(user, name, None): setattr(user, name, value) changed = True # Fire a pre-update signal sending current backend instance, # user instance (created or retrieved from database), service # response and processed details. # # Also fire socialauth_registered signal for newly registered # users. # # Signal handlers must return True or False to signal instance # changes. Send method returns a list of tuples with receiver # and it's response. signal_response = lambda (receiver, response): response kwargs = {'sender': self.__class__, 'user': user, 'response': response, 'details': details} changed |= any(filter(signal_response, pre_update.send(**kwargs))) # Fire socialauth_registered signal on new user registration if is_new: changed |= any(filter(signal_response, socialauth_registered.send(**kwargs))) if changed: user.save()
def update_user_details(backend, details, response, user, is_new=False, *args, **kwargs): """Update user details using data from provider.""" # we don't want to change anything unless the user is new if not is_new: return changed = False # flag to track changes for name, value in details.iteritems(): # do not update username, it was already generated if name == USERNAME: continue if value and value != getattr(user, name, None): setattr(user, name, value) changed = True # Fire a pre-update signal sending current backend instance, # user instance (created or retrieved from database), service # response and processed details. # # Also fire socialauth_registered signal for newly registered # users. # # Signal handlers must return True or False to signal instance # changes. Send method returns a list of tuples with receiver # and it's response. signal_response = lambda (receiver, response): response signal_kwargs = {'sender': backend.__class__, 'user': user, 'response': response, 'details': details} changed |= any(filter(signal_response, pre_update.send(**signal_kwargs))) # Fire socialauth_registered signal on new user registration if is_new: changed |= any(filter(signal_response, socialauth_registered.send(**signal_kwargs))) if changed: user.save()
def update_user_details(backend, details, response, user, is_new=False, *args, **kwargs): """Update user details using data from provider.""" changed = False # flag to track changes warn_setting("SOCIAL_AUTH_CHANGE_SIGNAL_ONLY", "update_user_details") # check if values update should be left to signals handlers only if not getattr(settings, "SOCIAL_AUTH_CHANGE_SIGNAL_ONLY", False): for name, value in details.iteritems(): # do not update username, it was already generated if name == USERNAME: continue if value and value != getattr(user, name, None): setattr(user, name, value) changed = True # Fire a pre-update signal sending current backend instance, # user instance (created or retrieved from database), service # response and processed details. # # Also fire socialauth_registered signal for newly registered # users. # # Signal handlers must return True or False to signal instance # changes. Send method returns a list of tuples with receiver # and it's response. signal_response = lambda (receiver, response): response signal_kwargs = {"sender": backend.__class__, "user": user, "response": response, "details": details} changed |= any(filter(signal_response, pre_update.send(**signal_kwargs))) # Fire socialauth_registered signal on new user registration if is_new: changed |= any(filter(signal_response, socialauth_registered.send(**signal_kwargs))) if changed: user.save()
def update_user_details(backend, details, response, user, is_new=False, *args, **kwargs): """Update user details using data from provider.""" if backend.name not in ('twitter', 'facebook'): return fields_name = backend.RESPONSE_FIELDS profile = user.get_profile() if not profile.bio and response.get(fields_name['bio'], None): profile.bio = response[fields_name['bio']] if not profile.user.first_name and response.get('first_name', None): user.first_name = response['first_name'] if not profile.user.last_name and response.get('last_name', None): user.last_name = response['last_name'] if not profile.web and response.get(fields_name['web'], None): profile.web = response[fields_name['web']] if not profile.image and response.get(fields_name['image'], None): content = urllib.urlretrieve(response[fields_name['image']].encode('utf-8' ).replace("_normal", "")) profile.image.save("%s.jpg" % user.id, File(open(content[0])), save=True) if not profile.gender and response.get('gender', None): profile.gender = response['gender'] if not profile.birthdate and response.get('birthday', None): profile.birthdate = datetime.strptime(response['birthday'], "%m/%d/%Y").date() if not profile.city and response.get('location', None): try: profile.city = response['location'].get('name', None) except AttributeError: profile.city = response['location'] profile.geocode_location() profile.save() if not is_new: return return changed = False # flag to track changes for name, value in details.iteritems(): # do not update username, it was already generated # do not update configured fields if user already existed if name in (USERNAME, 'id', 'pk') or (not is_new and name in setting('SOCIAL_AUTH_PROTECTED_USER_FIELDS', [])): continue if value and value != getattr(user, name, None): setattr(user, name, value) changed = True # user instance (created or retrieved from database), service # response and processed details. # Fire a pre-update signal sending current backend instance, # # Also fire socialauth_registered signal for newly registered # users. # # Signal handlers must return True or False to signal instance # changes. Send method returns a list of tuples with receiver # and it's response. signal_response = lambda (receiver, response): response signal_kwargs = {'sender': backend.__class__, 'user': user, 'response': response, 'details': details} changed |= any(filter(signal_response, pre_update.send(**signal_kwargs))) # Fire socialauth_registered signal on new user registration if is_new: changed |= any(filter(signal_response, socialauth_registered.send(**signal_kwargs))) if changed: user.save() profile.save()