Improvement Request for registration/serializers.py#672
Open
ADRIDEV2024 wants to merge 8 commits into
Open
Conversation
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.
Hi, I´m Adrian and I work as backend developer mostly with Python and frameworks like Django. I write this PR because I´ve been navigating this repo and looks great how is going forward, so I thought it would be worthwhile to contribute and support this project. Recently forked this repo and found some problems or inconsistencies inside the serializers file code ( registration folder ). I don´t pretend that all the changes I am going to suggest will be integrated into this project, but I would like at least a part of them to be taken into consideration.
PROBLEM:
PROPOSED CHANGES:
get_request function improvements:
Password validation logic:
Perhaps it will be better if password validation process is located in another place as separate logic that belongs to a new file named as password_valdations.py ( inside the registration folder). I removed the previous functions and made a complete file with only one responsability: password validations. All validation rules in that file can be customized through the constructor and it´s easy to add or modify them.
Validate function:
The validate() function was long and performed multiple tasks (validation, obtaining tokens, etc.).
The function can be split into this sub-methods:
_handle_code_flow(): Logic to handle the authorization flow by code.
_attempt_login(): Logic to attempt to login with social authentication.
_handle_new_user_registration(): Logic to register user if user does not exist.
Benefits:
Modularization: break logic into small, easy to understand tasks.
Reusability: Methods can be reused or tested separately.
Readability: The validate function is more readable and easier to follow.