1
0
mirror of https://gitlab.com/brutaldon/brutaldon.git synced 2024-12-04 14:46:24 -05:00

Forgetting the last account works

This commit is contained in:
Jason McBrayer 2019-04-27 20:28:03 -04:00
parent 59f2a9cf1e
commit 5612965b45

View File

@ -200,26 +200,27 @@ def switch_accounts(request, new_account):
return True return True
def forget_account(request, account_name): def forget_account(request, account_name):
"""Forget that you were logged into an account. If it's the last one, """Forget that you were logged into an account. If it's the last one, log out
log out entirely. Sets up session variables. Returns boolean success entirely. Sets up session variables. Returns a redirect to the correct
code""" view.
"""
accounts_dict = request.session.get("accounts_dict") accounts_dict = request.session.get("accounts_dict")
if not accounts_dict or not account_name in accounts_dict.keys(): if not accounts_dict or not account_name in accounts_dict.keys():
return False return redirect("accounts")
del accounts_dict[account_name] del accounts_dict[account_name]
if len(accounts_dict) == 0: if len(accounts_dict) == 0:
request.session.flush() request.session.flush()
return True return redirect("about")
else: else:
set_trace()
key = [*accounts_dict][0] key = [*accounts_dict][0]
request.session['active_user'] = accounts_dict[key]['user'] request.session['active_user'] = accounts_dict[key]['user']
try: try:
account = Account.objects.get(id=accounts_dict[key]['account_id']) account = Account.objects.get(id=accounts_dict[key]['account_id'])
request.session['active_username'] = account.username request.session['active_username'] = account.username
return redirect("accounts")
except: except:
request.session.flush() request.session.flush()
return True return redirect("about")
### ###
@ -1181,8 +1182,8 @@ def accounts(request, id=None):
return redirect("accounts") return redirect("accounts")
elif request.POST.get('forget'): elif request.POST.get('forget'):
account = Account.objects.get(id=id).username account = Account.objects.get(id=id).username
forget_account(request, account) return forget_account(request, account)
return redirect("accounts") redirect("accounts")
else: else:
accounts = [x for x in request.session.get('accounts_dict').values()] accounts = [x for x in request.session.get('accounts_dict').values()]
return render(request, 'accounts/list.html', return render(request, 'accounts/list.html',