Fix bug: can't switch accounts after using old login mode

Problem reason: account.id might not be available before account.save(),
if the account is newly-created

Changes: switches .save() call and accounts_dict update, to ensure that
the .id is available in accounts_dict

Note: this bugfix only fixes logins after this change. If you’ve logged
in using the old code, your session data still won't have ID. You need
to log out of all the accounts and then log in again.
This commit is contained in:
Dzmitry Kushnarou 2024-05-15 22:48:21 +01:00
parent 28aae9942a
commit f9839ea5cb
1 changed files with 1 additions and 1 deletions

View File

@ -583,6 +583,7 @@ def old_login(request):
account.username = request.session["active_username"] account.username = request.session["active_username"]
request.session["timezone"] = account.preferences.timezone request.session["timezone"] = account.preferences.timezone
account.save()
accounts_dict = request.session.get("accounts_dict") accounts_dict = request.session.get("accounts_dict")
if not accounts_dict: if not accounts_dict:
accounts_dict = {} accounts_dict = {}
@ -591,7 +592,6 @@ def old_login(request):
"user": user, "user": user,
} }
request.session["accounts_dict"] = accounts_dict request.session["accounts_dict"] = accounts_dict
account.save()
return redirect(home) return redirect(home)
except IntegrityError: except IntegrityError: