Browse Source

publihs -json key, temporary login

master
Ubuntu 2 years ago
parent
commit
a7e393ce6f
  1. 292
      smart_service/apis/app_user_login.py
  2. 97
      smart_service/apis/publish_api.py

292
smart_service/apis/app_user_login.py

@ -12,7 +12,7 @@ current_db_name = frappe.conf.get("db_name")
# Temporary Login
@frappe.whitelist(allow_guest=True)
def app_user_validation():
def app_user_validation_test():
dicData= {}
try:
doc = frappe.get_doc("Fish", None)
@ -22,153 +22,153 @@ def app_user_validation():
return {'status': 0, 'error': 'Site Error'}
return dicData
# @frappe.whitelist(allow_guest=True)
# def app_user_validation(usr=None, pwd=None):
# if usr == None and pwd == None:
# return {'status': 0, 'error': "Parameter's missing: Usr & pwd"}
# if usr == None:
# return {'status': 0, 'error': "Parameter missing: Usr"}
# if pwd == None:
# return {'status': 0, 'error': "Parameter missing: Pwd"}
# preference = frappe.get_last_doc('App Preference')
# mahindra_login = preference.mahindra_login_api
# technician_login = preference.technician_login_api
@frappe.whitelist(allow_guest=True)
def app_user_validation(usr=None, pwd=None):
if usr == None and pwd == None:
return {'status': 0, 'error': "Parameter's missing: Usr & pwd"}
if usr == None:
return {'status': 0, 'error': "Parameter missing: Usr"}
if pwd == None:
return {'status': 0, 'error': "Parameter missing: Pwd"}
preference = frappe.get_last_doc('App Preference')
mahindra_login = preference.mahindra_login_api
technician_login = preference.technician_login_api
# try:
# data = {'LoginID': usr, 'Password': pwd}
# headers = {"Content-Type": "application/x-www-form-urlencoded"}
# if technician_login == 1 and mahindra_login == 0:
# response = requests.post(
# "http://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
# decoded = response.content.decode('utf-8')
# if len(decoded) > 165:
# da = re.search("{", decoded)
# da1 = re.search("}", decoded)
# trunData = decoded[da.span()[0]:da1.span()[1]]
# dicData = json.loads(trunData)
# doc = frappe.get_doc("Fish", None)
# dicData['token'] = doc.apple
# dicData['status'] = 1
# if dicData['ID'] == "":
# dicData['ID'] = "100"
# return dicData
# else:
# return {'status': 0, 'error': 'Invalid Credentials'}
# elif technician_login == 0 and mahindra_login == 1:
# response1 = requests.post("http://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
# data=data, headers=headers)
# decoded1 = response1.content.decode('utf-8')
# node = ET.fromstring(decoded1)
# dictValue = xml_to_dict(node)
# dicData = {
# "ID": "{}@email.com".format(usr),
# "LoginName": usr,
# "FirstName": "",
# "LastName": "",
# "IsActive": "True",
# "UserType": "",
# "SkillID": "",
# "SkillName": "",
# "UserTypeDesc": "",
# "PasswordChanged": "",
# "AreaName": "",
# "Zone": "",
# "Code": "",
# "LocationName": "",
# "ChannelNo": "",
# "ServerDate": "",
# "ServerTime": "",
# "DealerName": "",
# "EmailId": "{}@email.com".format(usr),
# "isLDAPAuthenticated": ""}
# success_msg = None
# user_name = None
# msgDic = {}
# try:
# msgDic['UserName'] = dictValue['children']['UserName']['text']
# msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text']
# doc = frappe.get_doc("Fish", None)
# dicData['token'] = doc.apple
# dicData['status'] = 1
# if dicData['ID'] == "":
# dicData['ID'] = "100"
# return dicData
# except:
# msgDic['IsSuccessfull'] = node.text
# return {'status': 0, 'error': 'Invalid Credentials'}
# elif technician_login == 1 and mahindra_login == 1:
# response = requests.post(
# "http://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
# decoded = response.content.decode('utf-8')
# response1 = requests.post("http://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
# data=data, headers=headers)
# decoded1 = response1.content.decode('utf-8')
# node = ET.fromstring(decoded1)
# dictValue = xml_to_dict(node)
# dicData = {
# "ID": "",
# "LoginName": usr,
# "FirstName": usr,
# "LastName": "",
# "IsActive": "True",
# "UserType": "",
# "SkillID": "",
# "SkillName": "",
# "UserTypeDesc": "Mahindra User",
# "PasswordChanged": "",
# "AreaName": "Mahindra",
# "Zone": "Mahindra",
# "LocationName": "Mahindra",
# "ChannelNo": "",
# "ServerDate": "",
# "ServerTime": "",
# "DealerName": "Mahindra",
# "EmailId": "{}@mahindra.com".format(usr),
# "isLDAPAuthenticated": ""}
# success_msg = None
# user_name = None
# msgDic = {}
# if len(decoded) > 165:
# da = re.search("{", decoded)
# da1 = re.search("}", decoded)
# trunData = decoded[da.span()[0]:da1.span()[1]]
# dicData = json.loads(trunData)
# doc = frappe.get_doc("Fish", None)
# dicData['token'] = doc.apple
# dicData['status'] = 1
# if dicData['ID'] == "":
# dicData['ID'] = "100"
# return dicData
try:
data = {'LoginID': usr, 'Password': pwd}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
if technician_login == 1 and mahindra_login == 0:
response = requests.post(
"http://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
decoded = response.content.decode('utf-8')
if len(decoded) > 165:
da = re.search("{", decoded)
da1 = re.search("}", decoded)
trunData = decoded[da.span()[0]:da1.span()[1]]
dicData = json.loads(trunData)
doc = frappe.get_doc("Fish", None)
dicData['token'] = doc.apple
dicData['status'] = 1
if dicData['ID'] == "":
dicData['ID'] = "100"
return dicData
else:
return {'status': 0, 'error': 'Invalid Credentials'}
elif technician_login == 0 and mahindra_login == 1:
response1 = requests.post("http://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
data=data, headers=headers)
decoded1 = response1.content.decode('utf-8')
node = ET.fromstring(decoded1)
dictValue = xml_to_dict(node)
dicData = {
"ID": "{}@email.com".format(usr),
"LoginName": usr,
"FirstName": "",
"LastName": "",
"IsActive": "True",
"UserType": "",
"SkillID": "",
"SkillName": "",
"UserTypeDesc": "",
"PasswordChanged": "",
"AreaName": "",
"Zone": "",
"Code": "",
"LocationName": "",
"ChannelNo": "",
"ServerDate": "",
"ServerTime": "",
"DealerName": "",
"EmailId": "{}@email.com".format(usr),
"isLDAPAuthenticated": ""}
success_msg = None
user_name = None
msgDic = {}
try:
msgDic['UserName'] = dictValue['children']['UserName']['text']
msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text']
doc = frappe.get_doc("Fish", None)
dicData['token'] = doc.apple
dicData['status'] = 1
if dicData['ID'] == "":
dicData['ID'] = "100"
return dicData
except:
msgDic['IsSuccessfull'] = node.text
return {'status': 0, 'error': 'Invalid Credentials'}
elif technician_login == 1 and mahindra_login == 1:
response = requests.post(
"http://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers)
decoded = response.content.decode('utf-8')
response1 = requests.post("http://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential",
data=data, headers=headers)
decoded1 = response1.content.decode('utf-8')
node = ET.fromstring(decoded1)
dictValue = xml_to_dict(node)
dicData = {
"ID": "",
"LoginName": usr,
"FirstName": usr,
"LastName": "",
"IsActive": "True",
"UserType": "",
"SkillID": "",
"SkillName": "",
"UserTypeDesc": "Mahindra User",
"PasswordChanged": "",
"AreaName": "Mahindra",
"Zone": "Mahindra",
"LocationName": "Mahindra",
"ChannelNo": "",
"ServerDate": "",
"ServerTime": "",
"DealerName": "Mahindra",
"EmailId": "{}@mahindra.com".format(usr),
"isLDAPAuthenticated": ""}
success_msg = None
user_name = None
msgDic = {}
if len(decoded) > 165:
da = re.search("{", decoded)
da1 = re.search("}", decoded)
trunData = decoded[da.span()[0]:da1.span()[1]]
dicData = json.loads(trunData)
doc = frappe.get_doc("Fish", None)
dicData['token'] = doc.apple
dicData['status'] = 1
if dicData['ID'] == "":
dicData['ID'] = "100"
return dicData
# else:
# try:
# msgDic['UserName'] = dictValue['children']['UserName']['text']
# msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text']
# doc = frappe.get_doc("Fish", None)
# dicData['token'] = doc.apple
# dicData['status'] = 1
# if dicData['ID'] == "":
# dicData['ID'] = "100"
# return dicData
# except:
# return {'status': 0, 'error': 'Invalid Credentials'}
# else:
# return {'status': 0, 'error': 'Login Blocked'}
# except:
# return {'status': 0, 'error': 'Site Error'}
else:
try:
msgDic['UserName'] = dictValue['children']['UserName']['text']
msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text']
doc = frappe.get_doc("Fish", None)
dicData['token'] = doc.apple
dicData['status'] = 1
if dicData['ID'] == "":
dicData['ID'] = "100"
return dicData
except:
return {'status': 0, 'error': 'Invalid Credentials'}
else:
return {'status': 0, 'error': 'Login Blocked'}
except:
return {'status': 0, 'error': 'Site Error'}
def xml_to_dict(node):

97
smart_service/apis/publish_api.py

@ -11,6 +11,8 @@ current_db_name = frappe.conf.get("db_name")
site_name = cstr(frappe.local.site)
base_url = os.path.expanduser("~") + "/frappe-bench/sites/" + site_name + "/public"
internal_path = base_url + '/files/json_files/internal/'
global_path = base_url + '/files/json_files/global/'
class Publish(Document):
pass
@ -58,6 +60,7 @@ def api_procedure(args, vehicle, language, version):
def json_grouping(args, language):
dicfinal = []
docs_child = frappe.db.get_list('Publish_Docs', filters={'parent': args},
fields=['variant_mapping', 'system', 'sub_system', 'procedure_status',
'procedure_link'])
@ -181,8 +184,98 @@ def json_grouping(args, language):
variant_out['Variant']['Systems'] = system_out
final.append(variant_out)
dicfinal = {'JSON': final}
frappe.db.sql(""" UPDATE %s.tabPublish SET publish_status = '%s' where name = '%s' """ % (
current_db_name, 'Published', args))
frappe.db.commit()
return final
return dicfinal
def print(sts):
frappe.msgprint(str(sts))
""" New Publish """
@frappe.whitelist(allow_guest=True)
def new_publish(args, publish_type, vehicle, language, version):
publish_json = get_data(args)
try:
if not os.path.exists(internal_path + vehicle + '/'):
os.makedirs(internal_path + vehicle + '/')
if not os.path.exists(global_path + vehicle + '/'):
os.makedirs(global_path + vehicle + '/')
except Exception as e:
return {"status": 0, "error": "Failed to create Folders"}
file_ver = '%s-%s_v%s.json' % (vehicle, language, version)
if publish_type.lower() == 'internal':
file_name = internal_path + vehicle + '/' + file_ver
elif publish_type.lower() == 'global':
file_name = global_path + vehicle + '/' + file_ver
else:
return {"status": 0, 'error': 'Publish type not available'}
with open(file_name, 'w') as outfile:
outfile.write(json.dumps(publish_json))
list1 = []
if publish_type.lower() == 'internal':
for fil in os.listdir(internal_path + vehicle):
file_val = internal_path + vehicle + '/' + fil
if file_val != file_name:
if (fil.split('-')[1]).split('_')[0] == language:
list1.append(fil)
os.remove(file_val)
return file_name
def get_data(args):
try:
docs_child = frappe.db.get_list('Publish_Docs', filters={'parent': args},
fields=['variant_mapping', 'system', 'sub_system', 'procedure_status',
'procedure_link'])
except Exception as e:
return False
return docs_child
@frappe.whitelist(allow_guest=True)
def new_update(vehicle_list=None):
req_list = json.loads(vehicle_list)
vehicle = req_list['Vehicle']
iid = req_list['InstallationId']
vehicle_data = req_list['VehicleReqList']
list_val = []
json_val = []
for v in vehicle_data:
lang = v['LanguageID']
cur_ver = v['CurrentVersion']
# publish_list = frappe.db.sql(''' SELECT vehicle,`language`,version,publish_type FROM tabPublish where vehicle = '{}'
# and publish_type='Global' AND `language` = '{}';'''.format(vehicle,lang),as_dict=True)
# list_val.append(publish_list)
for f in os.listdir(internal_path + vehicle):
try:
if (f.split('-')[1]).split('_')[0] == lang:
json_data = json.load(open(internal_path + vehicle +'/'+f))
for d in json_data:
json_val.append(d)
except:
pass
for i in os.listdir(global_path + vehicle):
try:
if (i.split('-')[1]).split('_')[0] == lang:
json_data = json.load(open(global_path + vehicle +'/'+f))
for d in json_data:
json_val.append(d)
except:
pass
cumulative_update = global_path + vehicle+ '/' + 'global.json'
with open(cumulative_update,'w') as outfile:
outfile.write(json.dumps(json_val))
return json_val
Loading…
Cancel
Save