Example #1
0
def Authenticate(cred):
    '''

    User authentication.

    :param cred: Credentials Dictionary(email, password)
     :type cred: Dict{}
    :return: Returns True/False response with message.
     :rtype: Dict{}
    '''
    # Validate User
    try:
        Users = (models.get_user_information())['users']
        # Check users for given email
        goal_User = Users[cred['email']]
    # If user is not found, return key error
    except KeyError:
        response = {
            'Response': 'False',
            'Message': 'Invalid email'
        }
        return response
    # Once User is Validated, check if password is a match
    if goal_User['password'] == cred['password']:
        # If match, return True
        response = {
            'Response': 'True',
            'Message': 'Credentials Correct',
            'Data': goal_User['email']
        }
        return response
    else:
        # Else, return False
        response = {
            'Response': 'False',
            'Message': 'Password incorrect'
        }
        return response
Example #2
0
def users():
    return json.dumps(models.get_user_information())