Skip to content

implement login with google#1038

Open
Ananya44444 wants to merge 6 commits intoalphaonelabs:mainfrom
Ananya44444:login
Open

implement login with google#1038
Ananya44444 wants to merge 6 commits intoalphaonelabs:mainfrom
Ananya44444:login

Conversation

@Ananya44444
Copy link
Contributor

@Ananya44444 Ananya44444 commented Mar 19, 2026

Google OAuth Login

Adds "Login with Google" and "Sign up with Google" buttons to the login and signup pages using django-allauth's social account module.

Changes

  • Added allauth.socialaccount and allauth.socialaccount.providers.google to INSTALLED_APPS
  • Configured SOCIALACCOUNT_PROVIDERS in settings.py to read credentials from environment variables
  • Added Google button to login.html and signup.html

Production Setup Required

Before deploying, please:

  1. Add to .env:
    • GOOGLE_CLIENT_ID=
    • GOOGLE_CLIENT_SECRET=
  2. In Google Cloud Console, add authorized redirect URI:(IMP otherwise it will break)
    -https://www.alphaonelabs.com/en/accounts/google/login/callback/
    -https://www.alphaonelabs.com/es/accounts/google/login/callback/
    -https://www.alphaonelabs.com/fr/accounts/google/login/callback/
    -https://www.alphaonelabs.com/de/accounts/google/login/callback/
    -https://www.alphaonelabs.com/zh-hans/accounts/google/login/callback/
  3. Add authorized JavaScript origin:
    • https://www.alphaonelabs.com
  4. Do NOT add a Google app via Django admin as credentials are handled via settings.py
Screen.Recording.2026-03-20.025824.mp4

Purpose

Adds Google OAuth login and signup via django-allauth so users can authenticate with Google accounts.

Key Changes

  • web/settings.py
    • Added "allauth.socialaccount" and "allauth.socialaccount.providers.google" to INSTALLED_APPS.
    • Added SOCIALACCOUNT_FORMS and set SOCIALACCOUNT_AUTO_SIGNUP = False.
    • Introduced SOCIALACCOUNT_PROVIDERS for Google (scopes: profile, email; access_type: online; auth params) and set SOCIALACCOUNT_EMAIL_VERIFICATION = "mandatory" and SOCIALACCOUNT_EMAIL_REQUIRED = True.
    • Loads GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET from environment and enforces their presence when DEBUG is False (raises ImproperlyConfigured).
    • Adjusted MESSAGE_ENCRYPTION_KEY / SECURE_MESSAGE_KEY behavior: default is now empty string; a Fernet key is generated only for "early debug" scenarios (development/test or collectstatic); in production startup will raise ImproperlyConfigured when the key is missing. Added EARLY_DEBUG and descriptive error messages.
  • Templates
    • web/templates/account/login.html: loads i18n and socialaccount tags; inserts an "Or continue with" divider and a localized "Sign in with Google" button using {% provider_login_url 'google' next=... %} with a Google SVG icon.
    • web/templates/account/signup.html: loads i18n and socialaccount tags; inserts an "Or sign up with" divider and a localized "Sign up with Google" button using {% provider_login_url 'google' next=... %} with a Google SVG icon.
  • web/forms.py
    • Added SocialUserRegistrationForm (subclass of allauth's SocialSignupForm) exported via all; includes first_name, last_name, optional is_teacher, referral_code validation, how_did_you_hear_about_us, captcha, and is_profile_public. save(request) applies profile updates and handles referrals.
  • pyproject.toml
    • Added dependency: pyjwt = "^2.12.1".

Impact

  • Enables Google-based login/signup with mandatory email verification for social accounts and explicit social signup form handling.
  • Startup will fail fast in production if GOOGLE_CLIENT_ID/GOOGLE_CLIENT_SECRET or required message-encryption key are not set.
  • UI: login and signup pages now include Google OAuth buttons and a visual divider; existing forms and flows remain unchanged otherwise.
  • Deployment requires setting GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET in environment and configuring Google Cloud OAuth authorized redirect URIs for each locale plus the JS origin (https://www.alphaonelabs.com). Do not add the Google app via Django admin; credentials are managed in settings.

Review Effort

  • High: settings (credential validation, encryption key behavior, allauth integration, SOCIALACCOUNT_FORMS).
  • Medium: new social signup form and template additions.
  • Low: dependency addition.

Copilot AI review requested due to automatic review settings March 19, 2026 22:18
@github-actions
Copy link
Contributor

👀 Peer Review Required

Hi @Ananya44444! This pull request does not yet have a peer review.

Before this PR can be merged, please request a review from one of your peers:

  • Go to the PR page and click "Reviewers" on the right sidebar.
  • Select a team member or contributor to review your changes.
  • Once they approve, this reminder will be automatically removed.

Thank you for contributing! 🎉

@github-actions github-actions bot added the files-changed: 3 PR changes 3 files label Mar 19, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'tools'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

Adds Google OAuth via django-allauth (templates and settings), enforces runtime validation for message encryption key and Google OAuth credentials in settings, introduces a social signup form, and adds pyjwt as a runtime dependency.

Changes

Cohort / File(s) Summary
Settings / OAuth & security
web/settings.py
Imports ImproperlyConfigured; introduces EARLY_DEBUG/messages; changes MESSAGE_ENCRYPTION_KEY/SECURE_MESSAGE_KEY to default to "" and generate only for early/debug/collectstatic paths, otherwise raise ImproperlyConfigured; requires GOOGLE_CLIENT_ID/GOOGLE_CLIENT_SECRET when DEBUG=False; adds allauth.socialaccount and allauth.socialaccount.providers.google to INSTALLED_APPS; adds SOCIALACCOUNT_FORMS, SOCIALACCOUNT_AUTO_SIGNUP=False, SOCIALACCOUNT_PROVIDERS, SOCIALACCOUNT_EMAIL_VERIFICATION="mandatory", and SOCIALACCOUNT_EMAIL_REQUIRED=True.
Templates: authentication UI
web/templates/account/login.html, web/templates/account/signup.html
Loads {% load i18n socialaccount %} and inserts a translatable divider plus Google OAuth buttons using {% provider_login_url 'google' next=redirect_field_value %} with a static Google SVG icon; UI-only additions, no changes to existing form fields or submit logic.
Forms: social signup
web/forms.py
Adds SocialUserRegistrationForm (subclass of allauth's social signup) with fields: first_name, last_name, optional is_teacher, referral_code, how_did_you_hear_about_us, captcha, and required is_profile_public; implements clean_referral_code() and save(request) to populate user/profile and handle referral logic; exports form via __all__.
Dependencies
pyproject.toml
Adds runtime dependency pyjwt = "^2.12.1".

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Browser
  participant App as "Django App\n(allauth)"
  participant Google as "Google OAuth"
  participant DB as "Database"

  User->>Browser: Click "Sign in with Google"
  Browser->>App: Request provider login URL / initiate OAuth
  App->>Google: Redirect with client_id, scope, redirect_uri
  Google->>User: Prompt for consent / credentials
  User->>Google: Authenticate and consent
  Google->>Browser: Redirect back with code
  Browser->>App: Return to callback URL with code
  App->>Google: Exchange code for token (client_id, client_secret)
  Google->>App: Return access token and user info
  App->>DB: Create or update user record (and profile)
  App->>Browser: Set session and redirect to next
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the changeset: implementing Google OAuth login functionality across the application.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can get early access to new features in CodeRabbit.

Enable the early_access setting to enable early access features such as new models, tools, and more.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Google OAuth authentication entry points using django-allauth socialaccount integration so users can initiate “Sign in/up with Google” from the existing allauth login/signup pages.

Changes:

  • Added Google provider + socialaccount apps and Google provider settings in web/settings.py.
  • Added “Continue with Google” UI to login.html and “Sign up with Google” UI to signup.html.
  • Adjusted environment variable loading behavior in web/settings.py.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
web/settings.py Enables allauth socialaccount + Google provider and configures Google credentials via env vars; also changes .env loading logic.
web/templates/account/login.html Adds a divider and “Sign in with Google” link/button.
web/templates/account/signup.html Adds a divider and “Sign up with Google” link/button.
Comments suppressed due to low confidence (1)

web/settings.py:26

  • environ.Env.read_env(env_file) is now called unconditionally, but the file is also conditionally loaded again a few lines later. This is redundant and can also change startup behavior if .env is missing (the later os.path.exists branch suggests missing .env is expected). Remove the unconditional call and keep a single, consistent .env loading path.
env_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), ".env")
environ.Env.read_env(env_file)

# Set encryption key for secure messaging; in production, this must come from the environment
MESSAGE_ENCRYPTION_KEY = env.str("MESSAGE_ENCRYPTION_KEY", default=Fernet.generate_key()).strip()
SECURE_MESSAGE_KEY = MESSAGE_ENCRYPTION_KEY

if os.path.exists(env_file):
    environ.Env.read_env(env_file)
else:

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/settings.py`:
- Around line 134-136: The INSTALLED_APPS order is incorrect: move the
"allauth.socialaccount" and "allauth.socialaccount.providers.google" entries so
they come after the core allauth apps ("allauth" and "allauth.account") in the
INSTALLED_APPS list; locate the INSTALLED_APPS definition in web/settings.py and
reorder the entries so that "allauth" and "allauth.account" appear before
"allauth.socialaccount" and "allauth.socialaccount.providers.google".
- Line 18: Remove the unconditional call to environ.Env.read_env(env_file) and
keep only the conditional read that checks for the file's existence (the block
that uses os.path.exists(env_file) and then calls environ.Env.read_env(env_file)
or prints a message); specifically, delete the lone
environ.Env.read_env(env_file) invocation so the conditional branch around
environ.Env.read_env(env_file) is the single source of truth for loading the
.env file.
- Around line 550-551: SOCIALACCOUNT_EMAIL_REQUIRED is set to False which can
create accounts without emails while ACCOUNT_EMAIL_REQUIRED and
ACCOUNT_EMAIL_AUTHENTICATION are True; update SOCIALACCOUNT_EMAIL_REQUIRED to
True (and ensure SOCIALACCOUNT_EMAIL_VERIFICATION remains consistent with your
policy) so Google/social sign-ups always collect an email and align with
ACCOUNT_EMAIL_REQUIRED and ACCOUNT_EMAIL_AUTHENTICATION to prevent accounts
missing email-based authentication.

In `@web/templates/account/login.html`:
- Around line 90-108: The Google icon is loaded from an external CDN in the <a>
button's <img> (src="https://www.svgrepo.com/...") which can break if the CDN is
unavailable; download the SVG into your project's static assets (e.g.,
static/images/google-icon.svg) and update the <img> in the login template (the
anchor tag that uses provider_login_url 'google') to reference the local static
asset instead of the external URL, ensuring you load it via your framework's
static file helper so it works in production and during collectstatic.

In `@web/templates/account/signup.html`:
- Around line 252-270: The template currently loads the Google SVG from an
external URL in the img tag
("https://www.svgrepo.com/show/475656/google-color.svg"); to self-host it, save
that SVG into your static assets (e.g., static/images/google-color.svg) and
update the img src in the signup template to reference the local static file
(use your project's static/template helper, e.g., {% load static %} and {%
static 'images/google-color.svg' %}) so the button (the <a> with
provider_login_url 'google' and the img alt="Google") uses the local asset and
will work offline/if the external host is down; remember to add the SVG to
version control and run collectstatic if required.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2f56c145-2289-457d-9d17-72118fb76f7e

📥 Commits

Reviewing files that changed from the base of the PR and between c94caf8 and 6ee465e.

📒 Files selected for processing (3)
  • web/settings.py
  • web/templates/account/login.html
  • web/templates/account/signup.html

@github-actions github-actions bot added files-changed: 6 PR changes 6 files and removed files-changed: 3 PR changes 3 files labels Mar 19, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

💬 Unresolved Review Conversations

Hi @Ananya44444! 👋

This pull request currently has 3 unresolved review conversations.

Please address all review feedback and push a new commit to resolve them before this PR can be merged.

Steps to resolve:

  1. Review each comment thread in the "Files changed" tab.
  2. Make the necessary changes to your code.
  3. Reply to each conversation to explain your changes or ask for clarification.
  4. Click "Resolve conversation" once the feedback has been addressed.
  5. Push a new commit with your changes.

Once all conversations are resolved, this notice will be removed automatically. Thank you! 🙏

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has 3 unresolved review conversations. Please resolve them before this PR can be merged.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

♻️ Duplicate comments (1)
web/templates/account/signup.html (1)

257-258: ⚠️ Potential issue | 🟡 Minor

Mirror the divider dark-mode fix here.

This label has the same missing dark:text-* variant as the login divider, so it drops contrast in dark mode too.

As per coding guidelines "Always include dark mode alternatives using dark: prefix for elements".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/templates/account/signup.html` around lines 257 - 258, The divider label
span containing the text "Or sign up with" currently has classes "bg-white
dark:bg-gray-800 px-2 text-gray-500" and is missing a dark-mode text variant;
update that span's class list to include the same dark:text utility used for the
login divider (e.g., add dark:text-gray-400 or the project's chosen dark text
class) so the label retains sufficient contrast in dark mode (refer to the span
with text "Or sign up with" to locate the element).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/settings.py`:
- Around line 541-542: The raise in the settings conditional uses a hard-coded
message which triggers Ruff TRY003; refactor by extracting the message into a
named constant or by creating a small custom exception helper and using that
instead of inlining the string. Update the conditional that checks DEBUG and
(google_client_id or google_client_secret) to raise ImproperlyConfigured with
the constant (e.g., GOOGLE_CLIENT_CREDENTIALS_ERROR) or raise a thin helper
exception (e.g., raise_missing_google_credentials()) while keeping the symbols
DEBUG, google_client_id, google_client_secret, and ImproperlyConfigured
unchanged so the lint warning is resolved.
- Around line 544-553: The OAuth callback mismatch happens because your
accounts/allauth routes are inside i18n_patterns and produce locale-prefixed
callback URIs; move the accounts routes out of i18n_patterns so the callback is
locale-agnostic: locate the urls.py references to i18n_patterns and the
path/include that uses "accounts/" or "include('allauth.urls')" and relocate
that path to the top-level URL patterns (before or after i18n_patterns) so the
callback URI registered with Google is always used; after moving, verify
LOGIN_REDIRECT_URL/LOGIN_URL behavior and update any reverse() uses if
necessary.
- Around line 24-26: The current settings allow silent generation of a new
MESSAGE_ENCRYPTION_KEY which will break decryption in production; update
web/settings.py to require MESSAGE_ENCRYPTION_KEY when not DEBUG by checking
DEBUG and env("MESSAGE_ENCRYPTION_KEY", default=None) and raising
django.core.exceptions.ImproperlyConfigured if missing, while keeping the
development path to generate a key (use Fernet.generate_key().decode() to store
a string for MESSAGE_ENCRYPTION_KEY/SECURE_MESSAGE_KEY); also audit places that
instantiate Fernet (e.g., any Fernet(...) usage) and ensure they call .encode()
on SECURE_MESSAGE_KEY so Fernet receives bytes.

In `@web/templates/account/login.html`:
- Around line 95-96: The divider label span uses text-gray-500 which lacks a
dark-mode alternative; update the span's class (the element containing "Or
continue with") to include a dark:text-gray-300 variant (add
"dark:text-gray-300" alongside "text-gray-500") and make the same change to the
equivalent signup divider span so the label remains readable against
dark:bg-gray-800.

---

Duplicate comments:
In `@web/templates/account/signup.html`:
- Around line 257-258: The divider label span containing the text "Or sign up
with" currently has classes "bg-white dark:bg-gray-800 px-2 text-gray-500" and
is missing a dark-mode text variant; update that span's class list to include
the same dark:text utility used for the login divider (e.g., add
dark:text-gray-400 or the project's chosen dark text class) so the label retains
sufficient contrast in dark mode (refer to the span with text "Or sign up with"
to locate the element).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5a05c6a3-4777-4d78-b935-7f73c6d5cf53

📥 Commits

Reviewing files that changed from the base of the PR and between 6ee465e and ed52b82.

⛔ Files ignored due to path filters (2)
  • poetry.lock is excluded by !**/*.lock, !**/*.lock
  • web/static/images/google-icon.svg is excluded by !**/*.svg
📒 Files selected for processing (4)
  • pyproject.toml
  • web/settings.py
  • web/templates/account/login.html
  • web/templates/account/signup.html

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/settings.py`:
- Around line 17-21: EARLY_DEBUG (and any other env-derived fallbacks around
lines 28-34) is being computed before the .env is loaded and before test mode is
set, causing premature behavior; move the EARLY_DEBUG computation (the
env.bool("DEBUG", default=False) call) and any related fallback logic (e.g.,
MESSAGE_ENCRYPTION_KEY_REQUIRED_MSG / GOOGLE_OAUTH_CREDENTIALS_REQUIRED_MSG
usage) to after the env_file is loaded and after test-mode toggles so that DEBUG
is resolved from the same inputs (.env and test flags) as the rest of the
settings; update references to EARLY_DEBUG accordingly so the fallback decision
happens only after env.read_env (or equivalent) and test detection run.

In `@web/templates/account/login.html`:
- Line 5: The template currently only loads socialaccount and has hard-coded
English labels; add i18n support by adding `{% load i18n %}` alongside `{% load
socialaccount %}` and wrap the new Google-login divider and button text (the
strings introduced near the `{% load socialaccount %}` area and the block
covering lines ~96-107) in translation tags (`{% trans "Your label" %}` or `{%
blocktrans %}...{% endblocktrans %}`) so they are localized; make the identical
changes in signup.html to keep both auth pages translated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5f04b94d-530b-4687-9e4e-0332286b4ca0

📥 Commits

Reviewing files that changed from the base of the PR and between ed52b82 and 89f6c98.

📒 Files selected for processing (3)
  • web/settings.py
  • web/templates/account/login.html
  • web/templates/account/signup.html

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/settings.py`:
- Around line 555-564: The Google provider config in SOCIALACCOUNT_PROVIDERS is
missing the provider-level EMAIL_AUTHENTICATION flag; update the "google"
dictionary inside SOCIALACCOUNT_PROVIDERS to include EMAIL_AUTHENTICATION: True
so django-allauth will trust verified Google emails and match existing local
users by email (modify the existing SOCIALACCOUNT_PROVIDERS -> "google" dict
where client_id/secret, SCOPE, and AUTH_PARAMS are defined).
- Around line 555-567: Add a SOCIALACCOUNT_FORMS entry in settings to route
social signups through your onboarding form (e.g. set
SOCIALACCOUNT_FORMS["signup"] to your UserRegistrationForm or a
SocialSignupForm) and either implement the same validation for referral code,
captcha, and profile visibility on that form (class name: UserRegistrationForm
or new SocialSignupForm) or disable SOCIALACCOUNT_AUTO_SIGNUP so users must
submit the form; update settings to include SOCIALACCOUNT_FORMS and adjust
SOCIALACCOUNT_AUTO_SIGNUP accordingly so Google signups cannot bypass
onboarding.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: afefd50f-33eb-4e09-88da-59e357021008

📥 Commits

Reviewing files that changed from the base of the PR and between 89f6c98 and 1bc2a30.

📒 Files selected for processing (3)
  • web/settings.py
  • web/templates/account/login.html
  • web/templates/account/signup.html

@github-actions github-actions bot added files-changed: 7 PR changes 7 files and removed files-changed: 6 PR changes 6 files labels Mar 21, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/forms.py`:
- Around line 313-350: Extract the duplicated field definitions into a single
reusable mixin or shared constants and have both forms inherit/use it: create a
RegistrationFieldsMixin (or similar) that declares first_name, last_name,
is_teacher, referral_code, how_did_you_hear_about_us, captcha, and
is_profile_public using the existing
TailwindInput/TailwindTextarea/TailwindCheckboxInput/CaptchaField setup, then
update UserRegistrationForm and the other form (the class containing these
fields) to inherit RegistrationFieldsMixin and remove the duplicated field
declarations; ensure the coerce lambda and widget choices are preserved exactly
when moving is_profile_public.
- Line 312: Add a descriptive docstring to the SocialUserRegistrationForm class
explaining its purpose and when it is used (e.g., registration via social auth)
and how it differs from the regular UserRegistrationForm; place the docstring
immediately under the class declaration in the SocialUserRegistrationForm class
definition and keep it concise, describing intent, expected behavior, and any
special fields or validation that differ from UserRegistrationForm.
- Around line 358-377: The save method lacks type annotations and doesn't guard
against exceptions from referral processing; add proper type hints to the method
signature (e.g., request: HttpRequest and return type -> User or the project's
User model) and wrap the call to handle_referral(user, referral_code) in a
try/except that catches broad referral-related errors (exceptions raised by
add_referral_earnings or send_referral_reward_email) and logs the failure (using
the module/class logger) without interrupting user creation; keep the existing
behavior when referral_code is falsy and still return user at the end.
- Around line 352-356: Extract the inline validation message in
UserRegistrationForm.clean_referral_code into a shared constant (e.g.,
REFERRAL_CODE_INVALID_MSG) at module scope and replace the string literal in
clean_referral_code with that constant; ensure any other occurrences (such as
other forms that use the same message) reference the same constant to keep
messages consistent and satisfy the linter (Ruff TRY003).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ce58b08e-b03d-42e1-bfd0-451eb087f663

📥 Commits

Reviewing files that changed from the base of the PR and between 1bc2a30 and 2f1ebcc.

📒 Files selected for processing (2)
  • web/forms.py
  • web/settings.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

files-changed: 7 PR changes 7 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants