Have all error pages be rendered by Angular

Fixes #2198

Fixes https://www.pivotaltracker.com/story/show/135724483
This commit is contained in:
Joseph Schorr 2016-12-07 17:13:17 -05:00
parent 0aa6e6cd58
commit c06bba38de
13 changed files with 78 additions and 116 deletions

View file

@ -205,18 +205,18 @@ def render_page_template(name, route_data=None, **kwargs):
version_number = ' - ' + _get_version_number()
resp = make_response(render_template(name,
route_data=json.dumps(route_data),
route_data=route_data,
external_styles=external_styles,
external_scripts=external_scripts,
main_styles=add_cachebusters(main_styles),
library_styles=add_cachebusters(library_styles),
main_scripts=add_cachebusters(main_scripts),
library_scripts=add_cachebusters(library_scripts),
feature_set=json.dumps(features.get_features()),
config_set=json.dumps(frontend_visible_config(app.config)),
oauth_set=json.dumps(get_oauth_config()),
scope_set=json.dumps(scopes.app_scopes(app.config)),
vuln_priority_set=json.dumps(PRIORITY_LEVELS),
feature_set=features.get_features(),
config_set=frontend_visible_config(app.config),
oauth_set=get_oauth_config(),
scope_set=scopes.app_scopes(app.config),
vuln_priority_set=PRIORITY_LEVELS,
enterprise_logo=app.config.get('ENTERPRISE_LOGO_URL', ''),
mixpanel_key=app.config.get('MIXPANEL_KEY', ''),
munchkin_key=app.config.get('MARKETO_MUNCHKIN_ID', ''),

View file

@ -11,7 +11,7 @@ from app import app, analytics, get_app_url, github_login, google_login, dex_log
from auth.process import require_session_login
from data import model
from endpoints.common import common_login, route_show_if
from endpoints.web import render_page_template_with_routedata
from endpoints.web import index
from util.security.jwtutil import decode, InvalidTokenError
from util.validation import generate_valid_usernames
@ -20,15 +20,17 @@ client = app.config['HTTPCLIENT']
oauthlogin = Blueprint('oauthlogin', __name__)
def render_ologin_error(service_name,
error_message='Could not load user data. The token may have expired.'):
user_creation = features.USER_CREATION and features.DIRECT_LOGIN
return render_page_template_with_routedata('ologinerror.html',
service_name=service_name,
error_message=error_message,
service_url=get_app_url(),
user_creation=user_creation)
def render_ologin_error(service_name, error_message=None, register_redirect=False):
user_creation = bool(features.USER_CREATION and features.DIRECT_LOGIN)
error_info = {
'reason': 'ologinerror',
'service_name': service_name,
'error_message': error_message or 'Could not load user data. The token may have expired',
'service_url': get_app_url(),
'user_creation': user_creation,
'register_redirect': register_redirect,
}
return index('', error_info=error_info)
def get_user(service, token):
token_param = {
@ -81,7 +83,7 @@ def conduct_oauth_login(service, user_id, username, email, metadata={}):
message = message + "\nPlease log in with your username and password and "
message = message + "associate your %s account to use it in the future." % (service_name, )
return render_ologin_error(service_name, message)
return render_ologin_error(service_name, message, register_redirect=True)
except model.DataModelException as ex:
return render_ologin_error(service_name, ex.message)

View file

@ -67,7 +67,7 @@ def internal_error_display():
@web.errorhandler(404)
@web.route('/404', methods=['GET'])
def not_found_error_display(e = None):
resp = index('', error_code=404)
resp = index('', error_code=404, error_info=dict(reason='notfound'))
resp.status_code = 404
return resp
@ -275,12 +275,6 @@ def dbrevision_health():
return response
@web.route('/disclaimer', methods=['GET'])
@no_cache
def disclaimer():
return render_page_template_with_routedata('disclaimer.html')
@web.route('/robots.txt', methods=['GET'])
def robots():
robots_txt = make_response(render_template('robots.txt', baseurl=get_app_url()))
@ -367,7 +361,7 @@ def confirm_repo_email():
try:
record = model.repository.confirm_email_authorization_for_repo(code)
except model.DataModelException as ex:
return render_page_template_with_routedata('confirmerror.html', error_message=ex.message)
return index('', error_info=dict(reason='confirmerror', error_message=ex.message))
message = """
Your E-mail address has been authorized to receive notifications for repository
@ -390,7 +384,7 @@ def confirm_email():
try:
user, new_email, old_email = model.user.confirm_user_email(code)
except model.DataModelException as ex:
return render_page_template_with_routedata('confirmerror.html', error_message=ex.message)
return index('', error_info=dict(reason='confirmerror', error_message=ex.message))
if new_email:
send_email_changed(user.username, old_email, new_email)
@ -706,6 +700,7 @@ def redirect_to_repository(namespace_name, repo_name, tag_name):
# - If the repository does exist (no access), 403
# > If the user is not a member of the namespace: 403
error_info = {
'reason': 'notfound',
'for_repo': True,
'namespace_exists': namespace_exists,
'namespace': namespace_name,