Store user id/secret in session upon login (#61)
History table uses session's user_id instead of secret in URL.
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
<a class="btn btn-primary" href="{% url "graphs:display_artist_graph" user_secret %}" role="button">
|
<a class="btn btn-primary" href="{% url "graphs:display_artist_graph" user_secret %}" role="button">
|
||||||
Artists
|
Artists
|
||||||
</a>
|
</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
|
History
|
||||||
</a>
|
</a>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ urlpatterns = [
|
|||||||
name='display_genre_graph'),
|
name='display_genre_graph'),
|
||||||
path('audio_features/<str:user_secret>', display_features_graphs,
|
path('audio_features/<str:user_secret>', display_features_graphs,
|
||||||
name='display_audio_features'),
|
name='display_audio_features'),
|
||||||
path('history/<str:user_secret>', display_history_table,
|
# path('history/<str:user_secret>', display_history_table,
|
||||||
name='display_history_table'),
|
# name='display_history_table'),
|
||||||
|
path('history/', display_history_table, name='display_history_table'),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ def display_features_graphs(request, user_secret):
|
|||||||
return render(request, "graphs/features_graphs.html",
|
return render(request, "graphs/features_graphs.html",
|
||||||
get_secret_context(user_secret))
|
get_secret_context(user_secret))
|
||||||
|
|
||||||
def display_history_table(request, user_secret):
|
def display_history_table(request):
|
||||||
"""Renders the user history page
|
"""Renders the user history page
|
||||||
|
|
||||||
:param request: the HTTP request
|
:param request: the HTTP request
|
||||||
:param user_secret: user secret used for identification
|
:param user_secret: user secret used for identification
|
||||||
:return: renders the user history page
|
: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')
|
user_history = History.objects.filter(user__exact=user_id).order_by('-timestamp')
|
||||||
history_table = HistoryTable(user_history)
|
history_table = HistoryTable(user_history)
|
||||||
history_table.exclude = ('id', 'user', 'track', )
|
history_table.exclude = ('id', 'user', 'track', )
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ def callback(request):
|
|||||||
user_obj = create_user(token_response['refresh_token'],
|
user_obj = create_user(token_response['refresh_token'],
|
||||||
token_response['access_token'],
|
token_response['access_token'],
|
||||||
token_response['expires_in'])
|
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))
|
return render(request, 'login/scan.html', get_user_context(user_obj))
|
||||||
|
|
||||||
@@ -86,6 +89,10 @@ def admin_graphs(request):
|
|||||||
"""
|
"""
|
||||||
user_id = "polarbier"
|
user_id = "polarbier"
|
||||||
# user_id = "chrisshyi13"
|
# 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)
|
user_obj = User.objects.get(id=user_id)
|
||||||
return render(request, 'graphs/logged_in.html', get_user_context(user_obj))
|
return render(request, 'graphs/logged_in.html', get_user_context(user_obj))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user