core: add key field to token for easier rotation
This commit is contained in:
@ -9,7 +9,6 @@ from django.utils.translation import gettext as _
|
||||
from structlog import get_logger
|
||||
|
||||
from passbook.core.models import Token, TokenIntents, User
|
||||
from passbook.lib.config import CONFIG
|
||||
|
||||
LOGGER = get_logger()
|
||||
|
||||
@ -32,22 +31,17 @@ class Command(BaseCommand):
|
||||
|
||||
def get_url(self, token: Token) -> str:
|
||||
"""Get full recovery link"""
|
||||
path = reverse(
|
||||
"passbook_recovery:use-token", kwargs={"uuid": str(token.token_uuid)}
|
||||
)
|
||||
return f"https://{CONFIG.y('domain')}{path}"
|
||||
return reverse("passbook_recovery:use-token", kwargs={"key": str(token.key)})
|
||||
|
||||
def handle(self, *args, **options):
|
||||
"""Create Token used to recover access"""
|
||||
duration = int(options.get("duration", 1))
|
||||
delta = timedelta(days=duration * 365.2425)
|
||||
_now = now()
|
||||
expiry = _now + delta
|
||||
expiry = _now + timedelta(days=duration * 365.2425)
|
||||
user = User.objects.get(username=options.get("user"))
|
||||
token = Token.objects.create(
|
||||
expires=expiry,
|
||||
user=user,
|
||||
identifier="recovery",
|
||||
intent=TokenIntents.INTENT_RECOVERY,
|
||||
description=f"Recovery Token generated by {getuser()} on {_now}",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user