Browse Source

Store user id/secret in session upon login (#61)

History table uses session's user_id instead of secret in URL.
master
Kevin Mok 6 years ago
parent
commit
3d6dff359d
  1. 2
      graphs/templates/graphs/logged_in.html
  2. 5
      graphs/urls.py
  3. 4
      graphs/views.py
  4. 7
      login/views.py

2
graphs/templates/graphs/logged_in.html

@ -16,7 +16,7 @@
<a class="btn btn-primary" href="{% url "graphs:display_artist_graph" user_secret %}" role="button">
Artists
</a>
<a class="btn btn-primary" href="{% url "graphs:display_history_table" user_secret %}" role="button">
<a class="btn btn-primary" href="{% url "graphs:display_history_table" %}" role="button">
History
</a>
</body>

5
graphs/urls.py

@ -10,6 +10,7 @@ urlpatterns = [
name='display_genre_graph'),
path('audio_features/<str:user_secret>', display_features_graphs,
name='display_audio_features'),
path('history/<str:user_secret>', display_history_table,
name='display_history_table'),
# path('history/<str:user_secret>', display_history_table,
# name='display_history_table'),
path('history/', display_history_table, name='display_history_table'),
]

4
graphs/views.py

@ -43,14 +43,14 @@ def display_features_graphs(request, user_secret):
return render(request, "graphs/features_graphs.html",
get_secret_context(user_secret))
def display_history_table(request, user_secret):
def display_history_table(request):
"""Renders the user history page
:param request: the HTTP request
:param user_secret: user secret used for identification
:return: renders the user history page
"""
user_id = User.objects.get(secret=user_secret).id
user_id = request.session['user_id']
user_history = History.objects.filter(user__exact=user_id).order_by('-timestamp')
history_table = HistoryTable(user_history)
history_table.exclude = ('id', 'user', 'track', )

7
login/views.py

@ -75,6 +75,9 @@ def callback(request):
token_response['access_token'],
token_response['expires_in'])
request.session['user_id'] = user_obj.id
request.session['user_secret'] = user_obj.secret
return render(request, 'login/scan.html', get_user_context(user_obj))
# }}} callback #
@ -86,6 +89,10 @@ def admin_graphs(request):
"""
user_id = "polarbier"
# user_id = "chrisshyi13"
request.session['user_id'] = user_id
# request.session['user_secret'] = user_obj.secret
request.session['user_secret'] = User.objects.get(id=user_id).secret
user_obj = User.objects.get(id=user_id)
return render(request, 'graphs/logged_in.html', get_user_context(user_obj))

Loading…
Cancel
Save