stages/user_login: Allow changing of session duration
This commit is contained in:
parent
b26882a450
commit
e5165abf04
|
@ -14,6 +14,7 @@ class UserLoginStageSerializer(ModelSerializer):
|
||||||
fields = [
|
fields = [
|
||||||
"pk",
|
"pk",
|
||||||
"name",
|
"name",
|
||||||
|
"session_duration",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ class UserLoginStageForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
||||||
model = UserLoginStage
|
model = UserLoginStage
|
||||||
fields = ["name"]
|
fields = ["name", "session_duration"]
|
||||||
widgets = {
|
widgets = {
|
||||||
"name": forms.TextInput(),
|
"name": forms.TextInput(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# Generated by Django 3.0.7 on 2020-07-04 13:05
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("passbook_stages_user_login", "0001_initial"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="userloginstage",
|
||||||
|
name="session_duration",
|
||||||
|
field=models.PositiveIntegerField(
|
||||||
|
default=0,
|
||||||
|
help_text="Determines how long a session lasts, in seconds. Default of 0 means that the sessions lasts until the browser is closed.",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,4 +1,5 @@
|
||||||
"""login stage models"""
|
"""login stage models"""
|
||||||
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from passbook.flows.models import Stage
|
from passbook.flows.models import Stage
|
||||||
|
@ -7,6 +8,14 @@ from passbook.flows.models import Stage
|
||||||
class UserLoginStage(Stage):
|
class UserLoginStage(Stage):
|
||||||
"""Attaches the currently pending user to the current session."""
|
"""Attaches the currently pending user to the current session."""
|
||||||
|
|
||||||
|
session_duration = models.PositiveIntegerField(
|
||||||
|
default=0,
|
||||||
|
help_text=_(
|
||||||
|
"Determines how long a session lasts, in seconds. Default of 0 means"
|
||||||
|
" that the sessions lasts until the browser is closed."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
type = "passbook.stages.user_login.stage.UserLoginStageView"
|
type = "passbook.stages.user_login.stage.UserLoginStageView"
|
||||||
form = "passbook.stages.user_login.forms.UserLoginStageForm"
|
form = "passbook.stages.user_login.forms.UserLoginStageForm"
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,11 @@ class UserLoginStageView(StageView):
|
||||||
self.executor.plan.context[PLAN_CONTEXT_PENDING_USER],
|
self.executor.plan.context[PLAN_CONTEXT_PENDING_USER],
|
||||||
backend=backend,
|
backend=backend,
|
||||||
)
|
)
|
||||||
|
self.request.session.set_expiry(self.executor.current_stage.session_duration)
|
||||||
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],
|
||||||
flow_slug=self.executor.flow.slug,
|
flow_slug=self.executor.flow.slug,
|
||||||
|
session_duration=self.executor.current_stage.session_duration,
|
||||||
)
|
)
|
||||||
return self.executor.stage_ok()
|
return self.executor.stage_ok()
|
||||||
|
|
|
@ -99,5 +99,5 @@ class TestUserLoginStage(TestCase):
|
||||||
|
|
||||||
def test_form(self):
|
def test_form(self):
|
||||||
"""Test Form"""
|
"""Test Form"""
|
||||||
data = {"name": "test"}
|
data = {"name": "test", "session_duration": 0}
|
||||||
self.assertEqual(UserLoginStageForm(data).is_valid(), True)
|
self.assertEqual(UserLoginStageForm(data).is_valid(), True)
|
||||||
|
|
|
@ -6925,6 +6925,13 @@ definitions:
|
||||||
title: Name
|
title: Name
|
||||||
type: string
|
type: string
|
||||||
minLength: 1
|
minLength: 1
|
||||||
|
session_duration:
|
||||||
|
title: Session duration
|
||||||
|
description: Determines how long a session lasts, in seconds. Default of 0
|
||||||
|
means that the sessions lasts until the browser is closed.
|
||||||
|
type: integer
|
||||||
|
maximum: 2147483647
|
||||||
|
minimum: 0
|
||||||
UserLogoutStage:
|
UserLogoutStage:
|
||||||
required:
|
required:
|
||||||
- name
|
- name
|
||||||
|
|
Reference in New Issue