Repository: Cloud-CV/EvalAI

Issue:
Fix reset password message for inactive users
Users who are inactive get "Resent Password Link Sent to Email" message but do not receive emails.
We should not send them emails but at the same time show appropriate message here.
![Screenshot 2023-04-28 at 2 42 43 PM](https://user-images.githubusercontent.com/29076344/235228078-64ff6a54-af62-41a3-b65e-d6f3023aefbf.png)



Discussion:

Resolving patch:
diff --git a/apps/accounts/serializers.py b/apps/accounts/serializers.py
--- a/apps/accounts/serializers.py
+++ b/apps/accounts/serializers.py
@@ -1,5 +1,6 @@
 from django.contrib.auth import get_user_model
-
+from rest_auth.serializers import PasswordResetSerializer
+from rest_framework.exceptions import ValidationError
 from .models import JwtToken, Profile
 from rest_framework import serializers
 
@@ -99,3 +100,18 @@ class Meta:
             "refresh_token",
             "access_token",
         )
+
+
+class CustomPasswordResetSerializer(PasswordResetSerializer):
+    """
+    Serializer to check Account Active Status.
+    """
+    def get_email_options(self):
+        try:
+            user = get_user_model().objects.get(email=self.data['email'])
+            if not user.is_active:
+                raise ValidationError({'details': "Account is not active. Please contact the administrator."})
+            else:
+                return super().get_email_options()
+        except get_user_model().DoesNotExist:
+            raise ValidationError({'details': "User with the given email does not exist."})
diff --git a/settings/common.py b/settings/common.py
--- a/settings/common.py
+++ b/settings/common.py
@@ -291,7 +291,8 @@
 
 # To make usermame field read-only, customized serializer is defined.
 REST_AUTH_SERIALIZERS = {
-    "USER_DETAILS_SERIALIZER": "accounts.serializers.ProfileSerializer"
+    "USER_DETAILS_SERIALIZER": "accounts.serializers.ProfileSerializer",
+    "PASSWORD_RESET_SERIALIZER": "accounts.serializers.CustomPasswordResetSerializer"
 }
 
 # For inviting users to participant and host teams.


Test patch:
diff --git a/frontend/tests/controllers-test/authCtrl.test.js b/frontend/tests/controllers-test/authCtrl.test.js
--- a/frontend/tests/controllers-test/authCtrl.test.js
+++ b/frontend/tests/controllers-test/authCtrl.test.js
@@ -310,7 +310,7 @@ describe('Unit tests for auth controller', function () {
 
     describe('Unit tests for resetPassword function `auth/password/reset/`', function () {
         var success;
-
+        var inactiveResponse = 'Account is not active. Please contact the administrator.';
         var mailSent = 'mail sent';
 
         beforeEach(function () {
@@ -322,7 +322,7 @@ describe('Unit tests for auth controller', function () {
                         }
                     });
                 } else {
-                    parameters.callback.onError();
+                    parameters.callback.onError({status: 400, data: {details: inactiveResponse}});
                 }
             };
         });
@@ -338,6 +338,7 @@ describe('Unit tests for auth controller', function () {
             success = false;
             vm.resetPassword(true);
             expect(vm.isFormError).toEqual(true);
+            expect(vm.FormError).toEqual(inactiveResponse);
         });
 
         it('invalid details', function () {