def main(req: func.HttpRequest) -> func.HttpResponse:

    profile_id = str(req.params.get('profile_id'))
    vault_id = str(req.params.get('vault_id'))
    encrypted_vault = req.params.get('encrypted_vault')

    if not profile_id:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            profile_id = req_body.get('profile_id')

    if not encrypted_vault:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            encrypted_vault = req_body.get('encrypted_vault')

    respone = {"message": "There is a missing parameter in your request"}
    if not encrypted_vault:
        encrypted_vault = ""
    if profile_id:
        response = {'message': "Please verify your account"}
        if profile_is_verified(profile_id):

            load_vault_query = "EXEC Vault_load @Profile_id = '" + profile_id + "', @Encrypted_Vault = '" + encrypted_vault + "';"

            response = query_handler.exec_query_with_message(load_vault_query)
            response = json.loads(response)[0]

    return func.HttpResponse(json.dumps(response), mimetype="application/json")
def main(req: func.HttpRequest) -> func.HttpResponse:

    profile_id = req.params.get('profile_id')
    code = req.params.get('code')

    if not code:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            code = req_body.get('code')
    if not profile_id:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            profile_id = req_body.get('profile_id')

   
    if code and profile_id: 
        auth_profile_query = "EXEC Profile_Authenticate "+"@Profile_id='"+profile_id+"'"+" , @Authentication_Code='"+code+"';"
        response = query_handler.exec_query_with_message(auth_profile_query)
        response = json.loads(response)[0]
        return func.HttpResponse(
            json.dumps(response) ,
            mimetype="application/json"
        )
    else:

        return func.HttpResponse(
            "There is a missing parameter in your request",
            status_code=200
        )
Beispiel #3
0
def main(req: func.HttpRequest) -> func.HttpResponse:

    profile_id = req.params.get('profile_id')


    if not profile_id:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            profile_id = req_body.get('profile_id')

   

    response = {"message":"There is a missing parameter in your request"}
    if profile_id: 
        delete_profile_query = "EXEC Profile_Delete "+"@Profile_id ='"+profile_id+"';"
        response = query_handler.exec_query_with_message(delete_profile_query)
        response = json.loads(response)[0]


        
    return func.HttpResponse(
        json.dumps(response) ,
        mimetype="application/json"
    )
def profile_is_verified(profile_id: int) -> bool:
    """[summary]
        Checks if the user has been verified 
    Args:
        profile_id (int): profile id of the user logging in

    Returns:
        boolean: tells us whether the user has been verified or not
    """
    response = exec_query_with_message(
        "EXEC profile_is_verified @Profile_id = '" + str(profile_id) + "';")
    response = json.loads(response)[0]
    if response["verified"] == 1:
        return True
    return False
Beispiel #5
0
def main(req: func.HttpRequest) -> func.HttpResponse:

    name = req.params.get('name')
    email = req.params.get('email')
    password = req.params.get('password')

    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if not email:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            email = req_body.get('email')
    if not password:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            password = req_body.get('password')

    if name and password and email:
        add_profile_query = "EXEC Profile_Add " + "@Full_Name='" + name + "'" + " , @Email='" + email + "'" + " , @Password='******';"
        response = query_handler.exec_query_with_message(add_profile_query)
        data = json.loads(response)[0]

        if "profile_id" in data:
            profile_id = data['profile_id']
            # sms_client = SMS_Client()
            # sms_client.send_verification_message(profile_id)
            to_email, message = email_sender.generate_verification_message(
                profile_id)
            email_sender.send_mail(to_email, message)
        return func.HttpResponse(json.dumps(data), mimetype="application/json")
    else:

        return func.HttpResponse(
            "There is a missing parameter in your request", status_code=200)
Beispiel #6
0
def main(req: func.HttpRequest) -> func.HttpResponse:

    email = req.params.get('email')
    password = req.params.get('password')

    if not email:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            email = req_body.get('email')
    if not password:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            password = req_body.get('password')

    response = {'message': "There is a missing parameter in your request"}
    if password and email:
        profile_authentication_query = "EXEC validate_profile @Email='" + email + "'" + " , @Password='******';"
        response = query_handler.exec_query_with_message(
            profile_authentication_query)
        data = json.loads(response)[0]
        if not data["valid"]:

            return func.HttpResponse(json.dumps({'valid': False}),
                                     mimetype="application/json")

        if "profile_id" in data:
            profile_id = data['profile_id']

            response = {'message': "Please verify your account"}
            if profile_is_verified(profile_id):
                to_email, message = email_sender.generate_auth_message(
                    profile_id)
                email_sender.send_mail(to_email, message)
                response = data

    return func.HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #7
0
def main(req: func.HttpRequest) -> func.HttpResponse:

    name = req.params.get('name')
    email = req.params.get('email')
    password = req.params.get('password')
    encrypted_vault = req.params.get('encrypted_vault')

    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if not email:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            email = req_body.get('email')
    if not password:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            password = req_body.get('password')
  
    if not encrypted_vault:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            encrypted_vault = req_body.get('encrypted_vault')
   

    response = {"message":"There is a missing parameter in your request"}
    if name  and password and email and encrypted_vault: 
        add_profile_query = "EXEC Profile_Add "+"@Full_Name='"+name+"'"+" , @Email='"+email+"'"+" , @Password='******';"
        response = query_handler.exec_query_with_message(add_profile_query)
        data = json.loads(response)[0]
        response = data
    
        logging.info(response)
        # response = {'message': "error: try again later"}
        if "profile_id" in response:
            profile_id = response['profile_id']

            create_vault_query = "EXEC Vault_create "+"@Profile_id ='"+str(profile_id)+"'"+" , @Encrypted_vault='"+encrypted_vault+"';"
            query_handler.exec_query_with_no_response(create_vault_query)
      

            # sms_client = SMS_Client()
            # sms_client.send_verification_message(profile_id)
            to_email , message = email_sender.generate_verification_message(profile_id)
            email_sender.send_mail( to_email , message)
            response = data
        
    return func.HttpResponse(
        json.dumps(response) ,
        mimetype="application/json"
    )