Apply username sanitizing upon creation

Prevent purging of character ownerships when logging in
Listen to state permission changes for service access verification
This commit is contained in:
Adarnof
2017-03-26 17:45:32 -04:00
parent 06f78a7518
commit aaf196b477
3 changed files with 41 additions and 2 deletions

View File

@@ -58,6 +58,8 @@ class StateBackend(ModelBackend):
@staticmethod
def iterate_username(name):
name = str.replace(name, "'", "")
name = str.replace(name, ' ', '_')
if User.objects.filter(username__startswith=name).exists():
u = User.objects.filter(username__startswith=name)
num = len(u)

View File

@@ -71,9 +71,12 @@ def create_required_models(sender, instance, created, *args, **kwargs):
@receiver(post_save, sender=Token)
def record_character_ownership(sender, instance, created, *args, **kwargs):
if created:
if instance.user:
query = Q(owner_hash=instance.character_owner_hash) & Q(user=instance.user)
else:
query = Q(owner_hash=instance.character_owner_hash)
# purge ownership records if the hash or auth user account has changed
CharacterOwnership.objects.filter(character__character_id=instance.character_id).exclude(Q(
owner_hash=instance.character_owner_hash) & Q(user=instance.user)).delete()
CharacterOwnership.objects.filter(character__character_id=instance.character_id).exclude(query).delete()
# create character if needed
if EveCharacter.objects.filter(character_id=instance.character_id).exists() is False:
EveManager.create_character(instance.character_id)