Implement user authentication and management system with FastAPI
- Added authentication routes for login, registration, password reset, and account deletion in `auth.py`. - Implemented user profile management, including updating user information and changing passwords. - Created dashboard views to display user-specific information and recent activity in `dashboard.py`. - Developed leaderboard views to show team rankings and points in `leaderboard.py`. - Added QR code generation and redemption functionality in `qr.py` and `redeem.py`. - Implemented team management features, allowing users to create and join teams in `teams.py`. - Introduced session debugging utility to assist with session-related issues in `debug_session.py`. - Configured Docker Compose for MySQL database and FastAPI application with environment variables. - Updated requirements.txt to include necessary dependencies for the application.
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="max-w-md mx-auto my-8">
|
||||
<div class="bg-white p-8 rounded-lg shadow-md">
|
||||
<h1 class="text-2xl font-bold text-irish-green mb-6 text-center">Log In</h1>
|
||||
|
||||
<!-- Messages/Alerts -->
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div class="mb-4 p-3 rounded {% if message.type == 'error' %}bg-red-100 text-red-700{% else %}bg-green-100 text-green-700{% endif %}">
|
||||
{{ message.text }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<form action="/auth/login" method="post" class="space-y-4">
|
||||
<input type="hidden" name="next" value="{{ next }}">
|
||||
|
||||
<div>
|
||||
<label for="username" class="block text-sm font-medium text-gray-700 mb-1">Username or Email</label>
|
||||
<input
|
||||
type="text"
|
||||
id="username"
|
||||
name="username"
|
||||
value="{{ username or '' }}"
|
||||
required
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-irish-green focus:border-irish-green"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="password" class="block text-sm font-medium text-gray-700 mb-1">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-irish-green focus:border-irish-green"
|
||||
>
|
||||
</div>
|
||||
|
||||
<!-- Debug info -->
|
||||
<div class="text-xs text-gray-500">
|
||||
<p>Having trouble logging in? Make sure your browser accepts cookies.</p>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="remember"
|
||||
name="remember"
|
||||
class="h-4 w-4 text-irish-green focus:ring-irish-green border-gray-300 rounded"
|
||||
>
|
||||
<label for="remember" class="ml-2 block text-sm text-gray-700">Remember me</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full bg-irish-green text-white py-2 px-4 rounded-md hover:bg-opacity-90 transition focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-irish-green"
|
||||
>
|
||||
Log In
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="text-center text-sm mt-4">
|
||||
<a href="/auth/forgot-password" class="text-irish-green hover:text-opacity-80">Forgot password?</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="mt-6 pt-6 border-t border-gray-200 text-center">
|
||||
<p class="text-gray-600">Don't have an account?</p>
|
||||
<a href="/auth/register" class="block mt-2 bg-cream-white text-irish-green border border-irish-green py-2 px-4 rounded-md hover:bg-irish-green hover:text-white transition">
|
||||
Create an account
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- OAuth login options (to be implemented later) -->
|
||||
<div class="mt-6 pt-6 border-t border-gray-200">
|
||||
<p class="text-center text-gray-600 mb-4">Or sign in with</p>
|
||||
<div class="flex justify-center space-x-4">
|
||||
<button class="bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-opacity-90 transition w-full disabled:opacity-50" disabled>
|
||||
<i class="fab fa-google mr-2"></i> Google
|
||||
</button>
|
||||
<button class="bg-gray-800 text-white py-2 px-4 rounded-md hover:bg-opacity-90 transition w-full disabled:opacity-50" disabled>
|
||||
<i class="fab fa-github mr-2"></i> GitHub
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-center text-gray-500 text-xs mt-2">OAuth login coming soon</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,188 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="max-w-4xl mx-auto">
|
||||
<div class="bg-white rounded-lg shadow-md overflow-hidden mb-8">
|
||||
<!-- Profile Header -->
|
||||
<div class="bg-irish-green text-white p-6">
|
||||
<div class="flex flex-col sm:flex-row items-center">
|
||||
<div class="w-24 h-24 rounded-full bg-white border-4 border-white overflow-hidden mb-4 sm:mb-0 sm:mr-6">
|
||||
<img src="https://via.placeholder.com/150" alt="Profile" class="w-full h-full object-cover">
|
||||
</div>
|
||||
<div class="text-center sm:text-left">
|
||||
<h1 class="text-2xl font-bold">{{ user.username }}</h1>
|
||||
<p class="text-green-100">Member since {{ user.created_at.strftime('%B %Y') }}</p>
|
||||
<p class="mt-2">
|
||||
{% if user.is_verified %}
|
||||
<span class="bg-golden-ale text-black-stout text-xs px-2 py-1 rounded-full font-medium mr-1">Verified</span>
|
||||
{% endif %}
|
||||
<span class="bg-white text-irish-green text-xs px-2 py-1 rounded-full font-medium">{{ user.memberships|length }} Teams</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Messages/Alerts -->
|
||||
{% if messages %}
|
||||
<div class="p-4">
|
||||
{% for message in messages %}
|
||||
<div class="mb-4 p-3 rounded {% if message.type == 'error' %}bg-red-100 text-red-700{% else %}bg-green-100 text-green-700{% endif %}">
|
||||
{{ message.text }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Profile Content -->
|
||||
<div class="p-6">
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
<!-- Left Column: Personal Info -->
|
||||
<div class="md:col-span-1">
|
||||
<h2 class="text-xl font-semibold text-irish-green mb-4">Personal Information</h2>
|
||||
|
||||
<form action="/auth/update-profile" method="post" class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-600">Display Name</label>
|
||||
<div class="mt-1">
|
||||
<input
|
||||
type="text"
|
||||
name="username"
|
||||
value="{{ user.username }}"
|
||||
class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-irish-green"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-600">Email</label>
|
||||
<div class="mt-1">
|
||||
<input
|
||||
type="email"
|
||||
name="email"
|
||||
value="{{ user.email }}"
|
||||
class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-irish-green"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pt-4">
|
||||
<button type="submit" class="w-full bg-irish-green hover:bg-opacity-90 text-white font-medium py-2 px-4 rounded-md transition">
|
||||
Update Profile
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="mt-6 pt-6 border-t">
|
||||
<h3 class="text-lg font-medium text-irish-green mb-3">Change Password</h3>
|
||||
<form action="/auth/change-password" method="post" class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-600">Current Password</label>
|
||||
<div class="mt-1">
|
||||
<input
|
||||
type="password"
|
||||
name="current_password"
|
||||
required
|
||||
class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-irish-green"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-600">New Password</label>
|
||||
<div class="mt-1">
|
||||
<input
|
||||
type="password"
|
||||
name="new_password"
|
||||
required
|
||||
class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-irish-green"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-600">Confirm New Password</label>
|
||||
<div class="mt-1">
|
||||
<input
|
||||
type="password"
|
||||
name="confirm_password"
|
||||
required
|
||||
class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-irish-green"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="w-full bg-golden-ale hover:bg-opacity-90 text-black-stout font-medium py-2 px-4 rounded-md transition">
|
||||
Change Password
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right Column: Stats & Teams -->
|
||||
<div class="md:col-span-2">
|
||||
<h2 class="text-xl font-semibold text-irish-green mb-4">Your Statistics</h2>
|
||||
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
|
||||
<div class="bg-cream-white p-4 rounded-lg text-center">
|
||||
<p class="text-sm text-gray-600">Total Points</p>
|
||||
<p class="text-2xl font-bold text-irish-green">378</p>
|
||||
</div>
|
||||
<div class="bg-cream-white p-4 rounded-lg text-center">
|
||||
<p class="text-sm text-gray-600">QR Codes Redeemed</p>
|
||||
<p class="text-2xl font-bold text-irish-green">24</p>
|
||||
</div>
|
||||
<div class="bg-cream-white p-4 rounded-lg text-center">
|
||||
<p class="text-sm text-gray-600">Teams Joined</p>
|
||||
<p class="text-2xl font-bold text-irish-green">{{ user.memberships|length }}</p>
|
||||
</div>
|
||||
<div class="bg-cream-white p-4 rounded-lg text-center">
|
||||
<p class="text-sm text-gray-600">Best Position</p>
|
||||
<p class="text-2xl font-bold text-irish-green">#2</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2 class="text-xl font-semibold text-irish-green mb-4">Your Teams</h2>
|
||||
<div class="space-y-4">
|
||||
{% for team_info in user_teams %}
|
||||
<div class="border rounded-lg overflow-hidden">
|
||||
<div class="bg-cream-white px-4 py-3 flex justify-between items-center">
|
||||
<div class="font-medium">{{ team_info.team.name }}</div>
|
||||
{% if team_info.is_admin %}
|
||||
<span class="bg-golden-ale text-black-stout text-xs px-2 py-1 rounded-full">Captain</span>
|
||||
{% else %}
|
||||
<span class="bg-gray-200 text-gray-700 text-xs px-2 py-1 rounded-full">Member</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="px-4 py-3 flex justify-between items-center">
|
||||
<div>
|
||||
<p class="text-sm">Current Points: <span class="font-bold">187</span></p>
|
||||
<p class="text-sm text-gray-600">Current Rank: #4</p>
|
||||
</div>
|
||||
<a href="/teams/{{ team_info.team.id }}" class="text-irish-green hover:underline text-sm">View Team</a>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="text-center p-4 bg-gray-50 rounded-lg">
|
||||
<p class="text-gray-600">You haven't joined any teams yet.</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<a href="/teams/" class="block text-center text-irish-green hover:underline text-sm">
|
||||
<i class="fas fa-plus mr-1"></i> Join or Create Another Team
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Account Management -->
|
||||
<div class="mt-8 pt-6 border-t">
|
||||
<h3 class="text-xl text-red-600 font-semibold mb-4">Danger Zone</h3>
|
||||
<p class="text-gray-700 mb-4">These actions cannot be undone. Please be certain.</p>
|
||||
|
||||
<a href="/auth/delete-account" class="inline-block bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-md">
|
||||
Delete Account
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,94 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="max-w-md mx-auto my-8">
|
||||
<div class="bg-white p-8 rounded-lg shadow-md">
|
||||
<h1 class="text-2xl font-bold text-irish-green mb-6 text-center">Create an Account</h1>
|
||||
|
||||
<!-- Messages/Alerts -->
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div class="mb-4 p-3 rounded {% if message.type == 'error' %}bg-red-100 text-red-700{% else %}bg-green-100 text-green-700{% endif %}">
|
||||
{{ message.text }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<form action="/auth/register" method="post" class="space-y-4">
|
||||
<div>
|
||||
<label for="username" class="block text-sm font-medium text-gray-700 mb-1">Username</label>
|
||||
<input
|
||||
type="text"
|
||||
id="username"
|
||||
name="username"
|
||||
value="{{ username or '' }}"
|
||||
required
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-irish-green focus:border-irish-green"
|
||||
>
|
||||
<p class="text-xs text-gray-500 mt-1">Choose a unique username (3-30 characters, letters, numbers and underscores only)</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="email" class="block text-sm font-medium text-gray-700 mb-1">Email</label>
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
name="email"
|
||||
value="{{ email or '' }}"
|
||||
required
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-irish-green focus:border-irish-green"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="password" class="block text-sm font-medium text-gray-700 mb-1">Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
required
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-irish-green focus:border-irish-green"
|
||||
>
|
||||
<p class="text-xs text-gray-500 mt-1">At least 8 characters</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="confirm_password" class="block text-sm font-medium text-gray-700 mb-1">Confirm Password</label>
|
||||
<input
|
||||
type="password"
|
||||
id="confirm_password"
|
||||
name="confirm_password"
|
||||
required
|
||||
class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-irish-green focus:border-irish-green"
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="flex items-start">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="terms"
|
||||
name="terms"
|
||||
required
|
||||
class="h-4 w-4 mt-1 text-irish-green focus:ring-irish-green border-gray-300 rounded"
|
||||
>
|
||||
<label for="terms" class="ml-2 block text-sm text-gray-700">
|
||||
I agree to the <a href="/terms" class="text-irish-green hover:underline" target="_blank">Terms of Service</a> and <a href="/privacy" class="text-irish-green hover:underline" target="_blank">Privacy Policy</a>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button
|
||||
type="submit"
|
||||
class="w-full bg-irish-green text-white py-2 px-4 rounded-md hover:bg-opacity-90 transition focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-irish-green"
|
||||
>
|
||||
Create Account
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="mt-6 pt-6 border-t border-gray-200 text-center">
|
||||
<p class="text-gray-600">Already have an account?</p>
|
||||
<a href="/auth/login" class="text-irish-green hover:underline">Log in</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,34 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="max-w-md mx-auto my-12">
|
||||
<div class="bg-white p-8 rounded-lg shadow-md text-center">
|
||||
<div class="mb-6">
|
||||
<div class="inline-block p-4 rounded-full bg-green-100">
|
||||
<i class="fas fa-check-circle text-irish-green text-5xl"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1 class="text-2xl font-bold text-irish-green mb-4">Registration Successful!</h1>
|
||||
<p class="text-gray-600 mb-6">Your account has been created and you're now logged in.</p>
|
||||
|
||||
<div class="space-y-4">
|
||||
<a href="/dashboard" class="block w-full bg-irish-green hover:bg-opacity-90 text-white font-medium py-2 px-4 rounded-md transition">
|
||||
Go to Dashboard
|
||||
</a>
|
||||
<a href="/teams/" class="block w-full bg-cream-white border border-irish-green text-irish-green hover:bg-irish-green hover:text-white font-medium py-2 px-4 rounded-md transition">
|
||||
Join a Team
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="mt-8 pt-6 border-t border-gray-200">
|
||||
<h2 class="font-semibold mb-2">What's Next?</h2>
|
||||
<ul class="text-left text-sm space-y-2">
|
||||
<li><i class="fas fa-check-circle text-irish-green mr-2"></i> Explore the pub quiz leaderboards</li>
|
||||
<li><i class="fas fa-check-circle text-irish-green mr-2"></i> Join an existing team or create your own</li>
|
||||
<li><i class="fas fa-check-circle text-irish-green mr-2"></i> Scan QR codes at quiz events to earn points</li>
|
||||
<li><i class="fas fa-check-circle text-irish-green mr-2"></i> Complete your profile information</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user