stages/user_login: replace usage of -1 with 0
This commit is contained in:
parent
caba183c9b
commit
f12fd78822
|
@ -14,9 +14,6 @@ def update_duration(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
|
||||||
|
|
||||||
for stage in UserLoginStage.objects.using(db_alias).all():
|
for stage in UserLoginStage.objects.using(db_alias).all():
|
||||||
if stage.session_duration.isdigit():
|
if stage.session_duration.isdigit():
|
||||||
if stage.session_duration == 0:
|
|
||||||
stage.session_duration = "seconds=1"
|
|
||||||
else:
|
|
||||||
stage.session_duration = f"seconds={stage.session_duration}"
|
stage.session_duration = f"seconds={stage.session_duration}"
|
||||||
stage.save()
|
stage.save()
|
||||||
|
|
||||||
|
@ -32,8 +29,8 @@ class Migration(migrations.Migration):
|
||||||
model_name="userloginstage",
|
model_name="userloginstage",
|
||||||
name="session_duration",
|
name="session_duration",
|
||||||
field=models.TextField(
|
field=models.TextField(
|
||||||
default="seconds=-1",
|
default="seconds=0",
|
||||||
help_text="Determines how long a session lasts. Default of -1 means that the sessions lasts until the browser is closed. (Format: hours=-1;minutes=-2;seconds=-3)",
|
help_text="Determines how long a session lasts. Default of 0 means that the sessions lasts until the browser is closed. (Format: hours=-1;minutes=-2;seconds=-3)",
|
||||||
validators=[passbook.lib.utils.time.timedelta_string_validator],
|
validators=[passbook.lib.utils.time.timedelta_string_validator],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -15,10 +15,10 @@ class UserLoginStage(Stage):
|
||||||
"""Attaches the currently pending user to the current session."""
|
"""Attaches the currently pending user to the current session."""
|
||||||
|
|
||||||
session_duration = models.TextField(
|
session_duration = models.TextField(
|
||||||
default="seconds=-1",
|
default="seconds=0",
|
||||||
validators=[timedelta_string_validator],
|
validators=[timedelta_string_validator],
|
||||||
help_text=_(
|
help_text=_(
|
||||||
"Determines how long a session lasts. Default of -1 means "
|
"Determines how long a session lasts. Default of 0 means "
|
||||||
"that the sessions lasts until the browser is closed. "
|
"that the sessions lasts until the browser is closed. "
|
||||||
"(Format: hours=-1;minutes=-2;seconds=-3)"
|
"(Format: hours=-1;minutes=-2;seconds=-3)"
|
||||||
),
|
),
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import login
|
from django.contrib.auth import login
|
||||||
from django.http import HttpRequest, HttpResponse
|
from django.http import HttpRequest, HttpResponse
|
||||||
from django.utils.timezone import now
|
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from structlog import get_logger
|
from structlog import get_logger
|
||||||
|
|
||||||
|
@ -35,11 +34,10 @@ class UserLoginStageView(StageView):
|
||||||
backend=backend,
|
backend=backend,
|
||||||
)
|
)
|
||||||
delta = timedelta_from_string(self.executor.current_stage.session_duration)
|
delta = timedelta_from_string(self.executor.current_stage.session_duration)
|
||||||
if delta.seconds == -1:
|
if delta.seconds == 0:
|
||||||
self.request.session.set_expiry(0)
|
self.request.session.set_expiry(0)
|
||||||
else:
|
else:
|
||||||
expiry = now() + delta
|
self.request.session.set_expiry(delta)
|
||||||
self.request.session.set_expiry(expiry)
|
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"Logged in",
|
"Logged in",
|
||||||
user=self.executor.plan.context[PLAN_CONTEXT_PENDING_USER],
|
user=self.executor.plan.context[PLAN_CONTEXT_PENDING_USER],
|
||||||
|
|
Reference in New Issue