diff --git a/.env.example b/.env.example index 141a969..8c2c3c9 100644 --- a/.env.example +++ b/.env.example @@ -2,3 +2,11 @@ SECRET_KEY=your-secret-key-here DEBUG=True ALLOWED_HOSTS=localhost,127.0.0.1 GITHUB_REPO=owner/repo-name + +# OAuth providers (optional - set these only if you plan to use them) +# GitHub: https://github.com/settings/applications/new +GITHUB_OAUTH_CLIENT_ID= +GITHUB_OAUTH_SECRET= +# Google: https://console.developers.google.com/apis/credentials +GOOGLE_OAUTH_CLIENT_ID= +GOOGLE_OAUTH_SECRET= diff --git a/requirements.txt b/requirements.txt index 296458c..02998da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ numpy>=1.24.0 RestrictedPython>=6.0 dj-database-url>=2.0.0 psycopg2-binary>=2.9.0 +django-allauth[socialaccount]>=65.0.0 diff --git a/study/context_processors.py b/study/context_processors.py index c76fe3e..902fa86 100644 --- a/study/context_processors.py +++ b/study/context_processors.py @@ -6,3 +6,12 @@ def github_repo(request): return { 'GITHUB_REPO': getattr(settings, 'GITHUB_REPO', ''), } + + +def oauth_providers(request): + """Make configured OAuth provider names available in all templates.""" + providers = getattr(settings, 'SOCIALACCOUNT_PROVIDERS', {}) + return { + 'oauth_github_enabled': 'github' in providers, + 'oauth_google_enabled': 'google' in providers, + } diff --git a/study/forms.py b/study/forms.py index fcac5c0..091f72a 100644 --- a/study/forms.py +++ b/study/forms.py @@ -1,6 +1,22 @@ from django import forms +from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.models import User from .models import Course, Topic, Flashcard, CardFeedback, Skill + +class RegistrationForm(UserCreationForm): + """Custom registration form with optional email and privacy warning.""" + email = forms.EmailField( + required=False, + widget=forms.EmailInput(attrs={'class': 'form-control', 'placeholder': 'Optional email address'}), + help_text='Optional. Providing an email allows password recovery. Without it, there is no way to reset a forgotten password.', + ) + + class Meta: + model = User + fields = ['username', 'email', 'password1', 'password2'] + + class CourseForm(forms.ModelForm): class Meta: model = Course diff --git a/study/templates/study/base.html b/study/templates/study/base.html index 7504a83..b678b4b 100644 --- a/study/templates/study/base.html +++ b/study/templates/study/base.html @@ -240,7 +240,6 @@