From 5c45a31cf16d48e28c1fb6a2a52320491ff45037 Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Wed, 6 Feb 2019 08:49:50 -0500 Subject: [PATCH] Update userinfo on settings page There are cases where your session['user'] dictionary can be out of date, like if you change your avatar. In that case, brutaldon will display a broken image instead of your avatar in various places. This change updates your settings info when you go to the settings page, in addition to as it normally does when you log in. Updating on every request would be possible, but it's another round trip to the instance, and I don't want the performance hit. --- brutaldon/views.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/brutaldon/views.py b/brutaldon/views.py index a424035..008548d 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -424,7 +424,10 @@ def user(request, username, prev=None, next=None): @never_cache @br_login_required def settings(request): - account = Account.objects.get(username=request.session['username']) + try: + account, mastodon = get_usercontext(request) + except NotLoggedInException: + return redirect(about) if request.method == 'POST': form = PreferencesForm(request.POST) if form.is_valid(): @@ -440,6 +443,12 @@ def settings(request): request.session['timezone'] = account.preferences.timezone account.preferences.save() account.save() + + # Update this here because it's a handy place to do it. + user_info = mastodon.account_verify_credentials() + request.session['user'] = user_info + + return redirect(home) else: return render(request, 'setup/settings.html',