mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 19:53:13 -04:00
fix register from join service
This commit is contained in:
@@ -605,6 +605,14 @@ class RegisterUserForm(StripWhitespaceForm):
|
|||||||
auth_type = HiddenField("auth_type", default="sms_auth")
|
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):
|
class RegisterUserFromInviteForm(RegisterUserForm):
|
||||||
def __init__(self, invited_user):
|
def __init__(self, invited_user):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
from flask import abort, redirect, render_template, request, url_for
|
from flask import abort, redirect, render_template, request, url_for
|
||||||
from flask_login import current_user
|
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.main.views.sub_navigation_dictionaries import features_nav, using_notify_nav
|
||||||
from app.utils.user import user_is_logged_in
|
from app.utils.user import user_is_logged_in
|
||||||
|
|
||||||
|
login_dot_gov_url = os.getenv("LOGIN_DOT_GOV_INITIAL_SIGNIN_URL")
|
||||||
|
|
||||||
|
|
||||||
@main.route("/")
|
@main.route("/")
|
||||||
def index():
|
def index():
|
||||||
@@ -18,6 +21,7 @@ def index():
|
|||||||
"views/signedout.html",
|
"views/signedout.html",
|
||||||
sms_rate=CURRENT_SMS_RATE,
|
sms_rate=CURRENT_SMS_RATE,
|
||||||
counts=status_api_client.get_count_of_live_services_and_organizations(),
|
counts=status_api_client.get_count_of_live_services_and_organizations(),
|
||||||
|
login_dot_gov_url=login_dot_gov_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
from datetime import datetime, timedelta
|
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 flask_login import current_user
|
||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
@@ -8,6 +11,7 @@ from app.main.forms import (
|
|||||||
RegisterUserForm,
|
RegisterUserForm,
|
||||||
RegisterUserFromInviteForm,
|
RegisterUserFromInviteForm,
|
||||||
RegisterUserFromOrgInviteForm,
|
RegisterUserFromOrgInviteForm,
|
||||||
|
SetupUserProfileForm,
|
||||||
)
|
)
|
||||||
from app.main.views.verify import activate_user
|
from app.main.views.verify import activate_user
|
||||||
from app.models.user import InvitedOrgUser, InvitedUser, 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():
|
def registration_continue():
|
||||||
if not session.get("user_details"):
|
if not session.get("user_details"):
|
||||||
return redirect(url_for(".show_accounts_or_dashboard"))
|
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
|
@hide_from_search_engines
|
||||||
def set_up_your_profile():
|
def set_up_your_profile():
|
||||||
|
print("ENTER set_up_your_profile")
|
||||||
|
|
||||||
form = RegisterUserForm()
|
|
||||||
|
|
||||||
|
form = SetupUserProfileForm()
|
||||||
if form.validate_on_submit():
|
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)
|
return render_template("views/set-up-your-profile.html", form=form)
|
||||||
|
|||||||
@@ -524,7 +524,9 @@ def _check_messages(service_id, template_id, upload_id, preview_row):
|
|||||||
for user in Users(service_id):
|
for user in Users(service_id):
|
||||||
allow_list.extend([user.name, user.mobile_number, user.email_address])
|
allow_list.extend([user.name, user.mobile_number, user.email_address])
|
||||||
# Failed sms number
|
# 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
|
# Success sms number
|
||||||
allow_list.extend(
|
allow_list.extend(
|
||||||
["simulated user (success)", "+14254147755", "simulatedtwo@simulated.gov"]
|
["simulated user (success)", "+14254147755", "simulatedtwo@simulated.gov"]
|
||||||
|
|||||||
@@ -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"
|
url = f"{base_url}{cli_assert}&{cli_assert_type}&{code_param}&grant_type=authorization_code"
|
||||||
headers = {"Authorization": "Bearer %s" % token}
|
headers = {"Authorization": "Bearer %s" % token}
|
||||||
response = requests.post(url, headers=headers)
|
response = requests.post(url, headers=headers)
|
||||||
|
print(f"RESPONSE FROM LOGIN DOT GOV {response.json()}")
|
||||||
access_token = response.json()["access_token"]
|
access_token = response.json()["access_token"]
|
||||||
return access_token
|
return access_token
|
||||||
|
|
||||||
@@ -166,30 +167,8 @@ def sign_in():
|
|||||||
|
|
||||||
other_device = current_user.logged_in_elsewhere()
|
other_device = current_user.logged_in_elsewhere()
|
||||||
notify_env = os.getenv("NOTIFY_ENVIRONMENT")
|
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")
|
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(
|
return render_template(
|
||||||
"views/signin.html",
|
"views/signin.html",
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ from flask_login import current_user
|
|||||||
|
|
||||||
from app.main import main
|
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():
|
def _sign_out_at_login_dot_gov():
|
||||||
base_url = os.getenv("LOGIN_DOT_GOV_BASE_LOGOUT_URL")
|
base_url = os.getenv("LOGIN_DOT_GOV_BASE_LOGOUT_URL")
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ Notify.gov
|
|||||||
<h1 class="font-serif-2xl usa-hero__heading">Reach people where they are with government-powered text messages</h1>
|
<h1 class="font-serif-2xl usa-hero__heading">Reach people where they are with government-powered text messages</h1>
|
||||||
<p class="font-sans-lg">Notify.gov is a text message service that helps federal, state, local, tribal and territorial governments more effectively communicate with the people they serve.</p>
|
<p class="font-sans-lg">Notify.gov is a text message service that helps federal, state, local, tribal and territorial governments more effectively communicate with the people they serve.</p>
|
||||||
<div class="usa-button-group margin-bottom-5">
|
<div class="usa-button-group margin-bottom-5">
|
||||||
<a class="usa-button usa-button--big margin-right-2" href="{{ url_for('main.sign_in' )}}">Sign in</a>
|
<a class="usa-button usa-button--big margin-right-2" href="{{ login_dot_gov_url }}">Sign in</a>
|
||||||
if you are an existing pilot partner
|
if you are an existing pilot partner
|
||||||
</div>
|
</div>
|
||||||
<p class="font-sans-md">Currently we are only working with select pilot partners. If you are interested in using Notify.gov in the future, please contact <br><a href="mailto:tts-benefits-studio@gsa.gov">tts-benefits-studio@gsa.gov</a> to learn more.</p>
|
<p class="font-sans-md">Currently we are only working with select pilot partners. If you are interested in using Notify.gov in the future, please contact <br><a href="mailto:tts-benefits-studio@gsa.gov">tts-benefits-studio@gsa.gov</a> to learn more.</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user