forked from s3lph/matemat
fix: default avatar missing after signup in non-kiosk mode
This commit is contained in:
parent
2be7bf7683
commit
1823759433
1 changed files with 13 additions and 11 deletions
|
@ -35,17 +35,19 @@ def signup_user(args: FormsDict, files: FormsDict, db: MatematDatabase) -> User:
|
||||||
# Finally, set the avatar, if provided
|
# Finally, set the avatar, if provided
|
||||||
if 'avatar' in files:
|
if 'avatar' in files:
|
||||||
avatar = files.avatar.file.read()
|
avatar = files.avatar.file.read()
|
||||||
if len(avatar) > 0:
|
else:
|
||||||
filemagic: magic.FileMagic = magic.detect_from_content(avatar)
|
avatar = None
|
||||||
if filemagic.mime_type.startswith('image/'):
|
if avatar:
|
||||||
abspath: str = os.path.join(os.path.abspath(config['UploadDir']), 'thumbnails/users/')
|
filemagic: magic.FileMagic = magic.detect_from_content(avatar)
|
||||||
os.makedirs(abspath, exist_ok=True)
|
if filemagic.mime_type.startswith('image/'):
|
||||||
# Parse the image data
|
abspath: str = os.path.join(os.path.abspath(config['UploadDir']), 'thumbnails/users/')
|
||||||
image: Image = Image.open(BytesIO(avatar))
|
os.makedirs(abspath, exist_ok=True)
|
||||||
# Resize the image to 150x150
|
# Parse the image data
|
||||||
image.thumbnail((150, 150), Image.LANCZOS)
|
image: Image = Image.open(BytesIO(avatar))
|
||||||
# Write the image to the file
|
# Resize the image to 150x150
|
||||||
image.save(os.path.join(abspath, f'{new_user.id}.png'), 'PNG')
|
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:
|
else:
|
||||||
# If a default avatar is set, copy it to the user's avatar path
|
# If a default avatar is set, copy it to the user's avatar path
|
||||||
# Create the absolute path of the upload directory
|
# Create the absolute path of the upload directory
|
||||||
|
|
Loading…
Reference in a new issue