stages/prompt: Add username type field

add autocomplete attributes for username and password
This commit is contained in:
Jens Langhammer 2020-06-15 19:05:18 +02:00
parent b49d39a685
commit feba3e2430
4 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,28 @@
# Generated by Django 3.0.7 on 2020-06-15 16:41
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("passbook_flows", "0005_provider_flows"),
("passbook_stages_identification", "0002_auto_20200530_2204"),
]
operations = [
migrations.AlterField(
model_name="identificationstage",
name="recovery_flow",
field=models.ForeignKey(
blank=True,
default=None,
help_text="Optional recovery flow, which is linked at the bottom of the page.",
null=True,
on_delete=django.db.models.deletion.SET_DEFAULT,
related_name="+",
to="passbook_flows.Flow",
),
),
]

View File

@ -0,0 +1,33 @@
# Generated by Django 3.0.7 on 2020-06-15 16:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("passbook_stages_prompt", "0002_auto_20200528_2059"),
]
operations = [
migrations.AlterField(
model_name="prompt",
name="type",
field=models.CharField(
choices=[
("text", "Text"),
("username", "Username"),
("e-mail", "Email"),
("password", "Password"),
("number", "Number"),
("checkbox", "Checkbox"),
("data", "Date"),
("data-time", "Date Time"),
("separator", "Separator"),
("hidden", "Hidden"),
("static", "Static"),
],
max_length=100,
),
),
]

View File

@ -12,7 +12,10 @@ from passbook.policies.models import PolicyBindingModel
class FieldTypes(models.TextChoices):
"""Field types an Prompt can be"""
# Simple text field
TEXT = "text"
# Same as text, but has autocomplete for password managers
USERNAME = "username"
EMAIL = "e-mail"
PASSWORD = "password" # noqa # nosec
NUMBER = "number"
@ -52,8 +55,11 @@ class Prompt(models.Model):
}
if self.type == FieldTypes.EMAIL:
field_class = forms.EmailField
if self.type == FieldTypes.USERNAME:
attrs["autocomplete"] = "username"
if self.type == FieldTypes.PASSWORD:
widget = forms.PasswordInput(attrs=attrs)
attrs["autocomplete"] = "new-password"
if self.type == FieldTypes.NUMBER:
field_class = forms.IntegerField
widget = forms.NumberInput(attrs=attrs)
@ -64,6 +70,10 @@ class Prompt(models.Model):
if self.type == FieldTypes.CHECKBOX:
field_class = forms.CheckboxInput
kwargs["required"] = False
if self.type == FieldTypes.DATE:
field_class = forms.DateInput
if self.type == FieldTypes.DATE_TIME:
field_class = forms.DateTimeInput
# TODO: Implement static
# TODO: Implement separator

View File

@ -6079,6 +6079,7 @@ definitions:
type: string
enum:
- text
- username
- e-mail
- password
- number