예제 #1
0
 def send_email(self, attachFilepath, toSend):
     self.config = read_config()
     output = {
         'statusCode': '200',
         'message': 'Email Sent.',
         'replyCode': 'Success'
     }
     try:
         if len(toSend) == 0:
             output['statusCode'] = '400'
             output['message'] = 'Please Provide Email Id'
             output['replyCode'] = 'Failed'
         fromEmail = self.config['SEND_EMAIL']['from']
         subject = self.config['SEND_EMAIL']['subject']
         message = self.config['SEND_EMAIL']['message']
         mail = EmailMessage(subject, message, fromEmail, toSend)
         try:
             for files in attachFilepath:
                 try:
                     mail.attach_file(str(files))
                 except Exception as e:
                     self.logger.error("Error while attaching files" +
                                       str(e))
         except Exception as e:
             self.logger.error("Error while attaching files" + str(e))
         try:
             mail.send()
         except Exception as e:
             print("Cant Send" + str(e) + "")
     except Exception as e:
         output['statusCode'] = '400'
         output['message'] = 'Email Cannot Sent'
         output['replyCode'] = 'Failed'
         self.logger.error("Error while Sending Email" + str(e))
     return output
예제 #2
0
def make_jwt_token(data: dict) -> str:
    """
    This function encode jwt token
    :param token: this is string type of input which contains jwt token.
        Sample token:
        eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyaWQiOiJVLTEifQ.aRzeeoMrtxJIi9HB4_9YoVnzJ16tgM0Xux5_q6q0gh0
    :return:
    """
    logger = get_logger()
    config = read_config()
    token = str()
    try:
        jwt_secret_key = config['JWT']['jwt_secret_key']
        jwt_algo = config['JWT']['jwt_algo']
        token = jwt.encode(data, jwt_secret_key, jwt_algo).decode('utf-8')
    except Exception as e:
        token = str()
        logger.error(str(e))
    return token
예제 #3
0
def extract_jwt_info(token: str) -> dict:
    """
    This function decode jwt token which we will receive from UI
    :param token: this is string type of input which contains jwt token.
        Sample token:
        eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyaWQiOiJVLTEifQ.aRzeeoMrtxJIi9HB4_9YoVnzJ16tgM0Xux5_q6q0gh0
    :return:
    """
    logger = get_logger()
    config = read_config()
    json_info = dict()
    try:
        jwt_secret_key = config['JWT']['jwt_secret_key']
        jwt_algo = config['JWT']['jwt_algo']
        json_info = jwt.decode(str(token),
                               jwt_secret_key,
                               algorithms=str(jwt_algo))
    except Exception as e:
        logger.error(str(e))
    return json_info
예제 #4
0
 def __init__(self):
     self.logger = get_logger() 
     self.config = read_config()
예제 #5
0
 def __init__(self):
     self.logger = get_logger()
     self.config = read_config()
     dt = datetime.datetime.now()
     self.todaydate = ("{}.{:03d}".format(dt.strftime('%Y-%m-%d %I:%M:%S'), dt.microsecond//1000))
예제 #6
0
from django.http.response import JsonResponse
from common_files.read_logger import get_logger
from common_files.read_configuration import read_config
import pyodbc
config = read_config()
logger = get_logger()


def db_conn(database=config['DIGICUBEDB']['database_name']):
    output = {
        'statusCode': 400,
        'message': 'Error in db connection',
        'replyCode': 'Fail',
        'data': {}
    }
    try:
        driver = config['DIGICUBEDB']['driver']
        server = config['DIGICUBEDB']['server']
        uid = config['DIGICUBEDB']['username']
        password = config['DIGICUBEDB']['password']
        connection = pyodbc.connect(
            "driver={};server={};database={};uid={};PWD={}".format(
                driver, server, database, uid, password),
            autocommit=False)
        return connection
    except Exception as e:
        logger.error("Error in db connection: " + str(e))
        return JsonResponse(output)