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.
This commit is contained in:
Jason McBrayer 2019-02-06 08:49:50 -05:00
parent 289bd28e28
commit 5c45a31cf1

View File

@ -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',