refactor: Split auth into services#54
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the authentication workflow by extracting most of the business logic from apps/auth/views.py / apps/auth/utils.py into a dedicated apps/auth/services/ layer, aiming to make the auth flow more modular and easier to maintain.
Changes:
- Moved OTP/temp-token, questionnaire callback verification, password validation, captcha verification, and user session creation into service modules.
- Simplified DRF views to delegate to service functions and translate
ServiceErrorinto HTTP responses. - Reduced
apps/auth/utils.pyto only contain CSRF-enforcing session authentication.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/auth/views.py | Delegates auth endpoints to services.* and centralizes error-to-Response mapping. |
| apps/auth/utils.py | Removes previous auth helpers; keeps only CSRFCheckSessionAuthentication. |
| apps/auth/services/init.py | Public re-exports for the new auth service surface. |
| apps/auth/services/types.py | Adds shared dataclasses (ServiceError, AuthIntent, etc.). |
| apps/auth/services/flows.py | Implements the main auth flows (initiate, verify callback, signup, reset, password login). |
| apps/auth/services/tokens.py | Extracts Redis + token/OTP generation/storage helpers. |
| apps/auth/services/questionnaire.py | Extracts questionnaire API integration and survey detail lookup. |
| apps/auth/services/captcha.py | Extracts Turnstile verification into a service module. |
| apps/auth/services/passwords.py | Extracts password strength scoring/validation. |
| apps/auth/services/users.py | Extracts user/session creation + Student integration. |
| apps/auth/init.py | Removes default_app_config entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+55
to
+59
| """Fetch the latest questionnaire answer for a given account from the WJ API(specific api for actions). | ||
| Returns a tuple of (filtered_data, error_response). | ||
| `filtered_data` contains: id, submitted_at, user.account, and otp. | ||
| `error_response` is a DRF Response object if an error occurs, otherwise None. | ||
| """ |
Comment on lines
+20
to
+24
| """Helper function includes session management, user creation and Student model integration. | ||
| Returns a tuple of (user, error_response). | ||
| `user` is the user object on success, otherwise None. | ||
| `error_response` is a DRF Response object if an error occurs, otherwise None. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split the auth workflow into services