diff --git a/atst/forms/edit_user.py b/atst/forms/edit_user.py new file mode 100644 index 00000000..0bf8f211 --- /dev/null +++ b/atst/forms/edit_user.py @@ -0,0 +1,70 @@ +import pendulum +from wtforms.fields.html5 import DateField, EmailField, TelField +from wtforms.fields import RadioField, StringField +from wtforms.validators import Email, Required + +from .fields import SelectField +from .forms import ValidatedForm +from .data import SERVICE_BRANCHES + +from .validators import Alphabet, DateRange, PhoneNumber + + +class EditUserForm(ValidatedForm): + + first_name = StringField("First Name", validators=[Required(), Alphabet()]) + + last_name = StringField("Last Name", validators=[Required(), Alphabet()]) + + email = EmailField( + "E-mail Address", + description="Enter your preferred contact e-mail address", + validators=[Required(), Email()], + ) + + phone_number = TelField( + "Phone Number", + description="Enter your 10-digit U.S. phone number", + validators=[Required(), PhoneNumber()], + ) + + service_branch = SelectField( + "Service Branch or Agency", + description="Which service or organization do you belong to within the DoD?", + choices=SERVICE_BRANCHES, + ) + + citizenship = RadioField( + description="What is your citizenship status?", + choices=[ + ("United States", "United States"), + ("Foreign National", "Foreign National"), + ("Other", "Other"), + ], + validators=[Required()], + ) + + designation = RadioField( + "Designation of Person", + description="What is your designation within the DoD?", + choices=[ + ("military", "Military"), + ("civilian", "Civilian"), + ("contractor", "Contractor"), + ], + validators=[Required()], + ) + + date_latest_training = DateField( + "Latest Information Assurance (IA) Training Completion Date", + description='To complete the training, you can find it in Information Assurance Cyber Awareness Challange website.', + validators=[ + Required(), + DateRange( + lower_bound=pendulum.duration(years=1), + upper_bound=pendulum.duration(days=0), + message="Must be a date within the last year.", + ), + ], + format="%m/%d/%Y", + ) diff --git a/atst/routes/__init__.py b/atst/routes/__init__.py index c2790196..4edbdb57 100644 --- a/atst/routes/__init__.py +++ b/atst/routes/__init__.py @@ -7,6 +7,7 @@ from atst.domain.users import Users from atst.domain.authnid import AuthenticationContext from atst.domain.audit_log import AuditLog from atst.domain.auth import logout as _logout +from atst.forms.edit_user import EditUserForm bp = Blueprint("atst", __name__) @@ -89,3 +90,16 @@ def logout(): def activity_history(): audit_events = AuditLog.get_all_events(g.current_user) return render_template("audit_log.html", audit_events=audit_events) + + +@bp.route("/user") +def user(): + form = EditUserForm(request.form) + user = g.current_user + return render_template("user/edit.html", form=form, user=user) + + +@bp.route("/save_user") +def save_user(): + # no op + return redirect(url_for(".home")) diff --git a/styles/components/_forms.scss b/styles/components/_forms.scss index db7ee296..5ebf01f4 100644 --- a/styles/components/_forms.scss +++ b/styles/components/_forms.scss @@ -16,6 +16,12 @@ margin-top: 0; } } + + .usa-input { + input { + max-width: none; + } + } } @include media($medium-screen) { @@ -46,10 +52,6 @@ right: -$gap * 3; } } - - input { - max-width: none; - } } &:first-child { diff --git a/templates/base_public.html b/templates/base_public.html index 2a5e9c32..9ceb400f 100644 --- a/templates/base_public.html +++ b/templates/base_public.html @@ -24,7 +24,7 @@ {% if g.current_user %} - + {{ g.current_user.first_name + " " + g.current_user.last_name }} {{ Icon('avatar', classes='topbar__link-icon') }} diff --git a/templates/fragments/edit_user_form.html b/templates/fragments/edit_user_form.html new file mode 100644 index 00000000..ed0ec406 --- /dev/null +++ b/templates/fragments/edit_user_form.html @@ -0,0 +1,38 @@ +{% from "components/text_input.html" import TextInput %} +{% from "components/options_input.html" import OptionsInput %} +{% from "components/date_input.html" import DateInput %} + +
+
+
+
+
+ {{ TextInput(form.first_name) }} +
+ +
+ {{ TextInput(form.last_name) }} +
+
+ +
+
+ {{ TextInput(form.email, validation='email') }} +
+ +
+ {{ TextInput(form.phone_number, validation='usPhone') }} +
+
+ + {{ OptionsInput(form.service_branch) }} + {{ OptionsInput(form.citizenship) }} + {{ OptionsInput(form.designation) }} + {{ DateInput(form.date_latest_training,tooltip="When was the last time you completed the IA training?
Information Assurance (IA) training is an important step in cyber awareness.",placeholder="MM / DD / YYYY", validation="date") }} +
+
+ +
+ +
+
diff --git a/templates/navigation/topbar.html b/templates/navigation/topbar.html index b5bd8e78..6bcd0d0a 100644 --- a/templates/navigation/topbar.html +++ b/templates/navigation/topbar.html @@ -20,7 +20,7 @@ {% endif %} - + {{ g.current_user.first_name + " " + g.current_user.last_name }} {{ Icon('avatar', classes='topbar__link-icon') }} diff --git a/templates/user/edit.html b/templates/user/edit.html new file mode 100644 index 00000000..44cbc71f --- /dev/null +++ b/templates/user/edit.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} +{% from "components/alert.html" import Alert %} + +{% block content %} +
+ {{ Alert('This form does not yet function', + message="

Functionality of this form is pending more engineering work. Engineers, please remove this alert when done.

", + level='warning' + ) }} + +
+
+

+
{{ user.first_name }} {{ user.last_name }}
+
Edit user details
+

+
+
+ + {% set form_action = url_for('atst.save_user') %} + {% include "fragments/edit_user_form.html" %} + +
+{% endblock %}