Sindbad~EG File Manager
from flask import Flask, request, Blueprint, jsonify, redirect, url_for,flash, render_template,session,Response,jsonify,json
from core.model.CMEPaymentModel import CMEPaymentModel
from random import randint
from core.library.email import EMAIL
from .. import Cryptography,Helper
from flask import session, app
from werkzeug.utils import secure_filename
import ast
from mandrill import Mandrill
from os.path import join, dirname,isfile, realpath
from datetime import datetime, timedelta
import os
import requests,mandrill,json,math,random
from itertools import groupby
from operator import itemgetter
from urllib.parse import unquote
import boto3, botocore
from botocore.exceptions import ClientError
import requests
app = Blueprint('cme_payment', __name__)
@app.route('/<int:conf_id>/<conf_key>/cme_delegate_info_mail/<user_uuid>', methods = ["GET", "POST"])
def CMEDelegateInfofMail(conf_id,conf_key,user_uuid):
conf_name = " "
conf_data = CMEPaymentModel().checkConfData_CMEPaymentModel(conf_id,conf_key)
if not conf_data :
error_msg = "Invalid URL"
return "<h3 style='color:red;text-align:center'>"+ error_msg +"</h3>"
return redirect(url_for('cme_payment.CMEMedicalCouncilLogin',conf_id=conf_id,conf_key=conf_key))
else:
conf_name = conf_data["conf_name"] or ''
conf_schema = conf_data['conf_schema']
delegate_data = CMEPaymentModel().delegateDataByUUID_CME(conf_id,conf_key,user_uuid,conf_schema)
if delegate_data :
data_1 = delegate_data
email = data_1["email"]
uuid = user_uuid
prefix = data_1["prefix"]
full_name_1 = data_1["full_name"] or ''
full_name = prefix + " " + full_name_1 if prefix else full_name_1
base_url = request.host_url
if "https" in base_url:
pass
else :
base_url = base_url.replace("http" , "https")
url_1 = base_url+str(conf_id)+"/"+conf_key+"/delegate_info/"+user_uuid
# url_1 = base_url+"mail_respond/"+uuid
html = render_template('cme_payment/email/delegate_info_mail.html', conf= conf_data,data=delegate_data,uuid=uuid,url_1=url_1)
if full_name :
subject = "Dear "+ full_name +", Very important! Confirmation required for "+ conf_name +" Conference"
else :
subject = "Very important! Confirmation required for "+ conf_name +" Conference"
# email = "ganesan@numerotec.com"
# print(email)
# return "please wait"
EMAIL.MCAcknowledgesendMail(subject,html,email,conf_data) # uncomment after testing
return "Email sent successfully."
@app.route('/<int:conf_id>/<conf_key>/cme_delegate_info/<user_uuid>', methods = ["GET", "POST"])
def CMEDelegateInfo(conf_id,conf_key,user_uuid):
conf_data = CMEPaymentModel().checkConfData_CMEPaymentModel(conf_id,conf_key)
conf_schema = conf_data['conf_schema']
enc_delegate_no = None
mc_state_id = None
if conf_id :
country_id = 101
states = CMEPaymentModel().getStates_CMEPaymentModel(country_id)
delegate_data = CMEPaymentModel().delegateDataByUUID_CME(conf_id,conf_key,user_uuid,conf_schema)
if delegate_data:
json_data = json.dumps(states,default =str)
mc_state_id = delegate_data["mc_state_id"]
enc_delegate_no = Cryptography.encrypt(delegate_data["delegate_no"])
# return str(mc_state_id)
return render_template('cme_payment/delegate_info.html',enc_delegate_no= enc_delegate_no,conf= conf_data,data=delegate_data,user_uuid=user_uuid,conf_id = conf_id,conf_key = conf_key,mc_state_id=mc_state_id,states=states)
else :
return "<h3 style='color:red;text-align:center'>Record does not exist.</h3>"
else :
return "<h3 style='color:red;text-align:center'>Invalid URL </h3>"
# Nov 14, 2023 start
@app.route('/cme_post_delegate_info', methods = ["GET", "POST"])
def CMEPostDelegateInfo():
now = datetime.now()
curr_dt = now.strftime("%Y-%m-%d %H:%M:%S")
curr_dt_1 = now.strftime("%d/%m/%Y, %H:%M:%S")
del_table_name = None
# curr_dt = "2023-03-25 15:30:00"
try:
enc_delegate_no = request.values.get("enc_delegate_no")
conf_id = request.values.get("conf_id")
conf_key = request.values.get("conf_key")
mc_number = request.values.get("mc_number") or ''
mc_state_id = request.values.get("mc_state_id") or ''
delegate_no = request.values.get("delegate_no")
user_uuid = request.values.get("user_uuid")
# Addedon Oct 04, 2023 start
email = request.values.get("email") or ' '
mobile = request.values.get("mobile") or ' '
prefix = request.values.get("prefix") or ' '
full_name = request.values.get("full_name") or ' '
full_name_1 = prefix +" "+full_name if prefix else full_name
# Addedon Oct 04, 2023 End
conf_id = int(conf_id) if conf_id else conf_id
conf_data = CMEPaymentModel().checkConfData_CMEPaymentModel(conf_id,conf_key)
conf_schema = conf_data['conf_schema']
if not conf_data :
flash("Invalid URL" , "errorMsg")
return redirect(url_for('cme_payment.CMEDelegateInfo',conf_id=conf_id,conf_key=conf_key,user_uuid=user_uuid))
else :
del_table_name = conf_data["del_table_name"]
if "'" in delegate_no:
delegate_no = delegate_no.replace("'", "")
delegate_no = int(delegate_no) if delegate_no else delegate_no
if "'" in mc_state_id:
mc_state_id = mc_state_id.replace("'", "")
mc_state_id = int(mc_state_id) if mc_state_id else mc_state_id
data_for_update={"mc_number":mc_number ,"mc_state_id" : mc_state_id , "updated_at" : curr_dt,"mc_data_updated_at" : curr_dt,"prefix" : prefix,"email" : email, "full_name" : full_name, "mobile" : mobile}
state_name = CMEPaymentModel().getMCState_CMEPaymentModel(mc_state_id)
if state_name :
state_name = state_name["state_name"]
else:
state_name = ""
# check duplicate email
check_email = CMEPaymentModel().check_delegates_email_CMEPaymentModel(conf_id,email,delegate_no,conf_schema)
enc_delegate_no = Cryptography.encrypt(delegate_no)
if check_email:
exist_email = check_email['email']
exist_mobile = check_email['mobile']
exist_name = check_email['prefix']+" "+check_email['full_name']
flash("The email you have provided is already mapped for <br> "+str(exist_name)+" ","errorMsg")
return redirect(url_for('cme_payment.CMEDelegateInfo',conf_id=conf_id,conf_key=conf_key,user_uuid=user_uuid))
else :
# check duplicate mobile
check_mobile = CMEPaymentModel().check_delegates_mobile_CMEPaymentModel(conf_id,mobile,delegate_no,conf_schema)
if check_mobile:
exist_email = check_mobile['email']
exist_mobile = check_mobile['mobile']
exist_name = check_mobile['prefix']+" "+check_mobile['full_name']
flash("The mobile number you have provided is already mapped for <br> "+str(exist_name)+" ","errorMsg")
return redirect(url_for('cme_payment.CMEDelegateInfo',conf_id=conf_id,conf_key=conf_key,user_uuid=user_uuid))
else:
pass
insert_data = CMEPaymentModel().insert_delegate_in_mc_delegates_CMEPaymentModel(conf_id,delegate_no,curr_dt,conf_schema) # before update delegate data first insert into mcc_delegates table
update_stmt = "UPDATE " +del_table_name+ " set full_name='"+full_name_1+"' ,email = '"+email+"',mobile = '"+mobile+"', mc_number= '" + mc_number+ "' , state = '"+ state_name+"' ,updated_at = '"+curr_dt+"' where delegate_no = " +str(delegate_no)+ " and conf_id = "+str(conf_id)+" "
update_mc_data = CMEPaymentModel().updateMCDataNew_CMEPaymentModel(data_for_update,delegate_no,conf_id,update_stmt,conf_schema)
if update_mc_data == "success" :
delegate_data = CMEPaymentModel().delegateDataByDelegateNo_CMEPaymentModel(conf_id,conf_key,delegate_no,conf_schema)
data = delegate_data
full_name_1 = data["prefix"] + " " + data["full_name"] if data["prefix"] else data["full_name"]
subject = "Dear "+ full_name_1 +", your medical council registration details have been updated at " + curr_dt_1
email = data["email"]
# email = "ganesan@numerotec.com" # please comment after testing
if email :
html = render_template('cme_payment/email/mc_updated_thanks_mail.html',data = data,conf= conf_data,email=email)
EMAIL.sendMail(subject,html,email,conf_data) # please uncomment after testing
return render_template('cme_payment/mc_thanks_screen.html',conf=conf_data)
flash("Thank you" , "successMsg")
return redirect(url_for('cme_payment.CMEMedicalCouncilLogin',conf_id=conf_id,conf_key=conf_key))
return render_template('cme_payment/mc_thanks_screen.html',conf=conf_data)
else :
return update_mc_data
return "<h3 style='color:red;text-align:center'>"+ update_mc_data +"</h3>"
except Exception as e:
return "<h3 style='color:red;text-align:center'>"+ str(e) +"</h3>"
# Nov 14, 2023 end
# -------------------------------------------------------------------------
@app.route('/<int:conf_id>/<conf_key>/cme_login', methods = ["GET", "POST"])
def CMEMedicalCouncilLogin(conf_id,conf_key):
conf_data = CMEPaymentModel().checkConfData_CMEPaymentModel(conf_id,conf_key)
if conf_data :
return render_template('cme_payment/login_by_delegateno.html',conf_id = conf_id,conf_key=conf_key,conf = conf_data)
else :
return "<h3 style='color:red;text-align:center'>Invalid URL </h3>"
@app.route('/<int:conf_id>/<conf_key>/cme_post_mc_detail_login', methods = ["GET", "POST"])
def CMEPostMedicalCouncilLogin(conf_id,conf_key):
conf_data = CMEPaymentModel().checkConfData_CMEPaymentModel(conf_id,conf_key)
conf_schema = conf_data['conf_schema']
delegate_no = request.values.get("delegate_no")
delegate_data = CMEPaymentModel().delegateDataByDelegateNo_CMEPaymentModel(conf_id,conf_key,delegate_no,conf_schema)
if delegate_data :
enc_delegate_no = Cryptography.encrypt(delegate_no)
return redirect(url_for('cme_payment.CMEDelegateMCInfo',enc_delegate_no =enc_delegate_no,conf_id=conf_id,conf_key=conf_key))
else :
flash("Record not found" , "errorMsg")
return redirect(url_for('cme_payment.CMEMedicalCouncilLogin',conf_id=conf_id,conf_key=conf_key))
mc_state_id = None
if conf_id :
country_id = 101
return render_template('cme_payment/login_by_delegateno.html',conf_id = conf_id,conf_key=conf_key)
else :
return "<h3 style='color:red;text-align:center'>Invalid URL </h3>"
@app.route('/cme_delegate_mc_info/<int:conf_id>/<conf_key>/<enc_delegate_no>', methods = ["GET", "POST"])
def CMEDelegateMCInfo(conf_id,conf_key,enc_delegate_no):
conf_data = CMEPaymentModel().checkConfData_CMEPaymentModel(conf_id,conf_key)
enc_delegate_no = unquote(enc_delegate_no)
payment_data = None
if conf_id :
delegate_no = Cryptography.decrypt(enc_delegate_no)
conf_schema = conf_data['conf_schema']
delegate_data = CMEPaymentModel().get_cme_delegate_data(conf_id,delegate_no)
for index,value in enumerate(delegate_data):
print(index,value,"\n")
if index == 0:
states_db = value
if index == 1:
del_data_db = value[0]
if index == 2:
check_status = value[0]
if index == 3:
payment_data = value
if payment_data is None:
del_data_db = del_data_db
else :
del_data_db = payment_data[0]
return render_template('cme_payment/mc_delegate_info.html',conf=conf_data,check_status=check_status,data=del_data_db,delegate_no=delegate_no,enc_delegate_no=enc_delegate_no,conf_id = conf_id,conf_key = conf_key,states=states_db)
else :
return "<h3 style='color:red;text-align:center'>Invalid URL </h3>"
@app.route('/<int:conf_id>/<conf_key>/cme_post_mc_delegate_info', methods = ["GET", "POST"])
def CMEPostMCDelegateInfo(conf_id,conf_key):
now = datetime.now()
curr_dt = now.strftime("%Y-%m-%d %H:%M:%S")
curr_dt_1 = now.strftime("%d/%m/%Y, %H:%M:%S")
del_table_name = None
# curr_dt = "2023-03-25 15:30:00"
try:
conf_data = CMEPaymentModel().checkConfData_CMEPaymentModel(conf_id,conf_key)
conf_schema = conf_data['conf_schema']
if not conf_data :
return redirect(url_for('cme_payment.CMEMedicalCouncilLogin',conf_id=conf_id,conf_key=conf_key))
delegate_id = request.values.get("delegate_id")
if delegate_id :
check_cme_payment = CMEPaymentModel().check_cme_payment(conf_id,delegate_id,conf_schema)
if check_cme_payment:
del_id = check_cme_payment['delegate_id']
else :
del_id = None
if del_id == None :
enc_delegate_no = request.values.get("enc_delegate_no")
delegate_no = request.values.get("delegate_no")
user_id = request.values.get('user_id')
mc_number = request.values.get("mc_number")
mc_state_id = request.values.get("mc_state_id")
utr_number = request.values.get('utr_no') or None
payment_method = request.values.get('payment_method')
email = request.values.get("email")
mobile = request.values.get("mobile")
prefix = request.values.get("prefix")
full_name = request.values.get("full_name")
full_name_1 = prefix +" "+full_name if prefix else full_name
conf_id = int(conf_id) if conf_id else conf_id
if "'" in delegate_no:
delegate_no = delegate_no.replace("'", "")
delegate_no = int(delegate_no)
if "'" in mc_state_id:
mc_state_id = mc_state_id.replace("'", "")
mc_state_id = int(mc_state_id) if mc_state_id else mc_state_id
data_for_update = {'is_cme_paid':1,"mc_number":mc_number ,"mc_state_id" : mc_state_id , "updated_at" : curr_dt,"mc_data_updated_at" : curr_dt}
state_name = CMEPaymentModel().getMCState_CMEPaymentModel(mc_state_id)
if state_name :
state_name = state_name["state_name"]
else:
state_name = ""
enc_delegate_no = Cryptography.encrypt(delegate_no)
insert_data = CMEPaymentModel().insert_delegate_in_mc_delegates_CMEPaymentModel(conf_id,delegate_no,curr_dt,conf_schema)
update_stmt = None
update_mc_data = CMEPaymentModel().updateMCDataNew_CMEPaymentModel(data_for_update,delegate_no,conf_id,update_stmt,conf_schema)
if update_mc_data == "success" :
file = request.files.get('files',None)
if file :
acl ="public-read"
s3 = boto3.client("s3",aws_access_key_id='AKIAILLDAQ7NFUMVOYLQ',aws_secret_access_key='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')
filename = secure_filename(file.filename)
file_extension = os.path.splitext(filename)[1]
file_str = "cme_payment_proof"+file_extension
if " " in file_str :
file_str = file_str.replace(" ","")
else :
pass
try:
bucket = "delegateapp"
foldername = "cme_payment_attachment"
file_path = "https://"+bucket+".s3-ap-southeast-1.amazonaws.com/"+foldername+"/"+str(conf_key)+"/"+str(delegate_no)
response = s3.upload_fileobj(file, bucket,foldername+'/'+str(conf_key)+'/'+str(delegate_no)+'/'+ file_str, ExtraArgs={"ACL": acl,"ContentType": file.content_type})
attach_path = file_path
attach_file_name = file_str
except ClientError as e:
logging.error(e)
msg = 'Please try again... '
status = 0
else:
attach_path = None
attach_file_name = None
now = datetime.now()
dt_string = now.strftime("%Y-%m-%d %H:%M:%S")
society_id = conf_data['society_id']
if delegate_id:
delegate = CMEPaymentModel().get_delegate(delegate_id,conf_id,conf_data.get('conf_schema'))
name = delegate['full_name']
prefix = delegate['prefix']
full_name = prefix + " " + name if prefix else name
email = delegate['email']
mobile = delegate['mobile']
unique_id = now.strftime('%Y%m%d%H%M%S')
created_at = now
url = conf_data['paymentgateway_api_url']
r = requests.get(url)
apikey = json.loads(r.content.decode())
am_id = conf_data['paymentgateway_appmaster_id']
is_test = conf_data['paymentgateway_is_test']
for index,value in enumerate(apikey) :
api_am_id = value['am_id']
if api_am_id == am_id:
app_key = value['app_key']
app_name = value['app_name']
break
else:
pass
payment_for = app_name
unique_id = app_key+"_"+unique_id
print("unique_id = ",unique_id)
delegate_id = delegate_id
app_type = "CME"
is_generate = 1
update_payment_proof = {
'attach_path' : attach_path,
'attach_file_name': attach_file_name,
'unique_id' : unique_id,
'created_at' : now,
'attach_type' : 'payment_proof',
'delegate_id' : delegate_id,
'conf_id' : conf_id,
'user_id' : user_id
}
if attach_path and attach_file_name:
update_data = CMEPaymentModel().insert_payment_screenshot(update_payment_proof)
remarks = None
amount = 300
generate_payement = CMEPaymentModel().usp_conf_cme_generate_payment(unique_id,delegate_id,user_id,payment_for,payment_method,remarks,full_name,email,mobile,is_generate,created_at,utr_number,society_id,app_type,conf_id,amount)
delegate_data = CMEPaymentModel().delegateDataByDelegateNo_CMEPaymentModel(conf_id,conf_key,delegate_no,conf_schema)
data = delegate_data
# cmail function starts
full_name_1 = data["prefix"] + " " + data["full_name"] if data["prefix"] else data["full_name"]
subject = "Dear "+ full_name_1 +", your medical council registration details have been updated at " + curr_dt_1
email = data["email"]
if email :
html = render_template('mc_details/email/mc_updated_thanks_mail.html',data = data,conf= conf_data,email=email)
# return html
# EMAIL.sendMail(subject,html,email,conf_data) # please uncomment after testing
flash("Thank you" , "successMsg")
return render_template('cme_payment/mc_thanks_screen.html',conf=conf_data,conf_id=conf_id,conf_key=conf_key)
else :
return update_mc_data
return "<h3 style='color:red;text-align:center'>"+ update_mc_data +"</h3>"
else :
return "<h3 style='color:red;text-align:center'>Already Registered</h3>"
except Exception as e:
return "<h3 style='color:red;text-align:center'>"+ str(e) +"</h3>"
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists