Skip to content

Commit fe7174f

Browse files
committed
its wooooooorkinggit add project/auth.py project/templates/profile.html git add project/auth.py project/templates/profile.html git add project/auth.py project/templates/profile.html
1 parent a9606eb commit fe7174f

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

project/auth.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def callback():
4040
try:
4141
user_info_response = gamma.get('/oauth2/userinfo', token=token)
4242
user_info = user_info_response.json()
43+
print("=== USER INFO FROM GAMMA ===")
44+
print(f"User info: {user_info}")
4345
except Exception as e:
4446
print(f"UserInfo API Exception: {e}")
4547
# Fallback to basic info from token
@@ -48,14 +50,33 @@ def callback():
4850
'scopes': token.get('scope', 'N/A')
4951
}
5052

53+
# Add token scope info to user data for display
54+
if 'scope' not in user_info and token.get('scope'):
55+
user_info['scopes'] = token.get('scope')
56+
57+
# Store only the most essential user info in session (reduce session size)
58+
essential_user_info = {
59+
'sub': user_info.get('sub'),
60+
'name': user_info.get('name'),
61+
'email': user_info.get('email'),
62+
'cid': user_info.get('cid')
63+
}
64+
5165
# Store user info in session
52-
session['user'] = user_info
53-
session['token'] = token
66+
session['user'] = essential_user_info
67+
# Don't store the full token to save space
68+
session['authenticated'] = True
5469

55-
return redirect(url_for('main.index'))
70+
print("=== SESSION DATA ===")
71+
print(f"User data stored in session: {essential_user_info}")
72+
print(f"Token scopes: {token.get('scope', 'N/A')}")
73+
print(f"Full user info: {user_info}")
74+
75+
return redirect(url_for('main.profile'))
5676

5777

5878
@auth.route('/logout')
5979
def logout():
60-
session.clear()
61-
return render_template('logout.html')
80+
session.pop('user', None)
81+
session.pop('authenticated', None)
82+
return redirect(url_for('main.index'))

project/templates/profile.html

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,49 @@
22

33
{% block content %}
44
<h1 class="title">
5-
Welcome, {{ user.name if user else 'digIT' }}!
5+
Welcome, {{ user.name if user and user.name else (user.email if user and user.email else 'digIT User') }}!
66
</h1>
77

88
{% if user %}
99
<div class="content">
1010
<h2>Profile Information</h2>
11+
12+
<!-- Basic user info -->
13+
{% if user.sub %}
1114
<p><strong>User ID:</strong> {{ user.sub }}</p>
15+
{% endif %}
16+
17+
{% if user.name %}
1218
<p><strong>Name:</strong> {{ user.name }}</p>
19+
{% endif %}
20+
21+
{% if user.email %}
1322
<p><strong>Email:</strong> {{ user.email }}</p>
23+
{% endif %}
24+
1425
{% if user.nick %}
1526
<p><strong>Nickname:</strong> {{ user.nick }}</p>
1627
{% endif %}
28+
1729
{% if user.cid %}
1830
<p><strong>CID:</strong> {{ user.cid }}</p>
1931
{% endif %}
20-
21-
<a class="button is-light" href="{{ url_for('auth.logout') }}">Logout</a>
32+
33+
<!-- OAuth scopes info -->
34+
{% if user.scopes %}
35+
<p><strong>OAuth Scopes:</strong> {{ user.scopes }}</p>
36+
{% endif %}
37+
38+
<!-- Debug: Show all available user data -->
39+
<details style="margin-top: 2rem;">
40+
<summary><strong>Raw User Data (Debug)</strong></summary>
41+
<pre style="background: #f5f5f5; padding: 1rem; margin-top: 1rem; white-space: pre-wrap;">{{ user | tojson(indent=2) }}</pre>
42+
</details>
43+
44+
<!-- Logout button -->
45+
<div style="margin-top: 2rem;">
46+
<a class="button is-light" href="{{ url_for('auth.logout') }}">Logout</a>
47+
</div>
2248
</div>
2349
{% else %}
2450
<div class="content">

0 commit comments

Comments
 (0)