{"action":"created","issue":{"url":"https://api.github.com/repos/sunscrapers/djoser/issues/94","labels_url":"https://api.github.com/repos/sunscrapers/djoser/issues/94/labels{/name}","comments_url":"https://api.github.com/repos/sunscrapers/djoser/issues/94/comments","events_url":"https://api.github.com/repos/sunscrapers/djoser/issues/94/events","html_url":"https://github.com/sunscrapers/djoser/issues/94","id":116210643,"number":94,"title":"get_users in PasswordResetView","user":{"login":"apokinsocha","id":11322329,"avatar_url":"https://avatars.githubusercontent.com/u/11322329?v=3","gravatar_id":"","url":"https://api.github.com/users/apokinsocha","html_url":"https://github.com/apokinsocha","followers_url":"https://api.github.com/users/apokinsocha/followers","following_url":"https://api.github.com/users/apokinsocha/following{/other_user}","gists_url":"https://api.github.com/users/apokinsocha/gists{/gist_id}","starred_url":"https://api.github.com/users/apokinsocha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apokinsocha/subscriptions","organizations_url":"https://api.github.com/users/apokinsocha/orgs","repos_url":"https://api.github.com/users/apokinsocha/repos","events_url":"https://api.github.com/users/apokinsocha/events{/privacy}","received_events_url":"https://api.github.com/users/apokinsocha/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sunscrapers/djoser/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-10T21:54:35Z","updated_at":"2015-11-14T15:54:51Z","closed_at":null,"body":"This is not really an issue but small improvement, I'm not sure what the reasoning is behind using \"get_users\" (plural) instead of \"get_user\" (singular)?\r\nThis assumes that multiple users can have the same e-mail address.\r\nI'm not sure if that would be a typical use case, I don't think it is.\r\nAnother case is if there is a custom User model that uses the e-mail address instead of the username, and the e-mail address must be unique.\r\nI think in both situations, default should be assumed one user can have one e-mail address.\r\nThis is in reference to the code for \"PasswordResetView\":\r\n\r\n```python\r\n    def action(self, serializer):\r\n        for user in self.get_users(serializer.data['email']):\r\n            self.send_email(**self.get_send_email_kwargs(user))\r\n        return response.Response(status=status.HTTP_200_OK)\r\n\r\n    def get_users(self, email):\r\n        active_users = User._default_manager.filter(\r\n            email__iexact=email,\r\n            is_active=True,\r\n        )\r\n        return (u for u in active_users if u.has_usable_password())\r\n```\r\n\r\na change to just:\r\n\r\n```python\r\n    def action(self, serializer):\r\n        users = User.objects.filter(email__iexact=serializer.data['email'], is_active=True)#or get()\r\n        if users.exists():\r\n            user = users.first()\r\n            if user.has_usable_password():\r\n                self.send_email(**self.get_send_email_kwargs(user))\r\n        return response.Response(status=status.HTTP_200_OK)\r\n```\r\n\r\nor set \"user\" on the serializer after validating e-mail and statuses is_active and has_usable_password()\r\n\r\n```python\r\n    def action(self, serializer):\r\n        self.send_email(**self.get_send_email_kwargs(serializer.user))\r\n        return response.Response(status=status.HTTP_200_OK)\r\n```"},"comment":{"url":"https://api.github.com/repos/sunscrapers/djoser/issues/comments/156713727","html_url":"https://github.com/sunscrapers/djoser/issues/94#issuecomment-156713727","issue_url":"https://api.github.com/repos/sunscrapers/djoser/issues/94","id":156713727,"user":{"login":"konradhalas","id":101077,"avatar_url":"https://avatars.githubusercontent.com/u/101077?v=3","gravatar_id":"","url":"https://api.github.com/users/konradhalas","html_url":"https://github.com/konradhalas","followers_url":"https://api.github.com/users/konradhalas/followers","following_url":"https://api.github.com/users/konradhalas/following{/other_user}","gists_url":"https://api.github.com/users/konradhalas/gists{/gist_id}","starred_url":"https://api.github.com/users/konradhalas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/konradhalas/subscriptions","organizations_url":"https://api.github.com/users/konradhalas/orgs","repos_url":"https://api.github.com/users/konradhalas/repos","events_url":"https://api.github.com/users/konradhalas/events{/privacy}","received_events_url":"https://api.github.com/users/konradhalas/received_events","type":"User","site_admin":false},"created_at":"2015-11-14T15:54:51Z","updated_at":"2015-11-14T15:54:51Z","body":"Hi @apokinsocha, thank you for your question.\r\n\r\nThis \"architecture\" is copy-pasted from original `django.contrib.auth.forms.PasswordResetForm`, it looks like this:\r\n\r\n```python\r\nclass PasswordResetForm(...):\r\n\r\n  def get_users(self, email):\r\n      \"\"\"Given an email, return matching user(s) who should receive a reset.\r\n\r\n      This allows subclasses to more easily customize the default policies\r\n      that prevent inactive users and users with unusable passwords from\r\n      resetting their password.\r\n      \"\"\"\r\n      active_users = get_user_model()._default_manager.filter(\r\n          email__iexact=email, is_active=True)\r\n      return (u for u in active_users if u.has_usable_password())\r\n\r\n  def save(self, ...):\r\n      \"\"\"\r\n      Generates a one-use only link for resetting password and sends to the\r\n      user.\r\n      \"\"\"\r\n      email = self.cleaned_data[\"email\"]\r\n      for user in self.get_users(email):\r\n          (...)\r\n```\r\n\r\nTBH, I also don't know why they are returning generator instead of single user. Does \"easily customize\" (from docstring) refers to existence of `get_users` method or is it excuse for returning generator? Is it easier to filter collection instead of extend simple if statement? I don't know. But this is what we found in Django and we are trying to handle this in a similar way.\r\n\r\nDo you think this is a good reason to leave it as it is or should we simplify it? Let me know. \r\n"}}