From 966d03edbdb783fb821ede59c72ff0fafc0daa8a Mon Sep 17 00:00:00 2001 From: Chneemann Date: Tue, 6 Aug 2024 18:35:01 +0200 Subject: [PATCH] password change via email & token possible --- backend/videoflix/auth/views.py | 5 +++- backend/videoflix/videoflix/urls.py | 3 ++- .../forgot-password.component.html | 5 ++++ .../forgot-password.component.ts | 25 ++++++++++++++++--- frontend/src/app/services/auth.service.ts | 6 +++++ 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/backend/videoflix/auth/views.py b/backend/videoflix/auth/views.py index 512f73e..78a448d 100644 --- a/backend/videoflix/auth/views.py +++ b/backend/videoflix/auth/views.py @@ -27,7 +27,7 @@ class LoginView(APIView): if not user.is_active: return Response({'password': 'Account is inactive, please check your mails'}, status=status.HTTP_403_FORBIDDEN) return self._create_token_response(user) - return Response({'detail': 'Unable to login with provided credentials.'}, status=status.HTTP_401_UNAUTHORIZED) + return Response({'mail': 'Unable to login with provided credentials.'}, status=status.HTTP_401_UNAUTHORIZED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) @@ -125,12 +125,15 @@ class ChangePasswordView(APIView): def post(self, request): email = request.data.get('email') token = request.data.get('token') + new_password = request.data.get('new_password') if not email or not token: return Response({"error": "Email and token are required."}, status=status.HTTP_400_BAD_REQUEST) user = CustomUser.objects.filter(Q(email=email) & Q(verify_email_token=token)).first() if user: + user.set_password(new_password) + user.save() return Response(status=status.HTTP_200_OK) else: return Response({"error": "Invalid email or token."}, status=status.HTTP_400_BAD_REQUEST) diff --git a/backend/videoflix/videoflix/urls.py b/backend/videoflix/videoflix/urls.py index 0d23654..ba52fa5 100644 --- a/backend/videoflix/videoflix/urls.py +++ b/backend/videoflix/videoflix/urls.py @@ -17,7 +17,7 @@ Including another URLconf from django.contrib import admin from django.urls import path, include from users import views -from auth.views import LoginView, RegisterView, VerifyEmailView, AuthView, ForgotPasswordView +from auth.views import LoginView, RegisterView, VerifyEmailView, AuthView, ForgotPasswordView,ChangePasswordView urlpatterns = [ path('admin/', admin.site.urls), @@ -28,5 +28,6 @@ urlpatterns = [ path('auth/register/', RegisterView.as_view()), path('auth/verify-email/', VerifyEmailView.as_view()), path('auth/forgot-password/', ForgotPasswordView.as_view()), + path('auth/change-password/', ChangePasswordView.as_view()), ] diff --git a/frontend/src/app/components/auth/forgot-password/forgot-password.component.html b/frontend/src/app/components/auth/forgot-password/forgot-password.component.html index 9f4cd72..0d2d0e1 100644 --- a/frontend/src/app/components/auth/forgot-password/forgot-password.component.html +++ b/frontend/src/app/components/auth/forgot-password/forgot-password.component.html @@ -110,6 +110,11 @@ passwordConfirm.touched) {

The passwords do not match

} +
+
+

{{ errors["error"] }}

+
+