-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Login and add graphic captcha #3117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ | |
| from users.serializers.user_serializers import RegisterSerializer, LoginSerializer, CheckCodeSerializer, \ | ||
| RePasswordSerializer, \ | ||
| SendEmailSerializer, UserProfile, UserSerializer, UserManageSerializer, UserInstanceSerializer, SystemSerializer, \ | ||
| SwitchLanguageSerializer | ||
| SwitchLanguageSerializer, CaptchaSerializer | ||
| from users.views.common import get_user_operation_object, get_re_password_details | ||
|
|
||
| user_cache = cache.caches['user_cache'] | ||
|
|
@@ -170,6 +170,18 @@ def _get_details(request): | |
| } | ||
|
|
||
|
|
||
| class CaptchaView(APIView): | ||
|
|
||
| @action(methods=['GET'], detail=False) | ||
| @swagger_auto_schema(operation_summary=_("Obtain graphical captcha"), | ||
| operation_id=_("Obtain graphical captcha"), | ||
| responses=CaptchaSerializer().get_response_body_api(), | ||
| security=[], | ||
| tags=[_("User management")]) | ||
| def get(self, request: Request): | ||
| return result.success(CaptchaSerializer().generate()) | ||
|
|
||
|
|
||
| class Login(APIView): | ||
|
|
||
| @action(methods=['POST'], detail=False) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet contains several improvements and corrections: Improvements
Corrections
Here is the corrected version of the code: from users.serializers.user_serializers import RegisterSerializer, LoginSerializer, CheckCodeSerializer, \
RePasswordSerializer, \
SendEmailSerializer, UserProfile, UserSerializer, UserManageSerializer, UserInstanceSerializer, SystemSerializer, \
SwitchLanguageSerializer, CaptchaSerializer
from users.views.common import get_user_operation_object, get_re_password_details
user_cache = cache.caches['user_cache']
def _get_details(request):
return {
'register': RegisterSerializer().get_response_body_api_detail(),
'login': LoginSerializer().get_response_body_api_detail(),
# ... (other fields)
}
class CaptchaView(APIView):
@action(methods=['GET'], detail=False)
@swagger_auto_schema(operation_summary=_("Obtain graphical captcha"),
operation_id=_("Obtain graphical captcha"),
responses=CaptchaSerializer().get_response_body_api(),
security=[],
tags=[_("User management")])
def get(self, request: Request):
return Result.success(CaptchaSerializer().generate())
class Login(APIView):
@action(methods=['POST'], detail=False)Optimization Suggestions
These changes ensure that the code is syntactically correct, removes redundancies, fixes import errors, and makes it more robust. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code has several improvements and optimizations:
Imports:
ImageCaptchadirectly within the module to use its methods without needing it at the top level.Code Structure:
CaptchaSerializer.Validation:
Cache Management:
"LOGIN:" + <captcha>).Serialization Enhancements:
Here's the revised code snippet with these enhancements:
Note: Ensure that you replace placeholders like
YourModel,AppApiException, etc., with appropriate Django model classes and exceptions as per your application structure.