diff --git a/matemat/webserver/pagelets/signup.py b/matemat/webserver/pagelets/signup.py index 098abc1..042fde0 100644 --- a/matemat/webserver/pagelets/signup.py +++ b/matemat/webserver/pagelets/signup.py @@ -35,17 +35,19 @@ def signup_user(args: FormsDict, files: FormsDict, db: MatematDatabase) -> User: # Finally, set the avatar, if provided if 'avatar' in files: avatar = files.avatar.file.read() - if len(avatar) > 0: - filemagic: magic.FileMagic = magic.detect_from_content(avatar) - if filemagic.mime_type.startswith('image/'): - abspath: str = os.path.join(os.path.abspath(config['UploadDir']), 'thumbnails/users/') - os.makedirs(abspath, exist_ok=True) - # Parse the image data - image: Image = Image.open(BytesIO(avatar)) - # Resize the image to 150x150 - image.thumbnail((150, 150), Image.LANCZOS) - # Write the image to the file - image.save(os.path.join(abspath, f'{new_user.id}.png'), 'PNG') + else: + avatar = None + if avatar: + filemagic: magic.FileMagic = magic.detect_from_content(avatar) + if filemagic.mime_type.startswith('image/'): + abspath: str = os.path.join(os.path.abspath(config['UploadDir']), 'thumbnails/users/') + os.makedirs(abspath, exist_ok=True) + # Parse the image data + image: Image = Image.open(BytesIO(avatar)) + # Resize the image to 150x150 + image.thumbnail((150, 150), Image.LANCZOS) + # Write the image to the file + image.save(os.path.join(abspath, f'{new_user.id}.png'), 'PNG') else: # If a default avatar is set, copy it to the user's avatar path # Create the absolute path of the upload directory