<s> from django import db <EOL> from django . contrib import auth <EOL> from django . utils . encoding import force_bytes <EOL> def check_password ( environ , username , password ) : <EOL> """<STR_LIT>""" <EOL> UserModel = auth . get_user_model ( ) <EOL> db . reset_queries ( ) <EOL> try : <EOL> try : <EOL> user = UserModel . _default_manager . get_by_natural_key ( username ) <EOL> except UserModel . DoesNotExist : <EOL> return None <EOL> if not user . is_active : <EOL> return None <EOL> return user . check_password ( password ) <EOL> finally : <EOL> db . close_old_connections ( ) <EOL> def groups_for_user ( environ , username ) : <EOL> """<STR_LIT>""" <EOL> UserModel = auth . get_user_model ( ) <EOL> db . reset_queries ( ) <EOL> try : <EOL> try : <EOL> user = UserModel . _default_manager . get_by_natural_key ( username ) <EOL> except UserModel . DoesNotExist : <EOL> return [ ] <EOL> if not user . is_active : <EOL> return [ ] <EOL> return [ force_bytes ( group . name ) for group in user . groups . all ( ) ] <EOL> finally : <EOL> db . close_old_connections ( ) </s>
