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 @@

📚 Study Platform

{% if user.is_staff %}
  • Feedback Review
  • {% endif %} -
  • Admin
  • {% csrf_token %} diff --git a/study/templates/study/home.html b/study/templates/study/home.html index b91fe14..1d6cd17 100644 --- a/study/templates/study/home.html +++ b/study/templates/study/home.html @@ -28,7 +28,7 @@

    📝 Study Sessions

    🎯 Quick Start

    Jump into studying

    - Manage Content + Create Course
    diff --git a/study/templates/study/login.html b/study/templates/study/login.html index 975c9ee..6882bfe 100644 --- a/study/templates/study/login.html +++ b/study/templates/study/login.html @@ -1,4 +1,5 @@ {% extends 'study/base.html' %} +{% load socialaccount %} {% block title %}Login - Study Platform{% endblock %} @@ -6,6 +7,32 @@

    Login

    + {% if oauth_github_enabled or oauth_google_enabled %} + +
    +

    Sign in with a social account

    +
    + {% if oauth_github_enabled %} + + + Sign in with GitHub + + {% endif %} + {% if oauth_google_enabled %} + + + Sign in with Google + + {% endif %} +
    +
    + +
    +
    + or sign in with username +
    + {% endif %} + {% csrf_token %} diff --git a/study/templates/study/register.html b/study/templates/study/register.html index 7af9d68..7f5fc8e 100644 --- a/study/templates/study/register.html +++ b/study/templates/study/register.html @@ -1,4 +1,5 @@ {% extends 'study/base.html' %} +{% load socialaccount %} {% block title %}Register - Study Platform{% endblock %} @@ -6,6 +7,32 @@

    Register

    + {% if oauth_github_enabled or oauth_google_enabled %} + +
    +

    Sign up with a social account

    +
    + {% if oauth_github_enabled %} + + + Sign up with GitHub + + {% endif %} + {% if oauth_google_enabled %} + + + Sign up with Google + + {% endif %} +
    +
    + +
    +
    + or register with username +
    + {% endif %} + {% csrf_token %} @@ -33,6 +60,14 @@

    Register< {% endif %}

    {% endfor %} + + +
    + ⚠️ No email? +

    + If you do not provide an email address, there will be no way to recover your password if forgotten. +

    +
    @@ -43,7 +78,7 @@

    Register<