From f9354d9aebf3a200c4d959bd53878b52bb3e5965 Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 25 Mar 2019 08:48:32 +0100 Subject: [PATCH] Start conversion for Django 2.0; change to auth for compatibility --- evennia/accounts/accounts.py | 23 ++++++----------------- evennia/server/evennia_launcher.py | 2 +- evennia/utils/create.py | 4 ++++ 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index d6d1e43f13..f1cee5321e 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -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() diff --git a/evennia/server/evennia_launcher.py b/evennia/server/evennia_launcher.py index a6c995c7ed..4e71803ca9 100644 --- a/evennia/server/evennia_launcher.py +++ b/evennia/server/evennia_launcher.py @@ -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 diff --git a/evennia/utils/create.py b/evennia/utils/create.py index d3a22be866..7403f1a8f3 100644 --- a/evennia/utils/create.py +++ b/evennia/utils/create.py @@ -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)