def remove_user(user): ''' Removes user account. ''' # Send signal (to commit any pending changes) user_pre_delete.send(instance=user, sender=user.__class__) # Change username user.username = '******'.format(user.pk) while User.objects.filter(username=user.username).exists(): user.username = '******'.format( user.pk, binascii.b2a_hex(os.urandom(5))) # Remove user information user.first_name = 'Deleted User' user.last_name = '' user.email = '*****@*****.**' # Disable the user user.is_active = False user.set_unusable_password() user.save() # Remove all social auth associations user.social_auth.all().delete()
def remove_user(user): ''' Removes user account. ''' # Send signal (to commit any pending changes) user_pre_delete.send(instance=user, sender=user.__class__) # Change username user.username = '******'.format(user.pk) while User.objects.filter(username=user.username).exists(): user.username = '******'.format( user.pk, binascii.b2a_hex(os.urandom(5)) ) # Remove user information user.first_name = 'Deleted User' user.last_name = '' user.email = '*****@*****.**' # Disable the user user.is_active = False user.set_unusable_password() user.save() # Remove all social auth associations user.social_auth.all().delete()
def remove_user(user, request): """Remove user account.""" # Send signal (to commit any pending changes) user_pre_delete.send(instance=user, sender=user.__class__) # Store activity log and notify notify_account_activity(user, request, 'removed') # Remove any email validation codes invalidate_reset_codes(user) # Change username user.username = '******'.format(user.pk) user.email = 'noreply+{}@weblate.org'.format(user.pk) while User.objects.filter(username=user.username).exists(): user.username = '******'.format( user.pk, binascii.b2a_hex(os.urandom(5))) while User.objects.filter(email=user.email).exists(): user.email = 'noreply+{0}-{1}@weblate.org'.format( user.pk, binascii.b2a_hex(os.urandom(5))) # Remove user information user.full_name = 'Deleted User' # Disable the user user.is_active = False user.set_unusable_password() user.save() # Remove all social auth associations user.social_auth.all().delete() # Remove user from all groups user.groups.clear()
def remove_user(user, request): """Remove user account.""" # Send signal (to commit any pending changes) user_pre_delete.send(instance=user, sender=user.__class__) # Store activity log and notify AuditLog.objects.create(user, request, "removed") # Remove any email validation codes invalidate_reset_codes(user) # Change username user.username = f"deleted-{user.pk}" user.email = f"noreply+{user.pk}@weblate.org" while User.objects.filter(username=user.username).exists(): user.username = "******".format(user.pk, os.urandom(5).hex()) while User.objects.filter(email=user.email).exists(): user.email = "noreply+{}-{}@weblate.org".format(user.pk, os.urandom(5).hex()) # Remove user information user.full_name = "Deleted User" # Disable the user user.is_active = False user.set_unusable_password() user.save() # Remove all social auth associations user.social_auth.all().delete() # Remove user from all groups user.groups.clear() # Remove user translation memory user.memory_set.all().delete()
def remove_user(user, request): """Remove user account.""" # Send signal (to commit any pending changes) user_pre_delete.send(instance=user, sender=user.__class__) # Store activity log and notify AuditLog.objects.create(user, request, "removed") # Remove any email validation codes invalidate_reset_codes(user) # Change username user.username = f"deleted-{user.pk}" user.email = f"noreply+{user.pk}@weblate.org" while User.objects.filter(username=user.username).exists(): user.username = f"deleted-{user.pk}-{os.urandom(5).hex()}" while User.objects.filter(email=user.email).exists(): user.email = f"noreply+{user.pk}-{os.urandom(5).hex()}@weblate.org" # Remove user information user.full_name = "Deleted User" # Disable the user user.is_active = False user.set_unusable_password() user.save() # Remove all social auth associations user.social_auth.all().delete() # Remove user from all groups user.groups.clear() # Remove user translation memory user.memory_set.all().delete() # Cleanup profile try: profile = user.profile profile.website = "" profile.liberapay = "" profile.fediverse = "" profile.codesite = "" profile.github = "" profile.twitter = "" profile.linkedin = "" profile.location = "" profile.company = "" profile.public_email = "" profile.save() except ObjectDoesNotExist: pass # Delete API tokens Token.objects.filter(user=user).delete()
def remove_user(user, request): """Remove user account.""" # Send signal (to commit any pending changes) user_pre_delete.send(instance=user, sender=user.__class__) # Store activity log and notify AuditLog.objects.create(user, request, 'removed') # Remove any email validation codes invalidate_reset_codes(user) # Change username user.username = '******'.format(user.pk) user.email = 'noreply+{}@weblate.org'.format(user.pk) while User.objects.filter(username=user.username).exists(): user.username = '******'.format( user.pk, binascii.b2a_hex(os.urandom(5)) ) while User.objects.filter(email=user.email).exists(): user.email = 'noreply+{0}-{1}@weblate.org'.format( user.pk, binascii.b2a_hex(os.urandom(5)) ) # Remove user information user.full_name = 'Deleted User' # Disable the user user.is_active = False user.set_unusable_password() user.save() # Remove all social auth associations user.social_auth.all().delete() # Remove user from all groups user.groups.clear()