PasswordResetView proposal to move the User.is_active check from database to Python
See original GitHub issueSomething like this:
class PasswordResetView(utils.ActionViewMixin, generics.GenericAPIView):
def get_users(self, email):
if self._users is None:
active_users = User._default_manager.filter(
email__iexact=email,
# is_active=True, <--- v0.6 code
)
# self._users = [u for u in active_users if u.has_usable_password()] <--- v0.6 code
self._users = [u for u in active_users if u.is_active and u.has_usable_password()]
return self._users
Here are the reasons:
- If
is_active
is not True, then this opportunity can be used to notify the user that they’ve already registered an account with that email address, and [offer to] resend the activation email.
_users = User._default_manager.filter(email=email)
self._users = []
for u in _users:
if u.has_usable_password():
if u.is_active:
self._users.append(u)
else:
# TODO resend activation email
- I think with the v0.6 code, there will be some conflict if
is_active
is implemented in a model like this:
class User(AbstractBaseUser):
score = models.SmallIntegerField(default=0)
status = models.SmallIntegerField(default=0)
email = models.CIEmailField(unique=True)
name = models.CITextField()
ip = models.ArrayField(models.GenericIPAddressField(unpack_ipv4=True))
objects = UserManager()
USERNAME_FIELD = 'email'
@property
def is_active(self):
# FIXME can't do this, djoser uses .filter(is_active=True)
return self.status > 0
@is_active.setter
def is_active(self, value):
if value is True:
self.status = abs(self.status or 1)
elif value is False:
self.status = -abs(self.status or 0)
else:
self.status = value
- Any concerns about performance/inefficiency of retrieving unnecessary rows from the database should be nominal in real-world usage because there wouldn’t be very many unactive accounts tied to a single email address in most cases. And again, if the activation email resend is implemented, then the retrieval of these rows wouldn’t be considered wasted.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Settings - Django documentation
Core Settings¶. Here's a list of settings available in Django core and their default values. Settings provided by contrib apps are listed below, ......
Read more >Can someone suggest how to implement custom Django ...
What is the official way to customize password reset view. So that user can search account by username or email for sending password...
Read more >Using Flask-Login for User Management with Flask
Flask-login is a Flask extension that enables user authentication. ... has an is_active() method that returns True if the user's account is active...
Read more >Quickstart: Use Python to query a database - Microsoft Learn
In this quickstart, you use Python to connect to Azure SQL Database, Azure SQL Managed Instance, or Synapse SQL database and use T-SQL ......
Read more >Using the Python Connector - Snowflake Documentation
conn = snowflake.connector.connect( user=USER, password=PASSWORD, account=ACCOUNT, warehouse=WAREHOUSE, database=DATABASE, schema=SCHEMA ).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same here, in case of any doubts do not hesitate to start a new issue and again - thank you for reporting and working on the issue.
Yes, this can be closed. Thank you for the great feedback, it’s been a pleasure 😃