Start conversion for Django 2.0; change to auth for compatibility

This commit is contained in:
Griatch 2019-03-25 08:48:32 +01:00
parent fbfae59138
commit f9354d9aeb
3 changed files with 11 additions and 18 deletions

View file

@ -595,29 +595,18 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
return valid, error
def set_password(self, password, force=False):
def set_password(self, password, **kwargs):
"""
Applies the given password to the account if it passes validation checks.
Can be overridden by using the 'force' flag.
Applies the given password to the account. Logs and triggers the `at_password_change` hook.
Args:
password (str): Password to set
password (str): Password to set.
Kwargs:
force (bool): Sets password without running validation checks.
Raises:
ValidationError
Returns:
None (None): Does not return a value.
Notes:
This is called by Django also when logging in; it should not be mixed up with validation, since that
would mean old passwords in the database (pre validation checks) could get invalidated.
"""
if not force:
# Run validation checks
valid, error = self.validate_password(password, account=self)
if error: raise error
super(DefaultAccount, self).set_password(password)
logger.log_sec("Password successfully changed for %s." % self)
self.at_password_change()

View file

@ -92,7 +92,7 @@ SRESET = chr(19) # shutdown server in reset mode
PYTHON_MIN = '3.7'
TWISTED_MIN = '18.0.0'
DJANGO_MIN = '1.11'
DJANGO_REC = '1.11'
DJANGO_REC = '2.0'
try:
sys.path[1] = EVENNIA_ROOT

View file

@ -469,6 +469,10 @@ def create_account(key, email, password,
new_account = typeclass(username=key, email=email,
is_staff=is_superuser, is_superuser=is_superuser,
last_login=now, date_joined=now)
valid, error = new_account.validate_password(password, new_account)
if not valid:
raise error
new_account.set_password(password)
new_account._createdict = dict(locks=locks, permissions=permissions, report_to=report_to,
tags=tags, attributes=attributes)