diff --git a/app/main/forms.py b/app/main/forms.py index 70dbfa37f..eb898142f 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -605,6 +605,14 @@ class RegisterUserForm(StripWhitespaceForm): auth_type = HiddenField("auth_type", default="sms_auth") +class SetupUserProfileForm(StripWhitespaceForm): + name = GovukTextInputField( + "Full name", validators=[DataRequired(message="Cannot be empty")] + ) + mobile_number = international_phone_number() + + + class RegisterUserFromInviteForm(RegisterUserForm): def __init__(self, invited_user): super().__init__( diff --git a/app/main/views/index.py b/app/main/views/index.py index e6107ab10..d3af767ee 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -1,3 +1,4 @@ +import os from flask import abort, redirect, render_template, request, url_for from flask_login import current_user @@ -8,6 +9,8 @@ from app.main.views.pricing import CURRENT_SMS_RATE from app.main.views.sub_navigation_dictionaries import features_nav, using_notify_nav from app.utils.user import user_is_logged_in +login_dot_gov_url = os.getenv("LOGIN_DOT_GOV_INITIAL_SIGNIN_URL") + @main.route("/") def index(): @@ -18,6 +21,7 @@ def index(): "views/signedout.html", sms_rate=CURRENT_SMS_RATE, counts=status_api_client.get_count_of_live_services_and_organizations(), + login_dot_gov_url=login_dot_gov_url, ) diff --git a/app/main/views/register.py b/app/main/views/register.py index 76c839251..fe0b04d66 100644 --- a/app/main/views/register.py +++ b/app/main/views/register.py @@ -1,6 +1,9 @@ from datetime import datetime, timedelta +import uuid -from flask import abort, redirect, render_template, session, url_for +from flask import abort, current_app, redirect, render_template, request, session, url_for +from app.main.views import sign_in +from app import user_api_client from flask_login import current_user from app.main import main @@ -8,6 +11,7 @@ from app.main.forms import ( RegisterUserForm, RegisterUserFromInviteForm, RegisterUserFromOrgInviteForm, + SetupUserProfileForm, ) from app.main.views.verify import activate_user from app.models.user import InvitedOrgUser, InvitedUser, User @@ -120,13 +124,46 @@ def _do_registration(form, send_sms=True, send_email=True, organization_id=None) def registration_continue(): if not session.get("user_details"): return redirect(url_for(".show_accounts_or_dashboard")) + else: + raise Exception("Unexpected routing in registration_continue") -@main.route("/set-up-your-profile") + +@main.route("/set-up-your-profile", methods=["GET", "POST"]) @hide_from_search_engines def set_up_your_profile(): + print("ENTER set_up_your_profile") - form = RegisterUserForm() + + + form = SetupUserProfileForm() if form.validate_on_submit(): - _do_registration(form, send_sms=False, send_email=False) + print("VALIDATING FORM") + # start login.gov + code = request.args.get("code") + state = request.args.get("state") + login_gov_error = request.args.get("error") + if code and state: + access_token = sign_in._get_access_token(code, state) + user_email, user_uuid = sign_in._get_user_email_and_uuid(access_token) + redirect_url = request.args.get("next") + + + + elif login_gov_error: + current_app.logger.error(f"login.gov error: {login_gov_error}") + raise Exception(f"Could not login with login.gov {login_gov_error}") + # end login.gov + + user = User.register( + name=form.name.data, + email_address=user_email, + mobile_number=form.mobile_number.data, + password=str(uuid.uuid4()), + auth_type="sms_auth", + ) + # activate the user + user = user_api_client.get_user_by_uuid_or_email(user_uuid, user_email) + activate_user(user["id"]) + return redirect(url_for("main.show_accounts_or_dashboard", next=redirect_url)) return render_template("views/set-up-your-profile.html", form=form) diff --git a/app/main/views/send.py b/app/main/views/send.py index 6ef2afc77..8853b7fc3 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -524,7 +524,9 @@ def _check_messages(service_id, template_id, upload_id, preview_row): for user in Users(service_id): allow_list.extend([user.name, user.mobile_number, user.email_address]) # Failed sms number - allow_list.extend(["simulated user (fail)", "+14254147167", "simulated@simulated.gov"]) + allow_list.extend( + ["simulated user (fail)", "+14254147167", "simulated@simulated.gov"] + ) # Success sms number allow_list.extend( ["simulated user (success)", "+14254147755", "simulatedtwo@simulated.gov"] diff --git a/app/main/views/sign_in.py b/app/main/views/sign_in.py index d39cb89af..034db6ae7 100644 --- a/app/main/views/sign_in.py +++ b/app/main/views/sign_in.py @@ -61,6 +61,7 @@ def _get_access_token(code, state): url = f"{base_url}{cli_assert}&{cli_assert_type}&{code_param}&grant_type=authorization_code" headers = {"Authorization": "Bearer %s" % token} response = requests.post(url, headers=headers) + print(f"RESPONSE FROM LOGIN DOT GOV {response.json()}") access_token = response.json()["access_token"] return access_token @@ -166,30 +167,8 @@ def sign_in(): other_device = current_user.logged_in_elsewhere() notify_env = os.getenv("NOTIFY_ENVIRONMENT") - current_app.logger.info("should render the sign in template") - # TODO REMOVE THIS INFO ONCE STAGING WORKS WITH LOGIN DOT GOV - current_app.logger.info(f"NOTIFY ENV = {notify_env}") - current_app.logger.info( - f"LOGIN_DOT_GOV_CLIENT_ID={os.getenv('LOGIN_DOT_GOV_CLIENT_ID')}" - ) - current_app.logger.info( - f"LOGIN_DOT_GOV_USER_INFO_URL={os.getenv('LOGIN_DOT_GOV_USER_INFO_URL')}" - ) - current_app.logger.info( - f"LOGIN_DOT_GOV_ACCESS_TOKEN_URL={os.getenv('LOGIN_DOT_GOV_ACCESS_TOKEN_URL')}" - ) - current_app.logger.info( - f"LOGIN_DOT_GOV_LOGOUT_URL={os.getenv('LOGIN_DOT_GOV_LOGOUT_URL')}" - ) - current_app.logger.info( - f"LOGIN_DOT_GOV_BASE_LOGOUT_URL={os.getenv('LOGIN_DOT_GOV_BASE_LOGOUT_URL')}" - ) - current_app.logger.info( - f"LOGIN_DOT_GOV_SIGNOUT_REDIRECT={os.getenv('LOGIN_DOT_GOV_SIGNOUT_REDIRECT')}" - ) initial_signin_url = os.getenv("LOGIN_DOT_GOV_INITIAL_SIGNIN_URL") - current_app.logger.info(f"LOGIN_DOT_GOV_INITIAL_SIGNIN_URL={initial_signin_url}") return render_template( "views/signin.html", diff --git a/app/main/views/sign_out.py b/app/main/views/sign_out.py index 6d03665da..5ec96e189 100644 --- a/app/main/views/sign_out.py +++ b/app/main/views/sign_out.py @@ -6,10 +6,6 @@ from flask_login import current_user from app.main import main -# ask login.gov if we really need manual logout and what's up with one hour sessions -# ask login.gov how they recommend approaching dev environment -# ask Tim Donaworth the same for #2 - def _sign_out_at_login_dot_gov(): base_url = os.getenv("LOGIN_DOT_GOV_BASE_LOGOUT_URL") diff --git a/app/templates/views/signedout.html b/app/templates/views/signedout.html index 9c7699329..1ce65aefd 100644 --- a/app/templates/views/signedout.html +++ b/app/templates/views/signedout.html @@ -21,7 +21,7 @@ Notify.gov

Reach people where they are with government-powered text messages

Notify.gov is a text message service that helps federal, state, local, tribal and territorial governments more effectively communicate with the people they serve.

- Sign in + Sign in if you are an existing pilot partner

Currently we are only working with select pilot partners. If you are interested in using Notify.gov in the future, please contact
tts-benefits-studio@gsa.gov to learn more.