<commit_before>from flask import jsonify
from validate_email import validate_email
from modals.modals import UserModal


class Authenticate(object):
    """
    Handles all user operations
    """

    def register(self,email, password, name):
        """
        Registers a new user to the application
        and returns an API response with status
        code set to 201 on success
        """
        if not name or not email or not password:
            response = jsonify({'Error': 'Missing Values'})
            response.status_code = 400
            return response

        if not validate_email(email):
            response = jsonify({'Error': 'Invalid Email'})
            response.status_code = 400
            return response

        if len(password) < 6:
            response = jsonify({'Error': 'Password is short'})
            response.status_code = 400
            return response

        user = UserModal(email=email, password=password, name=name)

        if user.query.filter_by(email=email).first():
            response = jsonify({'Error': 'Email Already exists'})
            response.status_code = 400
            return response

        user.save()
        response = jsonify({
            'Status': user.email + ' Successfully registered',
            'id': user.id
        })
        response.status_code = 201
        return response

    def login(self, email, password):
        """
        logs in an existing user to the application
        and returns an API response with status
        code set to 201 on success
        """
        if not email or not password:
            response = jsonify({'Error': 'Missing login credentials'})
            response.status_code = 400
            return response

        if not validate_email(email):
            response = jsonify({'Error': 'Enter valid email'})
            response.status_code = 400
            return response

        user = UserModal(email=email, password=password)
        user_data = user.query.filter_by(email=email).first()

        # If Login successful
        if user_data and user.check_password(user_data.password,
                                             password):
            response = jsonify({
                'Status': user.email + ' Login Successful',
                'id': user_data.id
            })
            response.status_code = 201
            return response

        response = jsonify({'Error': 'Incorrect email or password'})
        response.status_code = 400
        return response
<commit_msg>Check for empty and non-exisiting email<commit_after>from flask import jsonify
from validate_email import validate_email
from modals.modals import UserModal


class Authenticate(object):
    """
    Handles all user operations
    """

    def register(self,email, password, name):
        """
        Registers a new user to the application
        and returns an API response with status
        code set to 201 on success
        """
        if not name or not email or not password:
            response = jsonify({'Error': 'Missing Values'})
            response.status_code = 400
            return response

        if not validate_email(email):
            response = jsonify({'Error': 'Invalid Email'})
            response.status_code = 400
            return response

        if len(password) < 6:
            response = jsonify({'Error': 'Password is short'})
            response.status_code = 400
            return response

        user = UserModal(email=email, password=password, name=name)

        if user.query.filter_by(email=email).first():
            response = jsonify({'Error': 'Email Already exists'})
            response.status_code = 400
            return response

        user.save()
        response = jsonify({
            'Status': user.email + ' Successfully registered',
            'id': user.id
        })
        response.status_code = 201
        return response

    def login(self, email, password):
        """
        logs in an existing user to the application
        and returns an API response with status
        code set to 201 on success
        """
        if not email or not password:
            response = jsonify({'Error': 'Missing login credentials'})
            response.status_code = 400
            return response

        if not validate_email(email):
            response = jsonify({'Error': 'Enter valid email'})
            response.status_code = 400
            return response

        user = UserModal(email=email, password=password)
        user_data = user.query.filter_by(email=email).first()

        # If Login successful
        if user_data and user.check_password(user_data.password,
                                             password):
            response = jsonify({
                'Status': user.email + ' Login Successful',
                'id': user_data.id
            })
            response.status_code = 201
            return response

        response = jsonify({'Error': 'Incorrect email or password'})
        response.status_code = 400
        return response

    def reset_password(self, email):
        """
        resets password of an existing user
        and returns an API response with status
        code set to 201 on success
        """
        if not email:
            response = jsonify({'Error': 'No email sent'})
            response.status_code = 400
            return response

        if not validate_email(email):
            response = jsonify({'Error': 'Enter valid email'})
            response.status_code = 400
            return response

        user = UserModal(email=email, password='')
        user_data = user.query.filter_by(email=email).first()
        if user_data:
            return 0
        response = jsonify({'Error': 'Email does not exist'})
        response.status_code = 400
        return response

{'fraction_non_alphanumeric': 0.08387206532834297, 'fraction_numerical': 0.013780197346036067, 'mean_word_length': 1.8636142230881636, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2229360', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1393, 'n_words': 464}