comparison foodtruck/web.py @ 608:8e1b38632702

admin: Show the install page if no secret key is available.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 27 Jan 2016 23:39:00 -0800
parents c6bc0ef03f82
children efc1dc916e7c
comparison
equal deleted inserted replaced
607:c67dcc0fa80f 608:8e1b38632702
89 @app.errorhandler 89 @app.errorhandler
90 def _on_error(ex): 90 def _on_error(ex):
91 logging.exception(ex) 91 logging.exception(ex)
92 92
93 93
94 _missing_secret_key = False
95
96 if not app.secret_key:
97 # If there's no secret key, create a temp one but mark the app as not
98 # correctly installed so it shows the installation information page.
99 app.secret_key = 'temp-key'
100 _missing_secret_key = True
101
102
94 from flask.ext.login import LoginManager, UserMixin 103 from flask.ext.login import LoginManager, UserMixin
95 104
96 105
97 class User(UserMixin): 106 class User(UserMixin):
98 def __init__(self, uid, pwd): 107 def __init__(self, uid, pwd):
110 119
111 login_manager = LoginManager() 120 login_manager = LoginManager()
112 login_manager.init_app(app) 121 login_manager.init_app(app)
113 login_manager.login_view = 'login' 122 login_manager.login_view = 'login'
114 login_manager.user_loader(load_user) 123 login_manager.user_loader(load_user)
124
125 if _missing_secret_key:
126 def _handler():
127 raise FoodTruckConfigNotFoundError()
128
129 logger.debug("No secret key found, disabling website.")
130 login_manager.unauthorized_handler(_handler)
131 login_manager.login_view = None
115 132
116 133
117 try: 134 try:
118 from flask.ext.bcrypt import Bcrypt 135 from flask.ext.bcrypt import Bcrypt
119 except ImportError: 136 except ImportError: