<s> import base64 <EOL> from flask import Response <EOL> from flask . ext import login <EOL> from . app import app <EOL> login_manager = login . LoginManager ( ) <EOL> login_manager . init_app ( app ) <EOL> class AnonymousUser ( login . AnonymousUserMixin ) : <EOL> def is_anonymous ( self ) : <EOL> return True <EOL> def is_active ( self ) : <EOL> return False <EOL> def is_authenticated ( self ) : <EOL> return False <EOL> def get_id ( self ) : <EOL> return <EOL> class User ( login . UserMixin ) : <EOL> def __init__ ( self , id , password ) : <EOL> self . id = id <EOL> self . password = password <EOL> def is_authenticated ( self ) : <EOL> if not app . config . get ( '<STR_LIT>' ) : <EOL> return True <EOL> if self . id == app . config . get ( '<STR_LIT>' ) and self . password == app . config . get ( '<STR_LIT>' ) : <EOL> return True <EOL> return False <EOL> def is_active ( self ) : <EOL> return self . is_authenticated ( ) <EOL> login_manager . anonymous_user = AnonymousUser <EOL> @ login_manager . request_loader <EOL> def load_user_from_request ( request ) : <EOL> api_key = request . headers . get ( '<STR_LIT>' ) <EOL> if api_key : <EOL> api_key = api_key [ len ( "<STR_LIT>" ) : ] <EOL> try : <EOL> api_key = base64 . b64decode ( api_key ) . decode ( '<STR_LIT:utf8>' ) <EOL> return User ( * api_key . split ( "<STR_LIT::>" , <NUM_LIT:1> ) ) <EOL> except Exception as e : <EOL> app . logger . error ( '<STR_LIT>' , api_key , e ) <EOL> return None <EOL> return None <EOL> app . login_response = Response ( <EOL> "<STR_LIT>" , <NUM_LIT> , { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> @ app . before_request <EOL> def before_request ( ) : <EOL> if app . config . get ( '<STR_LIT>' , False ) : <EOL> if not login . current_user . is_active ( ) : <EOL> return app . login_response </s>
