<s> from flask import request <EOL> from flask_login import current_user <EOL> from itsdangerous import URLSafeTimedSerializer <EOL> from catwatch . extensions import login_manager , babel <EOL> def authentication ( app , user_model ) : <EOL> """<STR_LIT>""" <EOL> login_manager . login_view = '<STR_LIT>' <EOL> @ login_manager . user_loader <EOL> def load_user ( uid ) : <EOL> return user_model . query . get ( uid ) <EOL> @ login_manager . token_loader <EOL> def load_token ( token ) : <EOL> duration = app . config [ '<STR_LIT>' ] . total_seconds ( ) <EOL> serializer = URLSafeTimedSerializer ( app . secret_key ) <EOL> data = serializer . loads ( token , max_age = duration ) <EOL> user_uid = data [ <NUM_LIT:0> ] <EOL> return user_model . query . get ( user_uid ) <EOL> def locale ( app ) : <EOL> """<STR_LIT>""" <EOL> @ babel . localeselector <EOL> def get_locale ( ) : <EOL> if current_user . is_authenticated ( ) : <EOL> return current_user . locale <EOL> accept_languages = app . config . get ( '<STR_LIT>' ) <EOL> return request . accept_languages . best_match ( accept_languages ) </s>
