<commit_before># -*- coding: utf-8 -*-

# <NAME>
# Summer 2014
# Univerity of Colorado

import logging

import moodle.ws

import config

EXTRA_USER_SCHEMA = ['moodle_id', 'moodle_token']

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.NullHandler())

class Authenticator(object):

    def __init__(self):

        # Call Parent
        super(Authenticator, self).__init__()

        # Setup Vars
        self.host = config.AUTHMOD_MOODLE_HOST
        self.service = config.AUTHMOD_MOODLE_SERVICE

    def auth_user(self, username, password):

        moodlews = moodle.ws.WS(self.host)

        try:
            ret = moodlews.authenticate(username, password, self.service, error=True)
        except moodle.ws.WSAuthError as e:
            logger.warning("AUTH_ERROR: {:s}".format(e))
            ret = False

        if ret:
            logger.debug("AUTH_ALLOWED {:s}".format(username))
            return moodlews.get_WSUser()
        else:
            logger.info("AUTH_DENIED {:s}".format(username))
            return None
<commit_msg>Added more Moodle auth error handling and logging<commit_after># -*- coding: utf-8 -*-

# <NAME>
# Summer 2014
# Univerity of Colorado

import logging

import moodle.ws

import config

EXTRA_USER_SCHEMA = ['moodle_id', 'moodle_token']

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.NullHandler())

class Authenticator(object):

    def __init__(self):

        # Call Parent
        super(Authenticator, self).__init__()

        # Setup Vars
        self.host = config.AUTHMOD_MOODLE_HOST
        self.service = config.AUTHMOD_MOODLE_SERVICE

    def auth_user(self, username, password):

        moodlews = moodle.ws.WS(self.host)

        try:
            ret = moodlews.authenticate(username, password, self.service, error=True)
        except moodle.ws.WSAuthError as e:
            logger.error("AUTH_ERROR: {:s}".format(e))
            ret = False

        if ret:
            logger.info("AUTH_ALLOWED {:s}".format(username))
            try:
                ret = moodlews.get_WSUser()
            except moodle.ws.WSAuthError as e:
                logger.error("GETUSER_ERROR: {:s}".format(e))
                ret = None
        else:
            logger.warning("AUTH_DENIED {:s}".format(username))
            ret = None

        return ret

{'fraction_non_alphanumeric': 0.11176224361657597, 'fraction_numerical': 0.004185851820845542, 'mean_word_length': 2.4687953555878086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1166444', 'n_tokens_mistral': 772, 'n_tokens_neox': 737, 'n_words': 152}