|
|
@ -32,18 +32,16 @@ def custom_rate_limit(limit, seconds): |
|
|
|
return 1 |
|
|
|
|
|
|
|
# Temporary Login |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist(allow_guest=True) |
|
|
|
def app_user_validation_test(): |
|
|
|
dicData = {} |
|
|
|
try: |
|
|
|
doc = frappe.get_doc("Fish", None) |
|
|
|
dicData['token'] = doc.apple |
|
|
|
dicData['status'] = 1 |
|
|
|
except: |
|
|
|
return {'status': 0, 'error': 'Site Error'} |
|
|
|
return dicData |
|
|
|
# @frappe.whitelist(allow_guest=True) |
|
|
|
# def app_user_validation_test(): |
|
|
|
# dicData = {} |
|
|
|
# try: |
|
|
|
# doc = frappe.get_doc("Fish", None) |
|
|
|
# dicData['token'] = doc.apple |
|
|
|
# dicData['status'] = 1 |
|
|
|
# except: |
|
|
|
# return {'status': 0, 'error': 'Site Error'} |
|
|
|
# return dicData |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist(allow_guest=True) |
|
|
@ -60,13 +58,12 @@ def app_user_validation(usr=None, pwd=None): |
|
|
|
technician_login = preference.technician_login_api |
|
|
|
|
|
|
|
# ISmartAuth API - Email available |
|
|
|
|
|
|
|
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) |
|
|
|
"https://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers) |
|
|
|
decoded = response.content.decode('utf-8') |
|
|
|
|
|
|
|
if len(decoded) > 165: |
|
|
@ -85,7 +82,7 @@ def app_user_validation(usr=None, pwd=None): |
|
|
|
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", |
|
|
|
response1 = requests.post("https://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential", |
|
|
|
data=data, headers=headers) |
|
|
|
decoded1 = response1.content.decode('utf-8') |
|
|
|
node = ET.fromstring(decoded1) |
|
|
@ -131,10 +128,10 @@ def app_user_validation(usr=None, pwd=None): |
|
|
|
|
|
|
|
elif technician_login == 1 and mahindra_login == 1: |
|
|
|
response = requests.post( |
|
|
|
"http://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers) |
|
|
|
"https://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", |
|
|
|
response1 = requests.post("https://www.mahindramile.com/WindowAuth/Service.asmx/ValidateCredential", |
|
|
|
data=data, headers=headers) |
|
|
|
decoded1 = response1.content.decode('utf-8') |
|
|
|
node = ET.fromstring(decoded1) |
|
|
@ -218,7 +215,6 @@ def grant_user_access(userdata=None, iid=None): |
|
|
|
area_name = userdata['AreaName'] |
|
|
|
zone = userdata['Zone'] |
|
|
|
dealer_code = userdata['Code'] |
|
|
|
|
|
|
|
dealer_name = userdata['DealerName'] |
|
|
|
|
|
|
|
app_current_version = userdata['AppCurrentVersion'] |
|
|
@ -234,9 +230,7 @@ def grant_user_access(userdata=None, iid=None): |
|
|
|
frappe.set_user("Administrator") |
|
|
|
user_name = frappe.db.sql('''SELECT name FROM {0}.tabUser where email='{1}';'''.format( |
|
|
|
current_db_name, email), as_dict=1) |
|
|
|
# return user_name |
|
|
|
if user_name: |
|
|
|
# token = generate_keys(user_name[0]['name']) |
|
|
|
try: |
|
|
|
""" New Refresh token update """ |
|
|
|
access_token = generate_access_token(user_name[0]['name']) |
|
|
@ -259,7 +253,6 @@ def grant_user_access(userdata=None, iid=None): |
|
|
|
user_name = frappe.db.sql('''SELECT name FROM {0}.tabUser where email='{1}';'''.format( |
|
|
|
current_db_name, email), as_dict=1) |
|
|
|
if user_name: |
|
|
|
# token = generate_keys(user_name[0]['name']) |
|
|
|
try: |
|
|
|
""" New Refresh token update """ |
|
|
|
access_token = generate_access_token(user_name[0]['name']) |
|
|
@ -306,16 +299,6 @@ def grant_user_access(userdata=None, iid=None): |
|
|
|
|
|
|
|
'''Inserting Device data''' |
|
|
|
if iid == 'None' or iid == 'null': |
|
|
|
app_device = frappe.new_doc('App Device') |
|
|
|
app_device.device_id = device_id |
|
|
|
app_device.publish_type = "Global" |
|
|
|
app_device.device_type = device_type |
|
|
|
app_device.os = os |
|
|
|
app_device.os_version = os_version |
|
|
|
app_device.app_current_version = app_current_version |
|
|
|
app_device.last_login = now() |
|
|
|
app_device.insert() |
|
|
|
|
|
|
|
if frappe.db.exists({'doctype': 'App Device', 'device_id': device_id}): |
|
|
|
frappe.db.sql( |
|
|
|
'''UPDATE {2}.`tabApp Device` SET active_status= "{1}" where device_id = "{0}";'''.format(device_id, |
|
|
@ -328,21 +311,27 @@ def grant_user_access(userdata=None, iid=None): |
|
|
|
app_device1 = frappe.get_last_doc( |
|
|
|
'App Device', filters={"device_id": device_id}) |
|
|
|
|
|
|
|
app_device = frappe.new_doc('App Device') |
|
|
|
app_device.device_id = device_id |
|
|
|
app_device.publish_type = "Global" |
|
|
|
app_device.device_type = device_type |
|
|
|
app_device.os = os |
|
|
|
app_device.os_version = os_version |
|
|
|
app_device.app_current_version = app_current_version |
|
|
|
app_device.last_login = now() |
|
|
|
app_device.insert() |
|
|
|
|
|
|
|
app_logs = frappe.new_doc('App Log') |
|
|
|
app_logs.user = app_user1.name |
|
|
|
app_logs.device = app_device.name |
|
|
|
app_logs.type = 'Reinstalled' |
|
|
|
app_logs.latitude = latitude |
|
|
|
app_logs.longitude = longitude |
|
|
|
# app_logs.active_status = 'Active' |
|
|
|
app_logs.date_time_stamp = now() |
|
|
|
app_logs.insert() |
|
|
|
|
|
|
|
app_device_tmp = frappe.get_last_doc( |
|
|
|
'App Device', filters={"device_id": device_id}) |
|
|
|
frappe.db.sql('''UPDATE {2}.`tabApp Device` SET active_status= "{1}" where name = "{0}";'''.format( |
|
|
|
app_device_tmp.name, "Active", current_db_name)) |
|
|
|
frappe.db.commit() |
|
|
|
|
|
|
|
app_logs3 = frappe.new_doc('App Log') |
|
|
|
app_logs3.user = app_user1.name |
|
|
@ -354,6 +343,16 @@ def grant_user_access(userdata=None, iid=None): |
|
|
|
app_logs3.insert() |
|
|
|
|
|
|
|
else: |
|
|
|
app_device = frappe.new_doc('App Device') |
|
|
|
app_device.device_id = device_id |
|
|
|
app_device.publish_type = "Global" |
|
|
|
app_device.device_type = device_type |
|
|
|
app_device.os = os |
|
|
|
app_device.os_version = os_version |
|
|
|
app_device.app_current_version = app_current_version |
|
|
|
app_device.last_login = now() |
|
|
|
app_device.insert() |
|
|
|
|
|
|
|
app_user1 = frappe.get_last_doc( |
|
|
|
'App Users', filters={"email_id": email}) |
|
|
|
app_device1 = frappe.get_last_doc( |
|
|
@ -362,7 +361,6 @@ def grant_user_access(userdata=None, iid=None): |
|
|
|
app_logs.user = app_user1.name |
|
|
|
app_logs.device = app_device.name |
|
|
|
app_logs.type = 'Installed' |
|
|
|
# app_logs.active_status = 'Active' |
|
|
|
app_logs.latitude = latitude |
|
|
|
app_logs.longitude = longitude |
|
|
|
app_logs.date_time_stamp = now() |
|
|
@ -378,9 +376,6 @@ def grant_user_access(userdata=None, iid=None): |
|
|
|
app_logs4.save() |
|
|
|
|
|
|
|
else: |
|
|
|
# frappe.db.sql( |
|
|
|
# '''UPDATE {4}.`tabApp Device` set last_login= '{0}', user_name = '{2}', device_type = '{3}' where name = "{1}";'''.format( |
|
|
|
# now(), iid, email, user_type_desc, current_db_name)) |
|
|
|
frappe.db.sql( |
|
|
|
'''UPDATE {3}.`tabApp Device` set last_login= '{0}', device_type = '{2}' where name = "{1}";'''.format( |
|
|
|
now(), iid, device_type, current_db_name)) |
|
|
@ -406,7 +401,6 @@ def grant_user_access(userdata=None, iid=None): |
|
|
|
user_details = {} |
|
|
|
user_details['Installation ID'] = lst[0][0] |
|
|
|
user_details['User ID'] = lst1[0][0] |
|
|
|
# user_details['token'] = token |
|
|
|
user_details['status'] = 1 |
|
|
|
user_details['token_details'] = token_details |
|
|
|
return user_details |
|
|
@ -416,16 +410,178 @@ def grant_user_access(userdata=None, iid=None): |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist(allow_guest=True) |
|
|
|
def new_grant_user_access(userdata=None, iid=None): |
|
|
|
def data_invalidation(email, device_id, iid=None): |
|
|
|
rate_res = custom_rate_limit(limit=5, seconds=15) |
|
|
|
if rate_res != 1: |
|
|
|
return rate_res |
|
|
|
val = input_validation(userdata=userdata, iid=iid) |
|
|
|
try: |
|
|
|
# User validation |
|
|
|
frappe.set_user("Administrator") |
|
|
|
user_name = frappe.db.sql('''SELECT name FROM {0}.tabUser where email='{1}';'''.format( |
|
|
|
current_db_name, email), as_dict=1) |
|
|
|
|
|
|
|
token_details = [] |
|
|
|
if user_name: |
|
|
|
|
|
|
|
""" New Refresh token update """ |
|
|
|
access_token = generate_access_token(user_name[0]['name']) |
|
|
|
refresh_token = generate_refresh_token() |
|
|
|
token_details = update_tokens_in_doc( |
|
|
|
user_name[0]['name'], access_token, refresh_token) |
|
|
|
|
|
|
|
return {'status': 1, 'data': token_details, 'error': None} |
|
|
|
|
|
|
|
except Exception as e1: |
|
|
|
return {'status': 0, 'data': [], 'error': 'Failed to verify user'} |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist(allow_guest=True) |
|
|
|
def new_app_user_validation(usr=None, pwd=None, iid=None, device_data=None): |
|
|
|
rate_res = custom_rate_limit(limit=5, seconds=15) |
|
|
|
if rate_res != 1: |
|
|
|
return rate_res |
|
|
|
val = input_validation(usr=usr, pwd=pwd, iid=iid, device_data=device_data) |
|
|
|
if val != '': |
|
|
|
return {'status': 0, 'error': "Parameter's missing: " + val} |
|
|
|
|
|
|
|
preference = frappe.get_last_doc('App Preference') |
|
|
|
mahindra_login = preference.mahindra_login_api |
|
|
|
technician_login = preference.technician_login_api |
|
|
|
|
|
|
|
# ISmartAuth API - Email available |
|
|
|
device_data = json.loads(device_data) |
|
|
|
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( |
|
|
|
"https://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers) |
|
|
|
decoded = response.content.decode('utf-8') |
|
|
|
|
|
|
|
if len(decoded) > 165: |
|
|
|
frappe.set_user("Administrator") |
|
|
|
da = re.search("{", decoded) |
|
|
|
da1 = re.search("}", decoded) |
|
|
|
trunData = decoded[da.span()[0]:da1.span()[1]] |
|
|
|
|
|
|
|
dicData = json.loads(trunData) |
|
|
|
if dicData['ID'] == "": |
|
|
|
dicData['ID'] = "100" |
|
|
|
dicData.update(device_data) |
|
|
|
|
|
|
|
return new_grant_user_access(dicData, iid) |
|
|
|
else: |
|
|
|
return {'status': 0, 'error': 'Invalid Credentials'} |
|
|
|
|
|
|
|
elif technician_login == 0 and mahindra_login == 1: |
|
|
|
response1 = requests.post("https://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) |
|
|
|
frappe.set_user("Administrator") |
|
|
|
dicData = { |
|
|
|
"ID": "{}@email.com".format(usr), |
|
|
|
"LoginName": usr, |
|
|
|
"FirstName": usr, |
|
|
|
"LastName": "", |
|
|
|
"IsActive": "True", |
|
|
|
"UserType": "", |
|
|
|
"SkillID": "", |
|
|
|
"SkillName": "", |
|
|
|
"UserTypeDesc": "", |
|
|
|
"PasswordChanged": "", |
|
|
|
"AreaName": "", |
|
|
|
"Zone": "", |
|
|
|
"Code": "", |
|
|
|
"LocationName": "", |
|
|
|
"ChannelNo": "", |
|
|
|
"ServerDate": "", |
|
|
|
"ServerTime": "", |
|
|
|
"DealerName": "", |
|
|
|
"EmailId": "{}@email.com".format(usr), |
|
|
|
"isLDAPAuthenticated": ""} |
|
|
|
dicData.update(device_data) |
|
|
|
msgDic = {} |
|
|
|
|
|
|
|
try: |
|
|
|
msgDic['UserName'] = dictValue['children']['UserName']['text'] |
|
|
|
msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text'] |
|
|
|
if dicData['ID'] == "": |
|
|
|
dicData['ID'] = "100" |
|
|
|
return new_grant_user_access(dicData, iid) |
|
|
|
|
|
|
|
except: |
|
|
|
msgDic['IsSuccessfull'] = node.text |
|
|
|
return {'status': 0, 'error': 'Invalid Credentials'} |
|
|
|
|
|
|
|
elif technician_login == 1 and mahindra_login == 1: |
|
|
|
response = requests.post( |
|
|
|
"https://www.mahindramile.com/ISmartAuth/Service.asmx/ValidateCredential", data=data, headers=headers) |
|
|
|
decoded = response.content.decode('utf-8') |
|
|
|
|
|
|
|
response1 = requests.post("https://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": ""} |
|
|
|
|
|
|
|
msgDic = {} |
|
|
|
if len(decoded) > 165: |
|
|
|
frappe.set_user("Administrator") |
|
|
|
da = re.search("{", decoded) |
|
|
|
da1 = re.search("}", decoded) |
|
|
|
trunData = decoded[da.span()[0]:da1.span()[1]] |
|
|
|
dicData = json.loads(trunData) |
|
|
|
dicData['Code'] = "" |
|
|
|
if dicData['ID'] == "": |
|
|
|
dicData['ID'] = "100" |
|
|
|
|
|
|
|
dicData.update(device_data) |
|
|
|
return new_grant_user_access(dicData, iid) |
|
|
|
|
|
|
|
else: |
|
|
|
frappe.set_user("Administrator") |
|
|
|
msgDic['UserName'] = dictValue['children']['UserName']['text'] |
|
|
|
msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text'] |
|
|
|
if dicData['ID'] == "": |
|
|
|
dicData['ID'] = "100" |
|
|
|
dicData['Code'] = '' |
|
|
|
dicData.update(device_data) |
|
|
|
return new_grant_user_access(dicData, iid) |
|
|
|
|
|
|
|
else: |
|
|
|
return {'status': 0, 'error': 'Login Blocked'} |
|
|
|
except: |
|
|
|
return {'status': 0, 'error': 'Site Error'} |
|
|
|
|
|
|
|
|
|
|
|
def new_grant_user_access(userdata=None, iid=None): |
|
|
|
rate_res = custom_rate_limit(limit=5, seconds=15) |
|
|
|
if rate_res != 1: |
|
|
|
return rate_res |
|
|
|
try: |
|
|
|
userdata = json.loads(userdata) |
|
|
|
user_id = userdata['ID'] |
|
|
|
email = userdata['EmailId'] |
|
|
|
first_name = userdata['FirstName'] |
|
|
@ -456,17 +612,15 @@ def new_grant_user_access(userdata=None, iid=None): |
|
|
|
frappe.set_user("Administrator") |
|
|
|
user_name = frappe.db.sql('''SELECT name FROM {0}.tabUser where email='{1}';'''.format( |
|
|
|
current_db_name, email), as_dict=1) |
|
|
|
# return user_name |
|
|
|
|
|
|
|
if user_name: |
|
|
|
# token = generate_keys(user_name[0]['name']) |
|
|
|
try: |
|
|
|
""" New Refresh token update """ |
|
|
|
access_token = generate_access_token(user_name[0]['name']) |
|
|
|
refresh_token = generate_refresh_token() |
|
|
|
token_details = update_tokens_in_doc( |
|
|
|
user_name[0]['name'], access_token, refresh_token) |
|
|
|
except: |
|
|
|
return {'status': 0, 'error': "Failed to Create token"} |
|
|
|
token = generate_keys(user_name[0]['name']) |
|
|
|
|
|
|
|
""" New Refresh token update """ |
|
|
|
access_token = generate_access_token(user_name[0]['name']) |
|
|
|
refresh_token = generate_refresh_token() |
|
|
|
token_details = update_tokens_in_doc( |
|
|
|
user_name[0]['name'], access_token, refresh_token) |
|
|
|
|
|
|
|
else: |
|
|
|
user = frappe.new_doc('User') |
|
|
@ -481,15 +635,13 @@ def new_grant_user_access(userdata=None, iid=None): |
|
|
|
user_name = frappe.db.sql('''SELECT name FROM {0}.tabUser where email='{1}';'''.format( |
|
|
|
current_db_name, email), as_dict=1) |
|
|
|
if user_name: |
|
|
|
# token = generate_keys(user_name[0]['name']) |
|
|
|
try: |
|
|
|
""" New Refresh token update """ |
|
|
|
access_token = generate_access_token(user_name[0]['name']) |
|
|
|
refresh_token = generate_refresh_token() |
|
|
|
token_details = update_tokens_in_doc( |
|
|
|
user_name[0]['name'], access_token, refresh_token) |
|
|
|
except: |
|
|
|
return {'status': 0, 'error': "Failed to Create token"} |
|
|
|
token = generate_keys(user_name[0]['name']) |
|
|
|
|
|
|
|
""" New Refresh token update """ |
|
|
|
access_token = generate_access_token(user_name[0]['name']) |
|
|
|
refresh_token = generate_refresh_token() |
|
|
|
token_details = update_tokens_in_doc( |
|
|
|
user_name[0]['name'], access_token, refresh_token) |
|
|
|
|
|
|
|
'''Inserting Dealer Data''' |
|
|
|
if frappe.db.exists({'doctype': 'App Dealer', 'dealer_code': dealer_code}): |
|
|
@ -528,16 +680,6 @@ def new_grant_user_access(userdata=None, iid=None): |
|
|
|
|
|
|
|
'''Inserting Device data''' |
|
|
|
if iid == 'None' or iid == 'null': |
|
|
|
app_device = frappe.new_doc('App Device') |
|
|
|
app_device.device_id = device_id |
|
|
|
app_device.publish_type = "Global" |
|
|
|
app_device.device_type = device_type |
|
|
|
app_device.os = os |
|
|
|
app_device.os_version = os_version |
|
|
|
app_device.app_current_version = app_current_version |
|
|
|
app_device.last_login = now() |
|
|
|
app_device.insert() |
|
|
|
|
|
|
|
if frappe.db.exists({'doctype': 'App Device', 'device_id': device_id}): |
|
|
|
frappe.db.sql( |
|
|
|
'''UPDATE {2}.`tabApp Device` SET active_status= "{1}" where device_id = "{0}";'''.format(device_id, |
|
|
@ -549,6 +691,15 @@ def new_grant_user_access(userdata=None, iid=None): |
|
|
|
'App Users', filters={"email_id": email}) |
|
|
|
app_device1 = frappe.get_last_doc( |
|
|
|
'App Device', filters={"device_id": device_id}) |
|
|
|
app_device = frappe.new_doc('App Device') |
|
|
|
app_device.device_id = device_id |
|
|
|
app_device.publish_type = "Global" |
|
|
|
app_device.device_type = device_type |
|
|
|
app_device.os = os |
|
|
|
app_device.os_version = os_version |
|
|
|
app_device.app_current_version = app_current_version |
|
|
|
app_device.last_login = now() |
|
|
|
app_device.insert() |
|
|
|
|
|
|
|
app_logs = frappe.new_doc('App Log') |
|
|
|
app_logs.user = app_user1.name |
|
|
@ -556,16 +707,9 @@ def new_grant_user_access(userdata=None, iid=None): |
|
|
|
app_logs.type = 'Reinstalled' |
|
|
|
app_logs.latitude = latitude |
|
|
|
app_logs.longitude = longitude |
|
|
|
# app_logs.active_status = 'Active' |
|
|
|
app_logs.date_time_stamp = now() |
|
|
|
app_logs.insert() |
|
|
|
|
|
|
|
app_device_tmp = frappe.get_last_doc( |
|
|
|
'App Device', filters={"device_id": device_id}) |
|
|
|
frappe.db.sql('''UPDATE {2}.`tabApp Device` SET active_status= "{1}" where name = "{0}";'''.format( |
|
|
|
app_device_tmp.name, "Active", current_db_name)) |
|
|
|
frappe.db.commit() |
|
|
|
|
|
|
|
app_logs3 = frappe.new_doc('App Log') |
|
|
|
app_logs3.user = app_user1.name |
|
|
|
app_logs3.device = app_device.name |
|
|
@ -576,6 +720,16 @@ def new_grant_user_access(userdata=None, iid=None): |
|
|
|
app_logs3.insert() |
|
|
|
|
|
|
|
else: |
|
|
|
app_device = frappe.new_doc('App Device') |
|
|
|
app_device.device_id = device_id |
|
|
|
app_device.publish_type = "Global" |
|
|
|
app_device.device_type = device_type |
|
|
|
app_device.os = os |
|
|
|
app_device.os_version = os_version |
|
|
|
app_device.app_current_version = app_current_version |
|
|
|
app_device.last_login = now() |
|
|
|
app_device.insert() |
|
|
|
|
|
|
|
app_user1 = frappe.get_last_doc( |
|
|
|
'App Users', filters={"email_id": email}) |
|
|
|
app_device1 = frappe.get_last_doc( |
|
|
@ -584,7 +738,6 @@ def new_grant_user_access(userdata=None, iid=None): |
|
|
|
app_logs.user = app_user1.name |
|
|
|
app_logs.device = app_device.name |
|
|
|
app_logs.type = 'Installed' |
|
|
|
# app_logs.active_status = 'Active' |
|
|
|
app_logs.latitude = latitude |
|
|
|
app_logs.longitude = longitude |
|
|
|
app_logs.date_time_stamp = now() |
|
|
@ -600,9 +753,6 @@ def new_grant_user_access(userdata=None, iid=None): |
|
|
|
app_logs4.save() |
|
|
|
|
|
|
|
else: |
|
|
|
# frappe.db.sql( |
|
|
|
# '''UPDATE {4}.`tabApp Device` set last_login= '{0}', user_name = '{2}', device_type = '{3}' where name = "{1}";'''.format( |
|
|
|
# now(), iid, email, user_type_desc, current_db_name)) |
|
|
|
frappe.db.sql( |
|
|
|
'''UPDATE {3}.`tabApp Device` set last_login= '{0}', device_type = '{2}' where name = "{1}";'''.format( |
|
|
|
now(), iid, device_type, current_db_name)) |
|
|
@ -628,155 +778,12 @@ def new_grant_user_access(userdata=None, iid=None): |
|
|
|
user_details = {} |
|
|
|
user_details['Installation ID'] = lst[0][0] |
|
|
|
user_details['User ID'] = lst1[0][0] |
|
|
|
# user_details['token'] = token |
|
|
|
user_details['status'] = 1 |
|
|
|
user_details['token_details'] = token_details |
|
|
|
user_details['token'] = token |
|
|
|
return user_details |
|
|
|
|
|
|
|
except Exception as e1: |
|
|
|
return {'status': 0, 'error': "Invalid Inputs"} |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist(allow_guest=True) |
|
|
|
def new_app_user_validation(usr=None, pwd=None, iid=None, device_data=None): |
|
|
|
rate_res = custom_rate_limit(limit=5, seconds=15) |
|
|
|
if rate_res != 1: |
|
|
|
return rate_res |
|
|
|
val = input_validation(usr=usr, pwd=pwd, iid=iid, device_data=device_data) |
|
|
|
if val != '': |
|
|
|
return {'status': 0, 'error': "Parameter's missing: " + val} |
|
|
|
|
|
|
|
preference = frappe.get_last_doc('App Preference') |
|
|
|
mahindra_login = preference.mahindra_login_api |
|
|
|
technician_login = preference.technician_login_api |
|
|
|
return {'status': 0, 'error': 'Failed to verify user'} |
|
|
|
|
|
|
|
# ISmartAuth API - Email available |
|
|
|
device_data = json.loads(device_data) |
|
|
|
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: |
|
|
|
frappe.set_user("Administrator") |
|
|
|
da = re.search("{", decoded) |
|
|
|
da1 = re.search("}", decoded) |
|
|
|
trunData = decoded[da.span()[0]:da1.span()[1]] |
|
|
|
|
|
|
|
dicData = json.loads(trunData) |
|
|
|
if dicData['ID'] == "": |
|
|
|
dicData['ID'] = "100" |
|
|
|
dicData.update(device_data) |
|
|
|
|
|
|
|
return new_grant_user_access(dicData, iid) |
|
|
|
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) |
|
|
|
frappe.set_user("Administrator") |
|
|
|
dicData = { |
|
|
|
"ID": "{}@email.com".format(usr), |
|
|
|
"LoginName": usr, |
|
|
|
"FirstName": usr, |
|
|
|
"LastName": "", |
|
|
|
"IsActive": "True", |
|
|
|
"UserType": "", |
|
|
|
"SkillID": "", |
|
|
|
"SkillName": "", |
|
|
|
"UserTypeDesc": "", |
|
|
|
"PasswordChanged": "", |
|
|
|
"AreaName": "", |
|
|
|
"Zone": "", |
|
|
|
"Code": "", |
|
|
|
"LocationName": "", |
|
|
|
"ChannelNo": "", |
|
|
|
"ServerDate": "", |
|
|
|
"ServerTime": "", |
|
|
|
"DealerName": "", |
|
|
|
"EmailId": "{}@email.com".format(usr), |
|
|
|
"isLDAPAuthenticated": ""} |
|
|
|
dicData.update(device_data) |
|
|
|
msgDic = {} |
|
|
|
|
|
|
|
try: |
|
|
|
msgDic['UserName'] = dictValue['children']['UserName']['text'] |
|
|
|
msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text'] |
|
|
|
if dicData['ID'] == "": |
|
|
|
dicData['ID'] = "100" |
|
|
|
return new_grant_user_access(dicData, iid) |
|
|
|
|
|
|
|
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": ""} |
|
|
|
|
|
|
|
msgDic = {} |
|
|
|
if len(decoded) > 165: |
|
|
|
frappe.set_user("Administrator") |
|
|
|
da = re.search("{", decoded) |
|
|
|
da1 = re.search("}", decoded) |
|
|
|
trunData = decoded[da.span()[0]:da1.span()[1]] |
|
|
|
dicData = json.loads(trunData) |
|
|
|
dicData['Code'] = "" |
|
|
|
if dicData['ID'] == "": |
|
|
|
dicData['ID'] = "100" |
|
|
|
|
|
|
|
dicData.update(device_data) |
|
|
|
return new_grant_user_access(dicData, iid) |
|
|
|
|
|
|
|
else: |
|
|
|
frappe.set_user("Administrator") |
|
|
|
msgDic['UserName'] = dictValue['children']['UserName']['text'] |
|
|
|
msgDic['IsSuccessfull'] = dictValue['children']['IsSuccessfull']['text'] |
|
|
|
if dicData['ID'] == "": |
|
|
|
dicData['ID'] = "100" |
|
|
|
dicData['Code'] = '' |
|
|
|
dicData.update(device_data) |
|
|
|
return new_grant_user_access(dicData, iid) |
|
|
|
|
|
|
|
else: |
|
|
|
return {'status': 0, 'error': 'Login Blocked'} |
|
|
|
except: |
|
|
|
return {'status': 0, 'error': 'Site Error'} |
|
|
|
|
|
|
|
@frappe.whitelist(allow_guest=1) |
|
|
|
def generate_keys(user_name): |
|
|
@ -796,30 +803,27 @@ def generate_keys(user_name): |
|
|
|
return token |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|
def login_generate_token(doc=None, method=None): |
|
|
|
rate_res = custom_rate_limit(limit=5, seconds=15) |
|
|
|
if rate_res != 1: |
|
|
|
return rate_res |
|
|
|
new_tok = generate_keys('cms@guidedsmartservice.com') |
|
|
|
water = frappe.get_doc("Fish", None) |
|
|
|
water.apple = new_tok |
|
|
|
water.save() |
|
|
|
return water.apple |
|
|
|
# @frappe.whitelist() |
|
|
|
# def login_generate_token(doc=None, method=None): |
|
|
|
# rate_res = custom_rate_limit(limit=5, seconds=15) |
|
|
|
# if rate_res != 1: |
|
|
|
# return rate_res |
|
|
|
# new_tok = generate_keys('cms@guidedsmartservice.com') |
|
|
|
# water = frappe.get_doc("Fish", None) |
|
|
|
# water.apple = new_tok |
|
|
|
# water.save() |
|
|
|
# return water.apple |
|
|
|
|
|
|
|
|
|
|
|
def input_validation(**kwargs): |
|
|
|
sts = "" |
|
|
|
i = 0 |
|
|
|
for key, value in kwargs.items(): |
|
|
|
# frappe.log_error("key"+str(key)) |
|
|
|
# frappe.log_error("value"+str(value)) |
|
|
|
if value is None or value == "" or value == '': |
|
|
|
if value is None or value == "": |
|
|
|
if i != 0: |
|
|
|
sts += ',' |
|
|
|
sts += str(key) + "" |
|
|
|
i += 1 |
|
|
|
# frappe.log_error(sts) |
|
|
|
return sts |
|
|
|
|
|
|
|
|
|
|
@ -893,9 +897,7 @@ def refresh_token(): |
|
|
|
refresh_token = generate_refresh_token() |
|
|
|
token_details = update_tokens_in_doc( |
|
|
|
d['user'], access_token, refresh_token) |
|
|
|
# token_details['status'] = 1 |
|
|
|
return {'status': 1, 'token_details': token_details} |
|
|
|
# return token_details |
|
|
|
|
|
|
|
return {'status': 0, "error": 'Invalid token'} |
|
|
|
|
|
|
@ -958,8 +960,6 @@ def deactivate_account(refresh_token): |
|
|
|
|
|
|
|
|
|
|
|
def update_tokens_in_doc(user_email, access, refresh): |
|
|
|
# access_exp_hours = 15 * 60 |
|
|
|
# refresh_exp_hrs = 60 * 60 * 24 |
|
|
|
|
|
|
|
token_settings = frappe.get_doc('Token Settings') |
|
|
|
access_exp_hours = token_settings.access_expiry_time |
|
|
@ -982,9 +982,6 @@ def update_tokens_in_doc(user_email, access, refresh): |
|
|
|
refresh_doc.access_token = encrypt(access) |
|
|
|
refresh_doc.refresh_token = encrypt(refresh) |
|
|
|
|
|
|
|
# access_exp_time = datetime.now() + timedelta(seconds=access_exp_hours) |
|
|
|
# refresh_exp_time = datetime.now() + timedelta(seconds=refresh_exp_hrs) |
|
|
|
|
|
|
|
access_exp_time = datetime.now() + timedelta(minutes=access_exp_hours) |
|
|
|
refresh_exp_time = datetime.now() + timedelta(hours=refresh_exp_hrs) |
|
|
|
|
|
|
@ -1060,3 +1057,4 @@ def deactivate_tokens(): |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
return e |
|
|
|
|
|
|
|