recovery: handle error when user doesn't exist

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-10-05 10:40:59 +02:00
parent 8da00585e3
commit a515afae0b

View file

@ -37,7 +37,11 @@ class Command(BaseCommand):
duration = int(options.get("duration", 1))
_now = now()
expiry = _now + timedelta(days=duration * 365.2425)
user = User.objects.get(username=options.get("user"))
users = User.objects.filter(username=options.get("user"))
if not users.exists():
self.stderr.write(f"User '{options.get('user')}' not found.")
return
user = users.first()
token = Token.objects.create(
expires=expiry,
user=user,