Force user to fill out their user profile

This commit is contained in:
Patrick Smith
2018-10-30 15:31:56 -04:00
parent f8c4386d84
commit dd5f99faab
5 changed files with 95 additions and 4 deletions

View File

@@ -21,10 +21,26 @@ def apply_authentication(app):
user = get_current_user()
if user:
g.current_user = user
if should_redirect_to_user_profile(request, user):
return redirect(url_for("users.user", next=request.path))
elif not _unprotected_route(request):
return redirect(url_for("atst.root", next=request.path))
def should_redirect_to_user_profile(request, user):
has_complete_profile = user.profile_complete
is_unprotected_route = _unprotected_route(request)
is_requesting_user_endpoint = request.endpoint in [
"users.user",
"users.update_user",
]
if has_complete_profile or is_unprotected_route or is_requesting_user_endpoint:
return False
return True
def get_current_user():
user_id = session.get("user_id")
if user_id: