<s> """<STR_LIT>""" <EOL> import sys <EOL> from simplepam import authenticate <EOL> from flask import current_app <EOL> from website . services import exec_command <EOL> class User ( object ) : <EOL> id = None <EOL> username = None <EOL> def __init__ ( self , id , username ) : <EOL> self . id = id <EOL> self . username = username <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . id , self . username ) <EOL> def is_active ( self ) : <EOL> return True <EOL> def is_authenticated ( self ) : <EOL> return True <EOL> def is_anonymous ( self ) : <EOL> return False <EOL> def get_id ( self ) : <EOL> return unicode ( self . id ) <EOL> @ classmethod <EOL> def query_filter_by ( cls , id = None , username = None ) : <EOL> if id : <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' , str ( id ) ] <EOL> elif username : <EOL> cmd = [ '<STR_LIT:id>' , '<STR_LIT>' , str ( username ) ] <EOL> else : <EOL> return None <EOL> try : <EOL> r = exec_command ( cmd ) <EOL> except : <EOL> current_app . logger . error ( '<STR_LIT>' , cmd , <EOL> sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> return None <EOL> if r [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> current_app . logger . error ( '<STR_LIT>' , <EOL> cmd , r [ '<STR_LIT>' ] , r [ '<STR_LIT>' ] ) <EOL> return None <EOL> if id : <EOL> username = r [ '<STR_LIT>' ] . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> return cls ( id , username ) <EOL> if username : <EOL> id = int ( r [ '<STR_LIT>' ] ) <EOL> return cls ( id , username ) <EOL> @ classmethod <EOL> def check_auth ( cls , username , password ) : <EOL> r = authenticate ( str ( username ) , str ( password ) , service = '<STR_LIT>' ) <EOL> if not r : <EOL> current_app . logger . error ( '<STR_LIT>' , <EOL> username , r ) <EOL> return r </s>
