MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / before_request

Function before_request

web/pgadmin/__init__.py:832–872  ·  view source on GitHub ↗

Login the default user if running in desktop mode

()

Source from the content-addressed store, hash-verified

830
831 @app.before_request
832 def before_request():
833 """Login the default user if running in desktop mode"""
834
835 # Check the auth key is valid, if it's set, and we're not in server
836 # mode, and it's not a help file request.
837
838 if not config.SERVER_MODE and app.PGADMIN_INT_KEY != '' and ((
839 'key' not in request.args or
840 request.args['key'] != app.PGADMIN_INT_KEY) and
841 request.cookies.get('PGADMIN_INT_KEY') != app.PGADMIN_INT_KEY and
842 request.endpoint != 'help.static'
843 ):
844 abort(401)
845
846 if not config.SERVER_MODE and not current_user.is_authenticated:
847 user = user_datastore.find_user(email=config.DESKTOP_USER)
848 # Throw an error if we failed to find the desktop user, to give
849 # the sysadmin a hint. We'll continue to try to login anyway as
850 # that'll through a nice 500 error for us.
851 if user is None:
852 app.logger.error(
853 'The desktop user %s was not found in the configuration '
854 'database.'
855 % config.DESKTOP_USER
856 )
857 abort(401)
858 login_user(user)
859 elif config.SERVER_MODE and not current_user.is_authenticated and \
860 request.endpoint in ('redirects.index', 'security.login') and \
861 app.PGADMIN_EXTERNAL_AUTH_SOURCE in [KERBEROS, WEBSERVER]:
862 return authenticate.login()
863 # if the server is restarted the in memory key will be lost
864 # but the user session may still be active. Logout the user
865 # to get the key again when login
866 if config.SERVER_MODE and current_user.is_authenticated and \
867 'auth_source_manager' in session and \
868 session['auth_source_manager']['current_source'] not in \
869 [KERBEROS, OAUTH2, WEBSERVER] and \
870 current_app.keyManager.get() is None and \
871 request.endpoint not in ('security.login', 'security.logout'):
872 logout_user()
873
874 @app.after_request
875 def after_request(response):

Callers

nothing calls this directly

Calls 3

errorMethod · 0.80
getMethod · 0.45
loginMethod · 0.45

Tested by

no test coverage detected