From f37e1e04a4f65b5e8db85482f72dd4584dc542dc Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 18 Jan 2022 16:44:36 -0500 Subject: [PATCH] Fix gravatar not loading after being removed from cookie. Improve gravatar loading so it changes without relogging --- app/classes/web/panel_handler.py | 20 ++++++++++++++++++++ app/classes/web/public_handler.py | 17 ----------------- app/frontend/templates/notify.html | 4 ++-- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 270d8f1e..83e177e6 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -17,6 +17,8 @@ import threading from cron_validator import CronValidator #TZLocal is set as a hidden import on win pipeline from tzlocal import get_localzone +import libgravatar +import requests from tornado import locale, iostream from tornado.ioloop import IOLoop @@ -244,6 +246,24 @@ class PanelHandler(BaseHandler): } if api_key is not None else None, 'superuser': superuser } + if helper.get_setting("allow_nsfw_profile_pictures"): + rating = "x" + else: + rating = "g" + + + #Get grvatar hash for profile pictures + if exec_user['email'] != 'default@example.com' or "": + g = libgravatar.Gravatar(libgravatar.sanitize_email(exec_user['email'])) + url = g.get_image(size=80, default="404", force_default=False, rating=rating, filetype_extension=False, use_ssl=True) # + "?d=404" + if requests.head(url).status_code != 404: + profile_url = url + else: + profile_url = "/static/assets/images/faces-clipart/pic-3.png" + else: + profile_url = "/static/assets/images/faces-clipart/pic-3.png" + + page_data['user_image'] = profile_url if page == 'unauthorized': template = "panel/denied.html" diff --git a/app/classes/web/public_handler.py b/app/classes/web/public_handler.py index df3f26af..1c595691 100644 --- a/app/classes/web/public_handler.py +++ b/app/classes/web/public_handler.py @@ -120,23 +120,6 @@ class PublicHandler(BaseHandler): # log this login self.controller.management.add_to_audit_log(user_data.user_id, "Logged in", 0, self.get_remote_ip()) - if helper.get_setting("allow_nsfw_profile_pictures"): - rating = "x" - else: - rating = "g" - - - #Get grvatar hash for profile pictures - if user_data.email != 'default@example.com' or "": - g = libgravatar.Gravatar(libgravatar.sanitize_email(user_data.email)) - url = g.get_image(size=80, default="404", force_default=False, rating=rating, filetype_extension=False, use_ssl=True) # + "?d=404" - if requests.head(url).status_code != 404: - profile_url = url - else: - profile_url = "/static/assets/images/faces-clipart/pic-3.png" - else: - profile_url = "/static/assets/images/faces-clipart/pic-3.png" - next_page = "/panel/dashboard" self.redirect(next_page) else: diff --git a/app/frontend/templates/notify.html b/app/frontend/templates/notify.html index 53881b10..a0182928 100644 --- a/app/frontend/templates/notify.html +++ b/app/frontend/templates/notify.html @@ -18,10 +18,10 @@