@ -9,7 +9,7 @@ import xml.etree.ElementTree as ET
from copy import copy
current_db_name = frappe . conf . get ( " db_name " )
now_datetime = now ( )
@frappe . whitelist ( allow_guest = True )
def app_user_validation ( usr , pwd ) :
@ -34,8 +34,7 @@ def app_user_validation(usr, pwd):
dicData [ ' status ' ] = 1
return dicData
else :
message_to_send = { ' status ' : 0 , ' error ' : ' Invalid Credentials ' }
return message_to_send
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 )
@ -80,8 +79,7 @@ def app_user_validation(usr, pwd):
except :
msgDic [ ' IsSuccessfull ' ] = node . text
message_to_send = { ' status ' : 0 , ' error ' : ' Invalid Credentials ' }
return message_to_send
return { ' status ' : 0 , ' error ' : ' Invalid Credentials ' }
elif technician_login == 1 and mahindra_login == 1 :
response = requests . post (
@ -139,11 +137,9 @@ def app_user_validation(usr, pwd):
dicData [ ' status ' ] = 1
return dicData
except :
message_to_send = { ' status ' : 0 , ' error ' : ' Invalid Credentials ' }
return message_to_send
return { ' status ' : 0 , ' error ' : ' Invalid Credentials ' }
else :
message_to_send = { ' status ' : 0 , ' error ' : ' Login Blocked ' }
return message_to_send
return { ' status ' : 0 , ' error ' : ' Login Blocked ' }
def xml_to_dict ( node ) :
@ -153,167 +149,166 @@ def xml_to_dict(node):
@frappe . whitelist ( )
def grant_user_access ( userdata , iid ) :
user_details = { }
userdata = json . loads ( userdata )
user_id = userdata [ ' ID ' ]
email = userdata [ ' EmailId ' ]
first_name = userdata [ ' FirstName ' ]
last_name = userdata [ ' LastName ' ]
login_name = userdata [ ' LoginName ' ]
user_active_status = userdata [ ' IsActive ' ]
latitude = userdata [ ' latitude ' ]
longitude = userdata [ ' longitude ' ]
user_type = userdata [ ' UserType ' ]
user_type_desc = userdata [ ' UserTypeDesc ' ]
skill_id = userdata [ ' SkillID ' ]
skill_name = userdata [ ' SkillName ' ]
area_name = userdata [ ' AreaName ' ]
zone = userdata [ ' Zone ' ]
dealer_code = userdata [ ' Code ' ]
location_name = userdata [ ' LocationName ' ]
dealer_name = userdata [ ' DealerName ' ]
app_current_version = userdata [ ' AppCurrentVersion ' ]
device_id = userdata [ ' DeviceID ' ]
device_type = userdata [ ' DeviceType ' ]
os = userdata [ ' Os ' ]
os_version = userdata [ ' OsVersion ' ]
''' Inserting Dealer Data '''
if frappe . db . exists ( { ' doctype ' : ' App Dealer ' , ' dealer_code ' : dealer_code } ) :
dealer = frappe . get_doc ( { ' doctype ' : ' App Dealer ' , ' dealer_code ' : dealer_code } )
else :
dealer = frappe . new_doc ( ' App Dealer ' )
dealer . dealer_code = dealer_code
dealer . dealer_name = dealer_name
dealer . zone = zone
dealer . area = area_name
dealer . active_status = user_active_status
dealer . save ( )
dealer = frappe . get_doc ( { ' doctype ' : ' App Dealer ' , ' dealer_code ' : dealer_code } )
''' Inserting User data '''
app_dealer1 = frappe . get_last_doc ( ' App Dealer ' , filters = { " dealer_code " : dealer_code } )
if frappe . db . exists ( { ' doctype ' : ' App Users ' , ' email_id ' : email } ) :
app_user = frappe . get_doc ( { ' doctype ' : ' App Users ' , ' email_id ' : email } )
else :
app_user = frappe . new_doc ( ' App Users ' )
app_user . email_id = email
app_user . user_id = user_id
app_user . dealer = app_dealer1 . name
app_user . login_name = login_name
app_user . user_type = user_type_desc
app_user . first_name = first_name
app_user . last_name = last_name
app_user . skill_id = skill_id
app_user . skill_name = skill_name
app_user . active_status = user_active_status
app_user . save ( )
''' 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_datetime
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 , " Inactive " , current_db_name ) )
frappe . db . commit ( )
time . sleep ( 1 )
app_user1 = frappe . get_last_doc ( ' App Users ' , filters = { " email_id " : email } )
app_device1 = frappe . get_last_doc ( ' App Device ' , filters = { " device_id " : device_id } )
# frappe.db.sql('''UPDATE {2}.`tabApp Device` SET active_status= "{1}" where device_id = "{0}";'''.format(device_id, "Inactive", current_db_name))
# frappe.db.commit()
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_datetime
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
app_logs3 . type = ' Logged in '
app_logs3 . latitude = latitude
app_logs3 . longitude = longitude
app_logs3 . date_time_stamp = now_datetime
app_logs3 . insert ( )
try :
user_details = { }
userdata = json . loads ( userdata )
user_id = userdata [ ' ID ' ]
email = userdata [ ' EmailId ' ]
first_name = userdata [ ' FirstName ' ]
last_name = userdata [ ' LastName ' ]
login_name = userdata [ ' LoginName ' ]
user_active_status = userdata [ ' IsActive ' ]
latitude = userdata [ ' latitude ' ]
longitude = userdata [ ' longitude ' ]
user_type = userdata [ ' UserType ' ]
user_type_desc = userdata [ ' UserTypeDesc ' ]
skill_id = userdata [ ' SkillID ' ]
skill_name = userdata [ ' SkillName ' ]
area_name = userdata [ ' AreaName ' ]
zone = userdata [ ' Zone ' ]
dealer_code = userdata [ ' Code ' ]
location_name = userdata [ ' LocationName ' ]
dealer_name = userdata [ ' DealerName ' ]
app_current_version = userdata [ ' AppCurrentVersion ' ]
device_id = userdata [ ' DeviceID ' ]
device_type = userdata [ ' DeviceType ' ]
os = userdata [ ' Os ' ]
os_version = userdata [ ' OsVersion ' ]
''' Inserting Dealer Data '''
if frappe . db . exists ( { ' doctype ' : ' App Dealer ' , ' dealer_code ' : dealer_code } ) :
dealer = frappe . get_doc ( { ' doctype ' : ' App Dealer ' , ' dealer_code ' : dealer_code } )
else :
app_user1 = frappe . get_last_doc ( ' App Users ' , filters = { " email_id " : email } )
app_device1 = frappe . get_last_doc ( ' App Device ' , filters = { " device_id " : device_id } )
dealer = frappe . new_doc ( ' App Dealer ' )
dealer . dealer_code = dealer_code
dealer . dealer_name = dealer_name
dealer . zone = zone
dealer . area = area_name
dealer . active_status = user_active_status
dealer . save ( )
dealer = frappe . get_doc ( { ' doctype ' : ' App Dealer ' , ' dealer_code ' : dealer_code } )
''' Inserting User data '''
app_dealer1 = frappe . get_last_doc ( ' App Dealer ' , filters = { " dealer_code " : dealer_code } )
if frappe . db . exists ( { ' doctype ' : ' App Users ' , ' email_id ' : email } ) :
app_user = frappe . get_doc ( { ' doctype ' : ' App Users ' , ' email_id ' : email } )
else :
app_user = frappe . new_doc ( ' App Users ' )
app_user . email_id = email
app_user . user_id = user_id
app_user . dealer = app_dealer1 . name
app_user . login_name = login_name
app_user . user_type = user_type_desc
app_user . first_name = first_name
app_user . last_name = last_name
app_user . skill_id = skill_id
app_user . skill_name = skill_name
app_user . active_status = user_active_status
app_user . save ( )
''' 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 , " Inactive " , current_db_name ) )
frappe . db . commit ( )
time . sleep ( 1 )
app_user1 = frappe . get_last_doc ( ' App Users ' , filters = { " email_id " : email } )
app_device1 = frappe . get_last_doc ( ' App Device ' , filters = { " device_id " : device_id } )
# frappe.db.sql('''UPDATE {2}.`tabApp Device` SET active_status= "{1}" where device_id = "{0}";'''.format(device_id, "Inactive", current_db_name))
# frappe.db.commit()
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
app_logs3 . device = app_device . name
app_logs3 . type = ' Logged in '
app_logs3 . latitude = latitude
app_logs3 . longitude = longitude
app_logs3 . date_time_stamp = now ( )
app_logs3 . insert ( )
else :
app_user1 = frappe . get_last_doc ( ' App Users ' , filters = { " email_id " : email } )
app_device1 = frappe . get_last_doc ( ' App Device ' , filters = { " device_id " : device_id } )
app_logs = frappe . new_doc ( ' App Log ' )
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 ( )
app_logs . save ( )
app_logs4 = frappe . new_doc ( ' App Log ' )
app_logs4 . user = app_user1 . name
app_logs4 . device = app_device . name
app_logs4 . type = ' Logged in '
app_logs4 . latitude = latitude
app_logs4 . longitude = longitude
app_logs4 . date_time_stamp = now ( )
app_logs4 . save ( )
else :
frappe . db . sql ( ''' UPDATE {4} .`tabApp Device` set last_logged_in= ' {0} ' , user_name = ' {2} ' , device_type = ' {3} ' where name = " {1} " ; ''' . format ( now ( ) , iid , email , user_type_desc , current_db_name ) )
frappe . db . commit ( )
app_user2 = frappe . get_last_doc ( ' App Users ' , filters = { " email_id " : email } )
app_logs = frappe . new_doc ( ' App Log ' )
app_logs . user = app_user1 . name
app_logs . device = app_device . name
app_logs . type = ' Installed '
app_logs . active_status = ' Active '
app_logs . user = app_user2 . name
app_logs . device = iid
app_logs . type = ' Logged in '
app_logs . latitude = latitude
app_logs . longitude = longitude
app_logs . date_time_stamp = now_datetime
app_logs . date_time_stamp = now ( )
app_logs . save ( )
app_logs4 = frappe . new_doc ( ' App Log ' )
app_logs4 . user = app_user1 . name
app_logs4 . device = app_device . name
app_logs4 . type = ' Logged in '
app_logs4 . latitude = latitude
app_logs4 . longitude = longitude
app_logs4 . date_time_stamp = now_datetime
app_logs4 . save ( )
else :
frappe . db . sql ( ''' UPDATE {4} .`tabApp Device` set last_logged_in= ' {0} ' , user_name = ' {2} ' , device_type = ' {3} ' where name = " {1} " ; ''' . format ( now_datetime , iid , email , user_type_desc , current_db_name ) )
frappe . db . commit ( )
app_user2 = frappe . get_last_doc ( ' App Users ' , filters = { " email_id " : email } )
app_logs = frappe . new_doc ( ' App Log ' )
app_logs . user = app_user2 . name
app_logs . device = iid
app_logs . type = ' Logged in '
app_logs . latitude = latitude
app_logs . longitude = longitude
app_logs . date_time_stamp = now_datetime
app_logs . save ( )
''' create user with role system manager '''
if frappe . db . exists ( ' User ' , email ) :
# user = frappe.get_doc('User', email)
docu = frappe . get_doc ( " Fish " , None )
token = docu . apple
user_details [ ' token ' ] = token
lst = frappe . db . sql ( ''' SELECT name FROM {} .`tabApp Device` where device_id = " {} " order by name desc limit 1; ''' . format ( current_db_name , device_id ) , as_list = True )
lst1 = frappe . db . sql ( ''' SELECT name FROM {} .`tabApp Users` where email_id = " {} " order by name desc limit 1; ''' . format ( current_db_name , email ) , as_list = True )
''' create user with role system manager '''
if frappe . db . exists ( ' User ' , email ) :
# user = frappe.get_doc('User', email)
docu = frappe . get_doc ( " Fish " , None )
token = docu . apple
user_details [ ' token ' ] = token
lst = frappe . db . sql ( ''' SELECT name FROM {} .`tabApp Device` where device_id = " {} " order by name desc limit 1; ''' . format ( current_db_name , device_id ) , as_list = True )
lst1 = frappe . db . sql ( ''' SELECT name FROM {} .`tabApp Users` where email_id = " {} " order by name desc limit 1; ''' . format ( current_db_name , email ) , as_list = True )
try :
user_details [ ' Installation ID ' ] = lst [ 0 ] [ 0 ]
user_details [ ' User ID ' ] = lst1 [ 0 ] [ 0 ]
return user_details
except :
return " Login Failure "
try :
user_details [ ' Installation ID ' ] = lst [ 0 ] [ 0 ]
user_details [ ' User ID ' ] = lst1 [ 0 ] [ 0 ]
return user_details
except :
# return "Login Failure"
return { ' status ' : 0 , ' error ' : ' Login Failure ' }
else :
else :
# user = frappe.new_doc('User')
# user.email = email
# user.first_name = first_name
@ -322,17 +317,20 @@ def grant_user_access(userdata,iid):
# user.add_roles('_AppUser')
# user.save()
docu = frappe . get_doc ( " Fish " , None )
token = docu . apple
user_details [ ' token ' ] = token
lst = frappe . db . sql ( ''' SELECT name FROM {} .`tabApp Device` where device_id = " {} " order by creation asc; ''' . format ( current_db_name , device_id ) , as_list = True )
lst1 = frappe . db . sql ( ''' SELECT name FROM {} .`tabApp Users` where email_id = " {} " order by creation asc; ''' . format ( current_db_name , email ) , as_list = True )
try :
user_details [ ' Installation ID ' ] = lst [ - 1 ] [ 0 ]
user_details [ ' User ID ' ] = lst1 [ - 1 ] [ 0 ]
return user_details
except :
return " Login Failure "
docu = frappe . get_doc ( " Fish " , None )
token = docu . apple
user_details [ ' token ' ] = token
lst = frappe . db . sql ( ''' SELECT name FROM {} .`tabApp Device` where device_id = " {} " order by creation asc; ''' . format ( current_db_name , device_id ) , as_list = True )
lst1 = frappe . db . sql ( ''' SELECT name FROM {} .`tabApp Users` where email_id = " {} " order by creation asc; ''' . format ( current_db_name , email ) , as_list = True )
try :
user_details [ ' Installation ID ' ] = lst [ - 1 ] [ 0 ]
user_details [ ' User ID ' ] = lst1 [ - 1 ] [ 0 ]
return user_details
except :
# return "Login Failure"
return { ' status ' : 0 , ' error ' : ' Login Failure ' }
except :
return { ' status ' : 0 , ' error ' : ' Input data error ' }
def generate_keys ( user ) :
user_details = frappe . get_doc ( ' User ' , user )
@ -352,14 +350,3 @@ def login_generate_token(doc=None,method=None):
water . apple = new_tok
water . save ( )
return water . apple
@frappe . whitelist ( allow_guest = True )
def temporary_login ( ) :
user_details = { }
docu = frappe . get_doc ( " Fish " , None )
token = docu . apple
user_details [ ' token ' ] = token
user_details [ ' Installation ID ' ] = " AppDev-0142 "
user_details [ ' User ID ' ] = " U-00006 "
user_details [ ' Code ' ] = " SJ010081 "
return user_details