<s> import hashlib <EOL> from amonone . web . apps . core . basemodel import BaseModel <EOL> class UserModel ( BaseModel ) : <EOL> def __init__ ( self ) : <EOL> super ( UserModel , self ) . __init__ ( ) <EOL> self . collection = self . mongo . get_collection ( '<STR_LIT>' ) <EOL> def create_user ( self , userdata ) : <EOL> userdata [ '<STR_LIT:password>' ] = hashlib . sha1 ( userdata [ '<STR_LIT:password>' ] ) . hexdigest ( ) <EOL> self . collection . save ( userdata ) <EOL> def check_user ( self , userdata ) : <EOL> userdata [ '<STR_LIT:password>' ] = hashlib . sha1 ( userdata [ '<STR_LIT:password>' ] ) . hexdigest ( ) <EOL> result = self . collection . find_one ( { "<STR_LIT:username>" : userdata [ '<STR_LIT:username>' ] , <EOL> "<STR_LIT:password>" : userdata [ '<STR_LIT:password>' ] } ) <EOL> return result if result else { } <EOL> def count_users ( self ) : <EOL> return self . collection . count ( ) <EOL> def username_exists ( self , username ) : <EOL> result = self . collection . find ( { "<STR_LIT:username>" : username } ) . count ( ) <EOL> return result <EOL> def get_all ( self ) : <EOL> return self . collection . find ( ) <EOL> def get ( self , id ) : <EOL> try : <EOL> object_id = self . mongo . get_object_id ( id ) <EOL> except : <EOL> object_id = False <EOL> if object_id : <EOL> return self . collection . find_one ( object_id ) <EOL> def update ( self , data , id ) : <EOL> id = self . mongo . get_object_id ( id ) <EOL> servers = data . get ( '<STR_LIT>' , None ) <EOL> if servers is not None : <EOL> self . collection . update ( { "<STR_LIT>" : id } , { "<STR_LIT>" : { "<STR_LIT>" : data [ '<STR_LIT>' ] } } ) <EOL> password = data . get ( '<STR_LIT:password>' , None ) <EOL> if password is not None : <EOL> data [ '<STR_LIT:password>' ] = hashlib . sha1 ( data [ '<STR_LIT:password>' ] ) . hexdigest ( ) <EOL> self . collection . update ( { "<STR_LIT>" : id } , { "<STR_LIT>" : { "<STR_LIT:password>" : data [ '<STR_LIT:password>' ] } } ) <EOL> def delete ( self , id ) : <EOL> try : <EOL> object_id = self . mongo . get_object_id ( id ) <EOL> except : <EOL> object_id = False <EOL> if object_id : <EOL> self . collection . remove ( object_id ) <EOL> user_model = UserModel ( ) </s>
