<s> from pyramid . events import subscriber , BeforeRender <EOL> from social . apps . pyramid_app . utils import backends <EOL> from example . models import DBSession , User <EOL> def login_user ( backend , user , user_social_auth ) : <EOL> backend . strategy . session_set ( '<STR_LIT>' , user . id ) <EOL> def login_required ( request ) : <EOL> return getattr ( request , '<STR_LIT:user>' , None ) is not None <EOL> def get_user ( request ) : <EOL> user_id = request . session . get ( '<STR_LIT>' ) <EOL> if user_id : <EOL> user = DBSession . query ( User ) . filter ( User . id == user_id ) . first ( ) <EOL> else : <EOL> user = None <EOL> return user <EOL> @ subscriber ( BeforeRender ) <EOL> def add_social ( event ) : <EOL> request = event [ '<STR_LIT>' ] <EOL> event [ '<STR_LIT>' ] = backends ( request , request . user ) </s>
