:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(auth): flip is_email_verified when password reset completes (#58822)
Matt Brooker60be153aecd4
diff --git a/posthog/api/authentication.py b/posthog/api/authentication.pyindex 2fef8161c3aa..2ceff5a0db6f 100644--- a/posthog/api/authentication.py+++ b/posthog/api/authentication.py@@ -985,6 +985,11 @@ class PasswordResetCompleteSerializer(serializers.Serializer):user.set_password(password)user.requested_password_reset_at = None+ # Possessing the unique reset token (only ever delivered by email via+ # send_password_reset) proves the user owns this address, regardless of+ # whether they came in as None (legacy / agentic-provisioned), False+ # (invite-accept, Vercel-provisioned), or True.+ user.is_email_verified = Trueuser.save()report_user_password_reset(user)diff --git a/posthog/api/test/test_authentication.py b/posthog/api/test/test_authentication.pyindex 79730693c101..d653d97d7e07 100644--- a/posthog/api/test/test_authentication.py+++ b/posthog/api/test/test_authentication.py@@ -1584,6 +1584,44 @@ class TestPasswordResetAPI(APIBaseTest):},)+ @parameterized.expand(+ [+ ("none_becomes_true", None),+ ("true_stays_true", True),+ ("false_becomes_true", False),+ ]+ )+ def test_password_reset_flips_is_email_verified_to_true(self, _name, initial_state):+ self.user.is_email_verified = initial_state+ self.user.requested_password_reset_at = datetime.now()+ self.user.save()++ token = password_reset_token_generator.make_token(self.user)+ response = self.client.post(+ f"/api/reset/{self.user.uuid}/",+ {"token": token, "password": VALID_TEST_PASSWORD},+ )+ self.assertEqual(response.status_code, status.HTTP_200_OK)++ self.user.refresh_from_db()+ self.assertEqual(self.user.is_email_verified, True)++ def test_password_reset_does_not_clear_pending_email(self):+ self.user.is_email_verified = False+ self.user.pending_email = "[email protected]"+ self.user.requested_password_reset_at = datetime.now()+ self.user.save()++ token = password_reset_token_generator.make_token(self.user)+ response = self.client.post(+ f"/api/reset/{self.user.uuid}/",+ {"token": token, "password": VALID_TEST_PASSWORD},+ )+ self.assertEqual(response.status_code, status.HTTP_200_OK)++ self.user.refresh_from_db()+ self.assertEqual(self.user.pending_email, "[email protected]")+@patch("posthog.tasks.email.send_password_changed_email.delay")def test_password_change_invalidates_reset_token(self, mock_send_email):token = password_reset_token_generator.make_token(self.user)