2
0
mirror of https://github.com/jfmcbrayer/brutaldon synced 2024-12-23 05:43:41 +01:00

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 @never_cache
@br_login_required @br_login_required
def settings(request): 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': if request.method == 'POST':
form = PreferencesForm(request.POST) form = PreferencesForm(request.POST)
if form.is_valid(): if form.is_valid():
@ -440,6 +443,12 @@ def settings(request):
request.session['timezone'] = account.preferences.timezone request.session['timezone'] = account.preferences.timezone
account.preferences.save() account.preferences.save()
account.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) return redirect(home)
else: else:
return render(request, 'setup/settings.html', return render(request, 'setup/settings.html',