|
| 1 | +import secrets |
| 2 | +import string |
| 3 | + |
1 | 4 | from admin_api.serializers.user import ( |
2 | 5 | OrganizationAdminSerializer, |
3 | 6 | UserAdminPasswordChangeSerializer, |
| 7 | + UserAdminPasswordResetResponseSerializer, |
4 | 8 | UserAdminSerializer, |
5 | 9 | UserAdminSignInSerializer, |
6 | 10 | ) |
7 | | -from core.const.account import INITIAL_ADMIN_PASSWORD |
8 | 11 | from core.const.tag import OpenAPITag |
9 | 12 | from core.permissions import IsSuperUser |
10 | 13 | from core.viewset.json_schema_viewset import JsonSchemaViewSet |
@@ -58,13 +61,22 @@ def signout(self, request: request.Request, *args: tuple, **kwargs: dict) -> res |
58 | 61 | logout(request=request) |
59 | 62 | return response.Response(status=status.HTTP_204_NO_CONTENT) |
60 | 63 |
|
61 | | - @extend_schema(tags=[OpenAPITag.ADMIN_USER], responses={status.HTTP_204_NO_CONTENT: None}) |
| 64 | + @extend_schema( |
| 65 | + tags=[OpenAPITag.ADMIN_USER], |
| 66 | + responses={status.HTTP_200_OK: UserAdminPasswordResetResponseSerializer}, |
| 67 | + ) |
62 | 68 | @decorators.action(detail=True, methods=["DELETE"], url_path="password") |
63 | 69 | def reset_password(self, *args: tuple, **kwargs: dict) -> response.Response: |
| 70 | + alphabet = string.ascii_letters + string.digits + string.punctuation |
| 71 | + new_password = "".join(secrets.choice(alphabet) for _ in range(16)) |
| 72 | + |
64 | 73 | user: UserExt = self.get_object() |
65 | | - user.set_password(INITIAL_ADMIN_PASSWORD) |
| 74 | + user.set_password(new_password) |
66 | 75 | user.save(update_fields=["password"]) |
67 | | - return response.Response(status=status.HTTP_204_NO_CONTENT) |
| 76 | + return response.Response( |
| 77 | + data={"password": new_password}, |
| 78 | + status=status.HTTP_200_OK, |
| 79 | + ) |
68 | 80 |
|
69 | 81 | @extend_schema( |
70 | 82 | tags=[OpenAPITag.ADMIN_ACCOUNT], |
|
0 commit comments