def bullionprice(): if request.method=="GET": s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None cur, s, f1 = dbquery.get_bullion_price(con, cur) print(s) print(f1) if s <= 0: if s <= 0: f.append(f1) print('fetch is successful') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) # print(db_rec[0]) if db_rec is None: print('do something over here') t = 'data couldnt be extracted from fetch results' redata = [{"t": t}] res = make_response(jsonify(redata), 200) return res else: # db_rec = db_rec[0] print("fetch results extracted") pass print(s, f, t) print(db_rec) if s <= 0: # redata = [{"uId": db_rec['userid'], "uName": db_rec['username']}] redata = db_rec res = make_response(jsonify(redata), 200) return res else: return jsonify(False) return 'flow'
def app_appauth(criteria_json): print("inside appauth function") s = 0 f = None t = None #message to front end response = None res_to_send = 'fail' payload1 = criteria_json.get("payload", None) print(criteria_json) print(payload1) print(s) if s <= 0: if criteria_json.get("entityid", None) != None: origin_entityid = criteria_json['entityid'] else: origin_entityid = None s, f, t = errhand.get_status(s, 100, f, "Origin entity id not provided", t, "yes") if criteria_json.get("cntryid", None) != None: origin_cntryid = criteria_json['cntryid'] else: origin_cntryid = None s, f, t = errhand.get_status(s, 100, f, "Origin cntry code is not provided", t, "yes") print('origin', origin_entityid, origin_cntryid) #Use the installed entity and country code for further operatios entityid = config.INSTALLDATA[config.LIVE]["entityid"] cntryid = config.INSTALLDATA[config.LIVE]["countryid"] if payload1 == None: s, f, t = errhand.get_status( s, 100, f, "App data not sent. Please try again", t, "yes") else: if payload1.get("userauthtkn", None) != None: userauthtkn = payload1['userauthtkn'] else: userauthtkn = None s, f, t = errhand.get_status( s, 100, f, "User login success authtkn not provided", t, "yes") if payload1.get("appid", None) != None: appid = payload1['appid'] else: appid = None s, f, t = errhand.get_status(s, 100, f, "app id not provided", t, "yes") if payload1.get("appkey", None) != None: appkey = payload1['appkey'] else: appkey = None s, f, t = errhand.get_status(s, 100, f, "appkey is not provided", t, "yes") if payload1.get("redirecturi", None) != None: redirecturi = payload1['redirecturi'] else: redirecturi = None s, f, t = errhand.get_status(s, 100, f, "redirecturi is not provided", t, "yes") # update or create are the values print(userauthtkn, appid, redirecturi, appkey, entityid, cntryid) if s <= 0: con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("DB connection established", s, f, t) if s <= 0: command = cur.mogrify( """ SELECT json_agg(a) FROM ( SELECT * FROM ncapp.appdetail WHERE delflg != 'Y' AND expirydate >= CURRENT_DATE AND appid = %s AND appkey = %s AND redirecturi = %s AND entityid = %s AND countryid = %s ) as a """, ( appid, appkey, redirecturi, entityid, cntryid, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status( s, 200, f, "App Name data fetch failed with DB error", t, "no") print(s, f) app_db_rec = None if s <= 0: app_db_rec = cur.fetchall()[0][0] print("get db details") print(app_db_rec) if len(app_db_rec) < 1: s, f, t = errhand.get_status(s, 100, f, "Unable to locate the app id", t, "yes") else: app_db_rec = app_db_rec[0] print("appauth.py line 161 App id identified successfully") print(app_db_rec) print(s, f) appuserid = app_db_rec.get("appuserid", None) ''' if app_db_rec["appusertype"] == "D": useridts = appuserid elif app_db_rec["appusertype"] == "A": useridts = appuserid elif app_db_rec["appusertype"] == "P": useridts = appuserid elif app_db_rec["appusertype"] == "I": useridts = appuserid elif app_db_rec["appusertype"] == "T": useridts = appuserid ''' if s <= 0: command = cur.mogrify( """ SELECT json_agg(a) FROM ( SELECT * FROM ncusr.userauth WHERE tknexpiry >= CURRENT_TIMESTAMP AND userauthtkn = %s AND appid = %s AND entityid = %s AND countryid = %s ) as a """, ( userauthtkn, appid, entityid, cntryid, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status( s, 200, f, "User authtoke fetch failed with DB error", t, "no") print(s, f) usr_db_rec = None if s <= 0: usr_db_rec = cur.fetchall()[0][0] print(usr_db_rec) if len(usr_db_rec) < 1: s, f, t = errhand.get_status( s, 100, f, "Unable to locate the user auth details OR Token expired", t, "yes") else: usr_db_rec = usr_db_rec[0] print("User auth token validated successfully") useridts = usr_db_rec["userid"] #We are ready to generate API pass token print(s, f) i = 0 cur_time = datetime.now().strftime('%Y%m%d%H%M%S') passtknset = False pass_tkn = None while i < 50: r = ''.join( random.choice(string.ascii_letters + string.digits) for x in range(6)) pass_tkn = create_signature("md5", "nirunidhapasstkn" + r, userauthtkn + cur_time, appuserid + appid) command = cur.mogrify( """ SELECT count(1) FROM ncapp.appusrauth WHERE passwordtkn = %s """, (pass_tkn, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status( s, 200, f, "Password token data fetch failed with DB error", t, "no") print(s, f) if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) if db_rec > 0: s, f, t = errhand.get_status( s, 100, f, "Pass token Already exists. Retrying time: " + i, t, "no") i = i + 1 continue else: print("Pass code is unique. Generation task completed") passtknset = True break else: # Some error occured, so no point looping passtknset = False break print(s, f, t) appusrtype = app_db_rec.get("appusertype", None) if appusrtype == None: s, f, t = errhand.get_status(s, 200, f, "app user type is not known", t, "yes") if s <= 0 and passtknset: s1, f1 = db.mydbbegin(con, cur) print(s1, f1) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s <= 0: passexpiry = get_expiry_time(appusrtype) command = cur.mogrify( """ INSERT into ncapp.appusrauth (userauthtkn,appid,passwordtkn,passwordtknexpiry,entityid,countryid,octime,lmtime) VALUES(%s, %s, %s, %s, %s, %s, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) ON CONFLICT ON CONSTRAINT unq_comb_auauth DO UPDATE SET passwordtkn = %s, passwordtknexpiry = %s, lmtime = CURRENT_TIMESTAMP """, ( userauthtkn, appid, pass_tkn, passexpiry, entityid, cntryid, pass_tkn, passexpiry, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s > 0: s, f, t = errhand.get_status(s, 200, f, "passtoken update failed", t, "no") print('Insert or update is successful') if s <= 0: con.commit() if s <= 0: data_for_jwt = { "exp": passexpiry.strftime('%d%m%Y%H%M%S'), "passtkn": pass_tkn, "ei": entityid, "ci": cntryid, "ncuserid": useridts } natjwt = jwtf.generatejwt(data_for_jwt) if s > 0: res_to_send = 'fail' result_date = [] response = { 'result_data': result_date, 'status': res_to_send, 'status_code': s, 'usrmsg': errhand.error_msg_reporting(s, t) } else: res_to_send = 'success' result_date = natjwt response = { 'result_data': result_date, 'status': res_to_send, 'status_code': 0, 'usrmsg': "pass Token generation successful" } print(res_to_send, response) return (res_to_send, response)
def fn_appname(criteria_json): print("inside fn_appname function") s = 0 f = None t = None #message to front end response = None res_to_send = 'fail' payload = criteria_json.get("payload", None) print(s) if s <= 0: if criteria_json.get("entityid", None) != None: entityid = criteria_json['entityid'] else: entityid = None s, f, t = errhand.get_status(s, 100, f, "entity id not provided", t, "yes") if criteria_json.get("cntryid", None) != None: cntryid = criteria_json['cntryid'] else: cntryid = None s, f, t = errhand.get_status(s, 100, f, "cntry code is not provided", t, "yes") if payload == None: s, f, t = errhand.get_status( s, 100, f, "App data not sent. Please try again", t, "yes") else: if payload.get("appid", None) != None: appid = payload['appid'] else: appid = None s, f, t = errhand.get_status(s, 100, f, "app id not provided", t, "yes") if payload.get("redirecturi", None) != None: redirecturi = payload['redirecturi'] else: redirecturi = None s, f, t = errhand.get_status(s, 100, f, "redirecturi is not provided", t, "yes") # update or create are the values print(appid, redirecturi, entityid, cntryid) if s <= 0: con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("DB connection established", s, f, t) if s <= 0: command = cur.mogrify( """ SELECT json_agg(a) FROM ( SELECT * FROM ncapp.appdetail WHERE delflg != 'Y' AND expirydate >= CURRENT_DATE AND approved != 'N' AND appid = %s AND redirecturi = %s AND entityid = %s AND countryid = %s ) as a """, ( appid, redirecturi, entityid, cntryid, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status( s, 200, f, "App Name data fetch failed with DB error", t, "no") print(s, f) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) if db_rec == None or len(db_rec) > 1: s, f, t = errhand.get_status(s, 100, f, "Unable to locate the app id", t, "yes") else: db_rec = db_rec[0] print("auth.py line 136 App id identified successfully") pass print(s, f) if s > 0: res_to_send = 'fail' result_date = [] response = { 'result_data': result_date, 'status': res_to_send, 'status_code': s, 'usrmsg': errhand.error_msg_reporting(s, t) } else: res_to_send = 'success' result_data = {"appname": db_rec["appname"]} response = { 'result_data': result_data, 'status': res_to_send, 'status_code': 0, 'usrmsg': "Token generation successful" } print(res_to_send, response) return (res_to_send, response)
def app_userauth(criteria_json): # Generate a user auth token # input # criteria_json = { # "entityid" : entityid, # "cntryid" : cntryid, # "payload" : payload => {appid,redirecturi,userid,expiremin<tokenexipry in mins>} # } # Output # response = { # 'result_data' : result_data, => succ-> {'authtkn': auth_tkn} : err->[] # 'status': res_to_send, => success/fail # 'status_code': 0, # 'usrmsg': "Token generation successful" <=for success: error msg in case of error # } print("inside userauth function") s = 0 f = None t = None #message to front end response = None res_to_send = 'fail' payload = criteria_json.get("payload", None) print(s) if s <= 0: if criteria_json.get("entityid", None) != None: entityid = criteria_json['entityid'] else: entityid = None s, f, t = errhand.get_status(s, 100, f, "entity id not provided", t, "yes") if criteria_json.get("cntryid", None) != None: cntryid = criteria_json['cntryid'] else: cntryid = None s, f, t = errhand.get_status(s, 100, f, "cntry code is not provided", t, "yes") if payload == None: s, f, t = errhand.get_status( s, 100, f, "App data not sent. Please try again", t, "yes") else: if payload.get("appid", None) != None: appid = payload['appid'] else: appid = None s, f, t = errhand.get_status(s, 100, f, "app id not provided", t, "yes") if payload.get("redirecturi", None) != None: redirecturi = payload['redirecturi'] else: redirecturi = None s, f, t = errhand.get_status(s, 100, f, "redirecturi is not provided", t, "yes") if payload.get("userid", None) != None: userid = payload['userid'] else: userid = None s, f, t = errhand.get_status(s, 100, f, "userid is not provided", t, "yes") expiremin = payload.get("expiremin", None) print(appid, redirecturi, entityid, cntryid, userid) if s <= 0: con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("DB connection established", s, f, t) if s <= 0: command = cur.mogrify( """ SELECT json_agg(a) FROM ( SELECT * FROM ncapp.appdetail WHERE delflg != 'Y' AND expirydate >= CURRENT_DATE AND approved != 'N' AND appid = %s AND redirecturi = %s AND entityid = %s AND countryid = %s ) as a """, ( appid, redirecturi, entityid, cntryid, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status( s, 200, f, "App Name data fetch failed with DB error", t, "no") print(s, f) app_db_rec = None if s <= 0: app_db_rec = cur.fetchall()[0][0] print(app_db_rec) if app_db_rec != None: print(len(app_db_rec)) if app_db_rec == None or len(app_db_rec) < 1: s, f, t = errhand.get_status(s, 100, f, "Unable to locate the app id", t, "yes") else: app_db_rec = app_db_rec[0] print("auth.py line 319 App id identified successfully") pass print(s, f) #appuserid = app_db_rec.get("appuserid", None) if s <= 0: command = cur.mogrify( """ SELECT json_agg(a) FROM ( SELECT * FROM ncusr.userlogin WHERE userid = %s AND entityid = %s AND countryid = %s ) as a """, ( userid, entityid, cntryid, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "User fetch failed with DB error", t, "no") print(s, f) usr_db_rec = None if s <= 0: usr_db_rec = cur.fetchall()[0][0] print(usr_db_rec) if usr_db_rec == None or len(usr_db_rec) < 1: s, f, t = errhand.get_status(s, 100, f, "Unable to locate the user details", t, "yes") else: usr_db_rec = usr_db_rec[0] print("User details fetch successfull") pass if s <= 0: if usr_db_rec["userstatus"] == 'B': #B-Blocked , I-Deleteduser s, f, t = errhand.get_status(s, 100, f, "User is blocked", t, "yes") elif usr_db_rec["userstatus"] == 'I': #B-Blocked , I-Deleteduser s, f, t = errhand.get_status(s, 100, f, "User is Deleted", t, "yes") #We are ready to generate API pass token print(s, f) if s <= 0: i = 0 cur_time = datetime.now().strftime('%Y%m%d%H%M%S') authtknset = False auth_tkn = None while i < 50: r = ''.join( random.choice(string.ascii_letters + string.digits) for x in range(6)) auth_tkn = create_signature("md5", "nirunidhausrtkn" + r, userid + cur_time, appid + cur_time) command = cur.mogrify( """ SELECT count(1) FROM ncusr.userauth WHERE userauthtkn = %s """, (auth_tkn, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status( s, 200, f, "auth token data fetch failed with DB error", t, "no") print(s, f) if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) if db_rec > 0: s, f, t = errhand.get_status( s, 100, f, "auth token Already exists. Retrying time: " + i, t, "no") i = i + 1 continue else: print("Auth token is unique. Generation task completed") authtknset = True break else: # Some error occured, so no point looping authtknset = False break print(s, f, t) appusrtype = None if app_db_rec == None else app_db_rec.get( "appusertype", None) if appusrtype == None: s, f, t = errhand.get_status(s, 200, f, "app user type is not known", t, "yes") if s <= 0 and authtknset: s1, f1 = db.mydbbegin(con, cur) print(s1, f1) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s <= 0: passexpiry = get_expiry_time("authtkn", appusrtype, expiremin) # VALUES(%s, %s, %s, %(timestamp)s, %s, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) command = cur.mogrify( """ INSERT into ncusr.userauth (userid,appid,userauthtkn,tknexpiry,entityid,countryid,octime,lmtime) VALUES(%s, %s, %s, %s, %s, %s, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) ON CONFLICT ON CONSTRAINT unq_comb_uauth DO UPDATE SET userauthtkn = %s, tknexpiry = %s, lmtime = CURRENT_TIMESTAMP """, ( userid, appid, auth_tkn, passexpiry, entityid, cntryid, auth_tkn, passexpiry, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s > 0: s, f, t = errhand.get_status(s, 200, f, "authtoken update failed", t, "no") print('Insert or update is successful') if s <= 0: con.commit() if s > 0: res_to_send = 'fail' result_data = [] response = { 'result_data': result_data, 'status': res_to_send, 'status_code': s, 'usrmsg': errhand.error_msg_reporting(s, t) } else: res_to_send = 'success' result_data = {'authtkn': auth_tkn} response = { 'result_data': result_data, 'status': res_to_send, 'status_code': 0, 'usrmsg': "Token generation successful" } print(res_to_send, response) return (res_to_send, response)
def login(): if request.method == "POST": print("osignup") attempted_username = request.get_json(force=True)['username'] attempted_password = request.get_json(force=True)['password'] s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username, attempted_password) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') userid = attempted_username name = 'mangu' signupemail = '*****@*****.**' userstatus = 'A' entityid = 'bansss' countryid = '473874' if s <= 0: command = cur.mogrify( """ INSERT INTO unihot.userlogin (userid, username, useremail, userstatus, userstatlstupdt, octime, lmtime,logintype, usertype) VALUES (%s,%s,%s,%s,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP, %s, %s); """, ( userid, name, signupemail, userstatus, 'S', 'A', )) print(command) cur, s, f1 = db.mydbfunc(con, cur, command) if s <= 0: if s < 0: f.append(f1) # con.commit() print('Insert or update is successful') command = cur.mogrify( """ INSERT INTO unihot.useraccess (userid, logintype, usertype, entity, entitybranch, defaultindicator, roleid,site, accessstatus, octime, lmtime) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s, CURRENT_TIMESTAMP,CURRENT_TIMESTAMP); """, ( userid, 'dv', 'xx', 'dummy', 'dummy', 'A', 'Admin', 'somesite', 'f', )) print(command) cur, s, f1 = db.mydbfunc(con, cur, command) if s <= 0: if s < 0: f.append(f1) con.commit() print('Insert or update is successful to useraccess') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) if s <= 0: db_rec = {'userid': userid, 'username': name} print(db_rec) print(len(db_rec)) # print(db_rec[0]) if db_rec is None: print('do something over here') else: # db_rec = db_rec[0] print("auth.py line 136 user auth successfully") pass print(s, f, t) print(db_rec) if s <= 0: redata = [{"uId": db_rec['userid'], "uName": db_rec['username']}] res = make_response(jsonify(redata), 200) return res else: return jsonify(False)
def ologins(): if request.method == "POST": print("0login1") attempted_username = request.get_json(force=True)['username'] attempted_password = request.get_json(force=True)['password'] # attempted_username = '******' # attempted_password = '******' print(attempted_username, attempted_password) s = 0 f = None t = None # message to front end # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username, attempted_password) print("here") if s <= 0: con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("DB connection established", s, f, t) if s <= 0: command = cur.mogrify( """ SELECT json_agg(a) FROM ( SELECT userid,username FROM unihot.userlogin WHERE userstatus = 'A' AND uName = %s AND uPassword = %s AND branchid = %s AND hotelid = %s ) as a """, ( attempted_username, attempted_password, branchid, hotelid, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status( s, 200, f, "App Name data fetch failed with DB error", t, "no") print(s, f) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) print(len(db_rec)) print(db_rec[0]) if db_rec == None or len(db_rec) > 1: s, f, t = errhand.get_status(s, 100, f, "User authentication failed", t, "yes") else: db_rec = db_rec[0] print("auth.py line 136 user auth successfully") pass print(s, f, t) print(db_rec) if s <= 0: redata = [{"uId": db_rec['uid'], "uName": db_rec['uname']}] res = make_response(jsonify(redata), 200) return res else: return jsonify(False)
def generatejwt(d): #Create JWT print("inside jwt creation function") s = 0 f = None t = None #message to front end response = None res_to_send = 'fail' print(d) con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("DB connection established", s, f, t) natseckey = "secret" if s <= 0: command = cur.mogrify( """ SELECT json_agg(a) FROM ( SELECT secretcode,seccdid FROM ncapp.secrettkn WHERE entityid = %s AND countryid =%s ) as a """, (d["ei"], d["ci"])) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "secret fetch failed with DB error", t, "no") print(s, f) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] if len(db_rec) < 1: s, f, t = errhand.get_status(s, 100, f, "Unable to get secret", t, "no") else: print(db_rec) db_rec = db_rec[0] print("got the secret string successfully") pass print(s, f) if s <= 0: secretcode = db_rec.get("secretcode", None) if secretcode == None: s, f, t = errhand.get_status(s, 200, f, "unable to get secret code", t, "no") seccdid = db_rec.get("seccdid", None) if seccdid == None: s, f, t = errhand.get_status(s, 200, f, "unable to get secret code id", t, "no") print("@@@@@@@@@@@@@") print(secretcode) print("@@@@@@@@@@@@@") if s <= 0: #Call JWT to generate JWT START natjwt = jwt.encode( { "iss": "ncj", "exp": d["exp"], "iat": datetime.now().strftime('%d%m%Y%H%M%S%f'), "passtkn": d["passtkn"], "skd": seccdid, "eid": d["ei"], "cid": d["ci"], "ncuserid": d["ncuserid"] }, secretcode, algorithm='HS256') print("printing nat jwt") print(natjwt) #Call JWT to generate JWT END db.mydbcloseall(con, cur) return (json.dumps({"ncjwt": natjwt.decode("utf-8")}))
def app_detail_fetch(criteria_json): # payload = {'appid': xyz, 'login': <[noauth] to get data without user id>} # entity id and country id will come in header which are mandator. user id comes in jwt # Output = { 'result_data' : [success -> ncapp.appdetail] [Failure -> ""] # 'status': success/fail, 'status_code': 0, 'usrmsg': ''/error message } print("inside app_detail_fetch common function") s = 0 f = None t = None #message to front end payload = criteria_json.get("payload",None) print(payload) if s <= 0: if payload == None: appid = None login = None # s, f, t= errhand.get_status(s, 100, f, "no payload provided", t, "yes") else: if payload.get("appid", None) != None: appid = payload['appid'] else: appid = None if payload.get("login", None) != None: login = payload['login'] else: login = None print(appid, login, s) if s <= 0: if criteria_json.get("entityid", None) != None: entityid = criteria_json['entityid'] else: entityid = None s, f, t= errhand.get_status(s, 100, f, "entity id not provided", t, "yes") if criteria_json.get("cntryid", None) != None: cntryid = criteria_json['cntryid'] else: cntryid = None s, f, t= errhand.get_status(s, 100, f, "cntry code is not provided", t, "yes") if login != "nologin": if criteria_json.get("userid", None) != None: userid = criteria_json['userid'] else: # To get app details before login for entity and cntry userid = None s, f, t= errhand.get_status(s, 100, f, "user id not provided", t, "yes") else: userid = None if s <= 0: con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s <= 0: if appid == None: command = cur.mogrify(""" SELECT json_agg(a) FROM ( SELECT *, CASE WHEN expirydate < CURRENT_TIMESTAMP THEN 'EXPIRED' ELSE 'ACTIVE' END AS appexp FROM ncapp.appdetail WHERE appuserid = %s AND entityid = %s AND countryid = %s AND delflg = 'N' ) as a """,(userid,entityid,cntryid,)) elif userid == None: command = cur.mogrify(""" SELECT json_agg(a) FROM ( SELECT *, CASE WHEN expirydate < CURRENT_TIMESTAMP THEN 'EXPIRED' ELSE 'ACTIVE' END AS appexp FROM ncapp.appdetail WHERE appid = %s AND entityid = %s AND countryid = %s AND delflg = 'N' ) as a """,(appid,entityid,cntryid,)) else: command = cur.mogrify(""" SELECT json_agg(a) FROM ( SELECT *, CASE WHEN expirydate < CURRENT_TIMESTAMP THEN 'EXPIRED' ELSE 'ACTIVE' END AS appexp FROM ncapp.appdetail WHERE appuserid = %s AND entityid = %s AND countryid = %s AND appid = %s AND delflg = 'N' ) as a """,(userid,entityid,cntryid,appid,)) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "APP data fetch failed with DB error", t, "no") print(s,f) if s <= 0: db_json_rec = cur.fetchall()[0][0] print(db_json_rec) if s > 0: res_to_send = 'fail' response = { 'result_data' : "", 'status': res_to_send, 'status_code': s, 'usrmsg': errhand.error_msg_reporting(s, t) } else: res_to_send = 'success' response = { 'result_data' : db_json_rec, 'status': res_to_send, 'status_code': 0, 'usrmsg': '' } print(res_to_send, response) return (res_to_send, response)
def get_linked_apps_nd_save(linked_apps_input): #Get all the linked apps for a acuid print("inside get_linked_apps function") s = 0 f = None t = None #message to front end lnkd_app_data = None lnk_passtkn = linked_apps_input["pass_tkn"] lnk_pass_exp = datetime.strptime(linked_apps_input["pass_tkn_exp"],'%d%m%Y%H%M%S%f') acusrid = linked_apps_input["acuid"] lnk_app_uid = linked_apps_input["lnk_userid"] entityid = linked_apps_input["entityid"] countryid = linked_apps_input["countryid"] #Get con and cur con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("DB connection established", s,f,t) if s <= 0: s1, f1 = db.mydbbegin(con, cur) print(s1,f1) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s <= 0: command = cur.mogrify(""" UPDATE acusr.linkedapps SET lnk_passtkn = %s, lnk_pass_exp = %s WHERE userid = %s AND lnk_userid = %s AND entityid= %s AND countryid = %s; """,(lnk_passtkn, lnk_pass_exp, acusrid, lnk_app_uid, entityid, countryid,)) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s > 0: s, f, t= errhand.get_status(s, 200, f, "SIGNUP update failed", t, "no") print('Insert or update is successful') if s <= 0: con.commit() #get the linked apps for the acuid #Check for Token expiry of all the apps inside CASE if s <= 0: command = cur.mogrify(""" SELECT json_agg(a) FROM ( SELECT *, CASE WHEN (lnk_pass_exp < CURRENT_TIMESTAMP) THEN 'expired' ELSE 'active' END AS pass_tkn_status FROM acusr.linkedapps WHERE lnkstatus = 'L' AND userid = %s AND entityid = %s AND countryid = %s ) as a """,(linked_apps_input["acuid"],linked_apps_input["entityid"],linked_apps_input["countryid"],)) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "User data fetch failed with DB error", t, "no") print(s,f) if s <= 0: print("rowcount") print(cur.rowcount) print("rowcount") if cur.rowcount > 0: lnkd_app_data = cur.fetchall()[0][0] else: lnkd_app_data = None print(lnkd_app_data) print(s,f) if s <= 0: return s, lnkd_app_data else: return s, lnkd_app_data
def nc_pass_tkn(callback_data): #get pass token from nc s = 0 f = None t = None #message to front end lnkd_app_data = None entityid = callback_data["entityid"] countryid = callback_data["countryid"] headers = {"entityid": entityid, "countryid": countryid} req_payload = { "userauthtkn": callback_data["userauthtkn"], "appid": settings.NCAPPID[settings.LIVE], "appkey":settings.NCAPPKEY[settings.LIVE], "redirecturi":settings.MYREDIRURI[settings.LIVE] } print("###########################") print(req_payload) print(type(req_payload)) print("###########################") #r = requests.post(settings.NCPASSURL[settings.LIVE], headers=headers, data=json.dumps(req_payload)) try: r = requests.post(settings.NCPASSURL[settings.LIVE], headers=headers, data=json.dumps(req_payload)) except requests.exceptions.Timeout: print("timeout exception") s, f, t = errhand.get_status(s, 100, f, "Timeout error in sending request to nc", t, "yes") #pan_data = {"pan_name": None, "kyc_status": None} except requests.exceptions.RequestException as e: print("exception") print(e) s, f, t = errhand.get_status(s, 100, f, "error in sending request to nc", t, "yes") else: print(r.content) nc_usr_data = json.loads(r.content.decode("utf-8") ) print(json.loads(r.content.decode("utf-8"))) print('i see') print(type(nc_usr_data)) nc_usr_data = json.loads(nc_usr_data) print(nc_usr_data) print(type(nc_usr_data)) jwtdecoded = jwt.decode(nc_usr_data.get("ncjwt"), verify=False) print(jwtdecoded) ncuid = jwtdecoded["ncuserid"] nc_pass_tkn_exp = jwtdecoded["exp"] #Get acuserid from ncuserid con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("DB connection established", s,f,t) #get acuid from ncuid if s <= 0: command = cur.mogrify(""" SELECT userid FROM acusr.linkedapps WHERE lnkstatus = 'L' AND lnk_userid = %s AND entityid = %s AND countryid = %s """,(ncuid,entityid,countryid,)) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "User data fetch failed with DB error", t, "no") print(s,f) if s <= 0: print("rowcount") print(cur.rowcount) print("rowcount") if cur.rowcount > 0: uid = cur.fetchall()[0][0] print(uid) print(s,f) print("rowcount") #Check for other linked apps linked_apps_input = { "acuid": uid, "entityid": entityid, "countryid": countryid, "pass_tkn_exp" : nc_pass_tkn_exp, "pass_tkn": nc_usr_data.get("ncjwt"), "lnk_userid": ncuid } rec_status, linked_apps_lst = get_linked_apps_nd_save(linked_apps_input) if rec_status > 0: s, f, t = errhand.get_status(s, rec_status, f, "Linked app data fetch failed with error", t, "no") print(s,f) return s, linked_apps_lst
def save_usr_details(sav_usr): print("inside save_usr_details function") s = 0 f = None t = None #message to front end rec_status ="fail" con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("DB connection established", s,f,t) #validate user existence if s <= 0: command = cur.mogrify(""" SELECT json_agg(a) FROM ( SELECT userid, username, useremail, logintype FROM acusr.userlogin WHERE userstatus NOT IN ('I') AND ( userid = %s OR useremail = %s ) AND entityid = %s AND countryid = %s ) as a """,(sav_usr["uid"],sav_usr["nc_email"],sav_usr["entityid"],sav_usr["countryid"],)) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "User data fetch failed with DB error", t, "no") print(s,f) if s <= 0: db_json_rec = cur.fetchall()[0][0] print(db_json_rec) reg_status, reg_data = allow_regis_user(db_json_rec, sav_usr) print(reg_status) print(reg_data) if reg_status == "fail": s, f, t= errhand.get_status(s, 101, f, reg_data, t, "yes") print(s,f) if s <= 0: s1, f1 = db.mydbbegin(con, cur) print(s1,f1) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s <= 0: command = cur.mogrify(""" INSERT INTO acusr.userlogin (userid, username, useremail, logintype, userstatus, userstatlstupdt, octime, lmtime, entityid, countryid) VALUES (%s,%s,%s,'I','A',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,%s,%s); """,(sav_usr["uid"], sav_usr["nc_usrname"], sav_usr["nc_email"],settings.INSTALLDATA[settings.LIVE]["entityid"],settings.INSTALLDATA[settings.LIVE]["countryid"],)) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("end of ") if s > 0: s, f, t= errhand.get_status(s, 200, f, "SIGNUP userlogin insert failed", t, "no") print('userlogin Insert or update completed') if s <= 0: command = cur.mogrify(""" INSERT INTO acusr.linkedapps (userid, lnk_app, lnk_userid, lnk_email, lnkstatus, octime, lmtime, entityid, countryid) VALUES (%s,%s,%s,%s,'L',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,%s,%s); """,(sav_usr["uid"], sav_usr["nc_entity"], sav_usr["nc_usrid"], sav_usr["nc_email"],settings.INSTALLDATA[settings.LIVE]["entityid"],settings.INSTALLDATA[settings.LIVE]["countryid"],)) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s > 0: s, f, t= errhand.get_status(s, 200, f, "SIGNUP linkedapps insert failed", t, "no") print('linked app Insert or update completed') if s <= 0: con.commit() db.mydbcloseall(con,cur) if s<= 0: rec_status = "success" msg = "User data saved successfully" else: rec_status = "fail" tt = errhand.front_end_msg if errhand.front_end_msg != None else "" msg = "User data save failed " + tt return rec_status, msg
def entity(): """ This method will handle GET, POST, UPDATE, DELETE request made from the frontend for an entity. GET : It will return all the related entities of a provided userid. POST : It will insert a new entity details in entity table as well as it will assign that entity to the given useriid in useraccess table, if an entry exists for entityid in useraccess table for tha same userid and it is't dummy then a new record will be inserted otherwise the entityid field will be updated """ if request.method == "GET": print( "oentity GET Call For Listing ALl Entities Except 'PUBLIC' Entity " ) print(request.headers.get("thirdparty", None)) print(request.headers.get("usertype", None)) abc = dict(request.headers) print(abc) dtkn = jwtf.decodetoken(request, needtkn=False) userid = dtkn.get("user_id", None) entityid = request.headers.get("entityid", None) cntryid = request.headers.get("countryid", None) print(userid) print(entityid) print(cntryid) # attempted_username = request.get_json(force=True)['username'] attempted_username = userid s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') entitystatus = 'A' getuserentities = {} getuserentities['keys'] = {} getuserentities['keys']['userid'] = attempted_username getuserentities['keys']['entitystatus'] = entitystatus if s <= 0: cur, s, f1 = processdb.get_user_entities(con, cur, getuserentities) if s <= 0: if s < 0: f.append(f1) print('fetch is successful') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) # print(db_rec[0]) if db_rec is None: print('do something over here') t = 'data couldnt be extracted from fetch results' redata = [{"t": t}] res = make_response(jsonify(redata), 200) return res else: # db_rec = db_rec[0] print("fetch results extracted") pass print(s, f, t) print(db_rec) if s <= 0: # redata = [{"uId": db_rec['userid'], "uName": db_rec['username']}] redata = db_rec res = make_response(jsonify(redata), 200) return res else: return jsonify(False) elif request.method == "POST": print("oentity POST Call For Insert New Entity") attempted_username = request.get_json(force=True)['username'] attempted_entityaddline1 = request.get_json( force=True)['entityaddline1'] attempted_entityaddline2 = request.get_json( force=True)['entityaddline2'] attempted_entitycategory = request.get_json( force=True)['entitycategory'] attempted_entitycity = request.get_json(force=True)['entitycity'] attempted_entitycountry = request.get_json(force=True)['entitycountry'] attempted_entitydescription = request.get_json( force=True)['entitydescription'] attempted_entityemail = request.get_json(force=True)['entityemail'] attempted_entityfax = request.get_json(force=True)['entityfax'] attempted_entityfiscalyear = request.get_json( force=True)['entityfiscalyear'] attempted_entityimageurl = request.get_json( force=True)['entityimageurl'] attempted_entityindustry = request.get_json( force=True)['entityindustry'] attempted_entitylogo = request.get_json(force=True)['entitylogo'] attempted_entitymobile = request.get_json(force=True)['entitymobile'] attempted_entityname = request.get_json(force=True)['entityname'] attempted_entityphone = request.get_json(force=True)['entityphone'] attempted_entitypincode = request.get_json(force=True)['entitypincode'] attempted_entityshortname = request.get_json( force=True)['entityshortname'] attempted_entitystartdate = request.get_json( force=True)['entitystartdate'] attempted_entitystate = request.get_json(force=True)['entitystate'] attempted_entitystatus = request.get_json(force=True)['entitystatus'] attempted_entitytaxid = request.get_json(force=True)['entitytaxid'] attempted_entitytimezone = request.get_json( force=True)['entitytimezone'] attempted_entitywebsite = request.get_json(force=True)['entitywebsite'] attempted_muserid = request.get_json(force=True)['muserid'] attempted_roleid = request.get_json(force=True)['roleid'] attempted_logintype = request.get_json(force=True)['logintype'] attempted_usertype = request.get_json(force=True)['usertype'] s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') userid = attempted_username name = 'mangu' signupemail = '*****@*****.**' userstatus = 'A' entityid = 'bansss' countryid = '473874' insertentity = {} insertentity['values'] = {} insertentity['values']['entityaddline1'] = attempted_entityaddline1 insertentity['values']['entityaddline2'] = attempted_entityaddline2 insertentity['values']['entitycategory'] = attempted_entitycategory insertentity['values']['entitycity'] = attempted_entitycity insertentity['values']['entitycountry'] = attempted_entitycountry insertentity['values'][ 'entitydescription'] = attempted_entitydescription insertentity['values']['entityemail'] = attempted_entityemail insertentity['values']['entityfax'] = attempted_entityfax insertentity['values']['entityfiscalyear'] = attempted_entityfiscalyear insertentity['values']['entityimageurl'] = attempted_entityimageurl insertentity['values']['entityindustry'] = attempted_entityindustry insertentity['values']['entitylogo'] = attempted_entitylogo insertentity['values']['entitymobile'] = attempted_entitymobile insertentity['values']['entityname'] = attempted_entityname insertentity['values']['entityphone'] = attempted_entityphone insertentity['values']['entitypincode'] = attempted_entitypincode insertentity['values']['entityshortname'] = attempted_entityshortname insertentity['values']['entitystartdate'] = attempted_entitystartdate insertentity['values']['entitystate'] = attempted_entitystate insertentity['values']['entitystatus'] = attempted_entitystatus insertentity['values']['entitytaxid'] = attempted_entitytaxid insertentity['values']['entitytimezone'] = attempted_entitytimezone insertentity['values']['entitywebsite'] = attempted_entitywebsite insertentity['values']['userid'] = attempted_muserid if s <= 0: cur, s, f1 = processdb.insert_entity(con, cur, insertentity) if s <= 0: if s < 0: f.append(f1) entityid = cur.fetchone()[0] print('last entity id =', entityid) print('entity database insert results:', s, f, t) getuserentities = {} getuserentities['keys'] = {} getuserentities['keys']['userid'] = attempted_username getuserentities['keys']['entitystatus'] = 'A' if s <= 0: cur, s, f1 = processdb.get_user_entities( con, cur, getuserentities) if s <= 0: if s < 0: f.append(f1) print('fetch is successful') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) # print(db_rec[0]) insertuseraccess = dict() insertuseraccess['values'] = dict() insertuseraccess['values']['userid'] = attempted_username insertuseraccess['values'][ 'logintype'] = attempted_logintype insertuseraccess['values']['usertype'] = attempted_usertype insertuseraccess['values']['entityid'] = entityid insertuseraccess['values']['entitybranchid'] = 'dummy' insertuseraccess['values']['defaultindicator'] = 'N' insertuseraccess['values']['roleid'] = attempted_roleid insertuseraccess['values'][ 'entitywebsite'] = attempted_entitywebsite insertuseraccess['values']['accessstatus'] = 'A' if db_rec is None: print('do something over here') insertuseraccess['action'] = 'update entity' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('update is successful') redata = [{"userid": userid, "entityid": entityid}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: print("fetch results extracted") insertuseraccess['action'] = 'insert' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('Insert is successful') redata = [{"userid": userid, "entityid": entityid}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) elif request.method == "PUT": print("oentity PUT Call For Modify Existing Entity") attempted_username = request.get_json(force=True)['username'] attempted_entityaddline1 = request.get_json( force=True)['entityaddline1'] attempted_entityaddline2 = request.get_json( force=True)['entityaddline2'] attempted_entitycategory = request.get_json( force=True)['entitycategory'] attempted_entitycity = request.get_json(force=True)['entitycity'] attempted_entitycountry = request.get_json(force=True)['entitycountry'] attempted_entitydescription = request.get_json( force=True)['entitydescription'] attempted_entityemail = request.get_json(force=True)['entityemail'] attempted_entityfax = request.get_json(force=True)['entityfax'] attempted_entityfiscalyear = request.get_json( force=True)['entityfiscalyear'] attempted_entityimageurl = request.get_json( force=True)['entityimageurl'] attempted_entityindustry = request.get_json( force=True)['entityindustry'] attempted_entitylogo = request.get_json(force=True)['entitylogo'] attempted_entitymobile = request.get_json(force=True)['entitymobile'] attempted_entityname = request.get_json(force=True)['entityname'] attempted_entityphone = request.get_json(force=True)['entityphone'] attempted_entitypincode = request.get_json(force=True)['entitypincode'] attempted_entityshortname = request.get_json( force=True)['entityshortname'] attempted_entitystartdate = request.get_json( force=True)['entitystartdate'] attempted_entitystate = request.get_json(force=True)['entitystate'] attempted_entitystatus = request.get_json(force=True)['entitystatus'] attempted_entitytaxid = request.get_json(force=True)['entitytaxid'] attempted_entitytimezone = request.get_json( force=True)['entitytimezone'] attempted_entitywebsite = request.get_json(force=True)['entitywebsite'] attempted_muserid = request.get_json(force=True)['muserid'] attempted_roleid = request.get_json(force=True)['roleid'] attempted_logintype = request.get_json(force=True)['logintype'] attempted_usertype = request.get_json(force=True)['usertype'] s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') userid = attempted_username name = 'mangu' signupemail = '*****@*****.**' userstatus = 'A' entityid = 'bansss' countryid = '473874' modifyentity = {} modifyentity['values'] = {} modifyentity['values']['entityaddline1'] = attempted_entityaddline1 modifyentity['values']['entityaddline2'] = attempted_entityaddline2 modifyentity['values']['entitycategory'] = attempted_entitycategory modifyentity['values']['entitycity'] = attempted_entitycity modifyentity['values']['entitycountry'] = attempted_entitycountry modifyentity['values'][ 'entitydescription'] = attempted_entitydescription modifyentity['values']['entityemail'] = attempted_entityemail modifyentity['values']['entityfax'] = attempted_entityfax modifyentity['values']['entityfiscalyear'] = attempted_entityfiscalyear modifyentity['values']['entityimageurl'] = attempted_entityimageurl modifyentity['values']['entityindustry'] = attempted_entityindustry modifyentity['values']['entitylogo'] = attempted_entitylogo modifyentity['values']['entitymobile'] = attempted_entitymobile modifyentity['values']['entityname'] = attempted_entityname modifyentity['values']['entityphone'] = attempted_entityphone modifyentity['values']['entitypincode'] = attempted_entitypincode modifyentity['values']['entityshortname'] = attempted_entityshortname modifyentity['values']['entitystartdate'] = attempted_entitystartdate modifyentity['values']['entitystate'] = attempted_entitystate modifyentity['values']['entitystatus'] = attempted_entitystatus modifyentity['values']['entitytaxid'] = attempted_entitytaxid modifyentity['values']['entitytimezone'] = attempted_entitytimezone modifyentity['values']['entitywebsite'] = attempted_entitywebsite modifyentity['values']['muserid'] = attempted_muserid if s <= 0: cur, s, f1 = processdb.modify_entity(con, cur, modifyentity) if s <= 0: if s < 0: f.append(f1) entityid = cur.fetchone()[0] print('last entity id =', entityid) print('entity database modify results:', s, f, t) getuserentities = {} getuserentities['keys'] = {} getuserentities['keys']['userid'] = attempted_username getuserentities['keys']['entitystatus'] = 'A' if s <= 0: cur, s, f1 = processdb.get_user_entities( con, cur, getuserentities) if s <= 0: if s < 0: f.append(f1) print('fetch is successful') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) # print(db_rec[0]) insertuseraccess = dict() insertuseraccess['values'] = dict() insertuseraccess['values']['userid'] = attempted_username insertuseraccess['values'][ 'logintype'] = attempted_logintype insertuseraccess['values']['usertype'] = attempted_usertype insertuseraccess['values']['entityid'] = entityid insertuseraccess['values']['entitybranchid'] = 'dummy' insertuseraccess['values']['defaultindicator'] = 'N' insertuseraccess['values']['roleid'] = attempted_roleid insertuseraccess['values'][ 'entitywebsite'] = attempted_entitywebsite insertuseraccess['values']['accessstatus'] = 'A' if db_rec is None: print('do something over here') insertuseraccess['action'] = 'update entity' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('update is successful') redata = [{"userid": userid, "entityid": entityid}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: print("fetch results extracted") insertuseraccess['action'] = 'insert' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('Insert is successful') redata = [{"userid": userid, "entityid": entityid}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) elif request.method == "DELETE": print("oentity DELETE Call For Deleting Existing Entity") attempted_entityId = request.args.get('entityid') print(attempted_entityId) s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') userid = attempted_username name = 'mangu' signupemail = '*****@*****.**' userstatus = 'A' # entityid = 'bansss' countryid = '473874' if s <= 0: cur, s, f1 = processdb.delete_entity(con, cur, attempted_userid, attempted_entityId) if s <= 0: if s < 0: f.append(f1) entityid = cur.fetchone()[0] print('last entity id =', entityid) print('entity database modify results:', s, f, t) getuserentities = {} getuserentities['keys'] = {} getuserentities['keys']['userid'] = attempted_username getuserentities['keys']['entitystatus'] = 'A' if s <= 0: cur, s, f1 = processdb.get_user_entities( con, cur, getuserentities) if s <= 0: if s < 0: f.append(f1) print('fetch is successful') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) # print(db_rec[0]) insertuseraccess = dict() insertuseraccess['values'] = dict() insertuseraccess['values']['userid'] = attempted_username insertuseraccess['values'][ 'logintype'] = attempted_logintype insertuseraccess['values']['usertype'] = attempted_usertype insertuseraccess['values']['entityid'] = entityid insertuseraccess['values']['entitybranchid'] = 'dummy' insertuseraccess['values']['defaultindicator'] = 'N' insertuseraccess['values']['roleid'] = attempted_roleid insertuseraccess['values'][ 'entitywebsite'] = attempted_entitywebsite insertuseraccess['values']['accessstatus'] = 'A' if db_rec is None: print('do something over here') insertuseraccess['action'] = 'update entity' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('update is successful') redata = [{"userid": userid, "entityid": entityid}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: print("fetch results extracted") insertuseraccess['action'] = 'insert' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('Insert is successful') redata = [{"userid": userid, "entityid": entityid}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur)
def fetch_app_data_only_wth_tkn(criteria_json): # Description : Fetch app data # Functional use : # Called from : appfuncs.py->ncappfetchfrmtkn # Request data <criteria_json>: # criteria_json = {"entityid": entityid, "countryid": countryid, "payload": <as per below>} # payload = {"userauthtkn": callback_data["regdata"], "appid": settings.NCAPPID,"appkey":settings.NCAPPKEY} # Response from this endpoint: # Field Name success fail # ----------------------------------------------------------- # { # "userauthtkn": new_userauthtkn, BLANK # "tknexpiry": usr_db_rec["tknexpiry"], BLANK # "userid": more_usr_db_rec["userid"], BLANK # "username": more_usr_db_rec["username"], BLANK # "emailid": more_usr_db_rec["sinupemail"], BLANK # "status": success fail # "msg": BLANK fail message # } # called functions: None print("inside fetch_app_data_only_wth_tkn function") s = 0 f = None t = None #message to front end print(criteria_json) payload = criteria_json.get("payload",None) print(payload) if payload == None: appid = None appkey = None userauthtkn = None # s, f, t= errhand.get_status(s, 100, f, "no payload provided", t, "yes") else: if payload.get("appid", None) != None: appid = payload['appid'] else: appid = None s, f, t= errhand.get_status(s, 100, f, "appid not provided", t, "yes") if payload.get("appkey", None) != None: appkey = payload['appkey'] else: appkey = None s, f, t= errhand.get_status(s, 100, f, "appkey not provided", t, "yes") if payload.get("userauthtkn", None) != None: userauthtkn = payload['userauthtkn'] else: userauthtkn = None s, f, t= errhand.get_status(s, 100, f, "usertoken is not provided", t, "yes") print(appid, appkey, userauthtkn) if s <= 0: con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("DB connection established", s,f,t) if s <= 0: command = cur.mogrify(""" SELECT json_agg(a) FROM ( SELECT * FROM ncusr.userauth WHERE tknexpiry >= current_timestamp AND appid = %s AND userauthtkn = %s AND entityid = %s AND countryid = %s ) as a """,(appid, userauthtkn, config.INSTALLDATA[config.LIVE]["entityid"],config.INSTALLDATA[config.LIVE]["countryid"],) ) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "User auth token data fetch failed with DB error", t, "no") print(s,f) usr_db_rec = None if s <= 0: usr_db_rec = cur.fetchall()[0][0] print(usr_db_rec) if usr_db_rec != None: print(len(usr_db_rec)) if usr_db_rec == None or len(usr_db_rec) < 1: s, f, t= errhand.get_status(s, 100, f, "User auth token is not valid", t, "yes") else: usr_db_rec = usr_db_rec[0] print("Userauth token verified successfully") pass print(s,f) if s <= 0: command = cur.mogrify(""" SELECT json_agg(a) FROM ( SELECT * FROM ncapp.appdetail WHERE appid = %s AND appkey = %s AND entityid = %s AND countryid = %s AND delflg != 'Y' ) as a """,(appid, appkey, config.INSTALLDATA[config.LIVE]["entityid"],config.INSTALLDATA[config.LIVE]["countryid"],) ) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "User auth token data fetch failed with DB error", t, "no") print(s,f) app_db_rec = None if s <= 0: app_db_rec = cur.fetchall()[0][0] print(app_db_rec) if app_db_rec != None: print(len(app_db_rec)) if app_db_rec == None or len(app_db_rec) < 1: s, f, t= errhand.get_status(s, 100, f, "App id is not valid", t, "yes") else: app_db_rec = app_db_rec[0] if app_db_rec["approved"] == 'N': s, f, t= errhand.get_status(s, 100, f, "App id not approved yet", t, "yes") else: print("App id verified successfully") print(s,f) if s <= 0: command = cur.mogrify(""" SELECT json_agg(a) FROM ( SELECT * FROM ncusr.userdetails a, ncusr.userlogin b WHERE a.userid = %s AND a.entityid = %s AND a.countryid = %s AND a.userid = b.userid AND a.entityid = b.entityid AND a.countryid = b.countryid ) as a """,(usr_db_rec["userid"], config.INSTALLDATA[config.LIVE]["entityid"],config.INSTALLDATA[config.LIVE]["countryid"],) ) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "User details data fetch failed with DB error", t, "no") print(s,f) more_usr_db_rec = None if s <= 0: more_usr_db_rec = cur.fetchall()[0][0] print(more_usr_db_rec) print(len(more_usr_db_rec)) if more_usr_db_rec == None or len(more_usr_db_rec) < 1: s, f, t= errhand.get_status(s, 100, f, "User details not available for the given auth token", t, "yes") else: more_usr_db_rec = more_usr_db_rec[0] print("user details fetched successfully") pass print(s,f) if s <= 0: #Validate the user status if more_usr_db_rec["userstatus"] == 'B': #B-Blocked , I-Deleteduser s, f, t= errhand.get_status(s, 100, f, "User is blocked", t, "yes") elif more_usr_db_rec["userstatus"] == 'I': #B-Blocked , I-Deleteduser s, f, t= errhand.get_status(s, 100, f, "User is Deleted", t, "yes") if s <= 0: data_to_auth_tkn = { "entityid": config.INSTALLDATA[config.LIVE]["entityid"], "cntryid" : config.INSTALLDATA[config.LIVE]["countryid"], "payload" : { "appid" : app_db_rec["appid"], "redirecturi" : app_db_rec["redirecturi"], "userid" : more_usr_db_rec["userid"] } } ath_tkn_status, ath_tkn_detail = myauth.app_userauth(data_to_auth_tkn) print("new ath_tkn_detail") print(ath_tkn_detail) if ath_tkn_status == "success": s, f, t= errhand.get_status(s, 0, f, "User auth token regenerated", t, "no") new_userauthtkn = ath_tkn_detail["result_data"]["authtkn"] print(new_userauthtkn) else: s, f, t= errhand.get_status(s, 100, f, "error in User auth token regeneration", t, "no") new_userauthtkn = None res_status = None if s <= 0: res_status = "success" user_auth_detais = { "userauthtkn": new_userauthtkn, "tknexpiry": usr_db_rec["tknexpiry"], "userid": more_usr_db_rec["userid"], "username": more_usr_db_rec["username"], "emailid": more_usr_db_rec["sinupemail"], "status": res_status, "msg":"" } else: res_status = "fail" user_auth_detais = { "userauthtkn": "", "userid": "", "username": "", "emailid": "", "status": res_status, "msg": t } print("rached end") return res_status, user_auth_detais
def app_register(criteria_json): print("inside login GET") s = 0 f = None t = None #message to front end response = None res_to_send = 'fail' payload = criteria_json.get("payload",None) print(s) if s <= 0: if criteria_json.get("userid", None) != None: userid = criteria_json['userid'] else: userid = None s, f, t= errhand.get_status(s, 100, f, "user id not provided", t, "yes") if criteria_json.get("entityid", None) != None: entityid = criteria_json['entityid'] else: entityid = None s, f, t= errhand.get_status(s, 100, f, "entity id not provided", t, "yes") if criteria_json.get("cntryid", None) != None: cntryid = criteria_json['cntryid'] else: cntryid = None s, f, t= errhand.get_status(s, 100, f, "cntry code is not provided", t, "yes") if payload == None: s, f, t= errhand.get_status(s, 100, f, "App data not sent. Please try again", t, "yes") else: if payload.get("appname", None) != None: appname = payload['appname'] else: appname = None s, f, t= errhand.get_status(s, 100, f, "No App name provided", t, "yes") if payload.get("appusertype", None) != None: appusertype = payload['appusertype'] else: appusertype = None s, f, t= errhand.get_status(s, 100, f, "App user type not provided", t, "yes") if payload.get("redirecturi", None) != None: redirecturi = payload['redirecturi'] else: redirecturi = None s, f, t= errhand.get_status(s, 100, f, "Redirect URI not provided", t, "yes") if payload.get("postbackuri", None) != None: postbackuri = payload['postbackuri'] else: postbackuri = None s, f, t= errhand.get_status(s, 0, f, "postbackuri not provided", t, "no") if payload.get("description", None) != None: description = payload['description'] else: description = None s, f, t= errhand.get_status(s, -100, f, "description not provided", t, "no") if payload.get("starmfdet", None) != None: starmfdet = payload['starmfdet'] else: starmfdet = None if appusertype not in ['D','A']: s, f, t= errhand.get_status(s, -100, f, "star mf data not provided", t, "yes") else: s, f, t= errhand.get_status(s, -100, f, "star mf data not provided", t, "no") if payload.get("product", None) != None: product = payload['product'] else: product = None s, f, t= errhand.get_status(s, -100, f, "product not provided", t, "no") if payload.get("operation", None) != None: operation = payload['operation'] else: operation = None s, f, t= errhand.get_status(s, -100, f, "operation not provided", t, "no") # update or create are the values if operation == "delete" or operation == "update": if payload.get("appid", None) != None: appid = payload['appid'] else: appid = None s, f, t= errhand.get_status(s, -100, f, "appid not provided", t, "no") if payload.get("appkey", None) != None: appkey = payload['appkey'] else: appkey = None s, f, t= errhand.get_status(s, -100, f, "appkey not provided", t, "no") else: appid = None appkey = None if appusertype == 'T': approved = 'N' else: approved = 'Y' print(appid,"oiipoi", appkey) cur_time = datetime.now().strftime('%Y%m%d%H%M%S') print(appname,appusertype,redirecturi,postbackuri,description,starmfdet) if s <= 0: con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("connection statment done", s,f,t) if s <= 0: command = cur.mogrify(""" SELECT count(1) FROM ncapp.appdetail a WHERE delflg != 'Y' AND ( appname = %s ) AND appuserid = %s AND entityid = %s AND countryid = %s """,(appname, userid, entityid, cntryid,) ) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "App Name data fetch failed with DB error", t, "no") print(s,f) if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) if db_rec > 0: if operation == "create": s, f, t= errhand.get_status(s, 100, f, "App name Already exists for this user", t, "yes") else: if operation == "update" or operation == "delete": s, f, t= errhand.get_status(s, 100, f, "App name doesn't exists for this user", t, "yes") print("no records satifying the current user inputs") print(s,f) appikset = False i = 0 if s <= 0 and operation == "create": while i < 50: r = ''.join(random.choice(string.ascii_letters + string.digits) for x in range(6)) appid = create_signature("sha256", "nirunidhaappid" + r, userid + cur_time, userid) appkey = create_signature("md5", "nirunidhaappkey" + r, userid + cur_time, userid) command = cur.mogrify(""" SELECT count(1) FROM ncapp.appdetail WHERE delflg != 'Y' AND ( appid = %s OR appkey = %s ) """,(appid, appkey,) ) print(command) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status(s, 200, f, "App Name data fetch failed with DB error", t, "no") print(s,f) if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) if db_rec > 0: s, f, t= errhand.get_status(s, 100, f, "Appid or key Already exists for retrying time: " + i, t, "no") i = i + 1 continue else: print("no records satifying the current user inputs") appikset = True break else: # Some error occured, so no point looping appikset = False break print(s,f, t) if s <= 0 and operation == "create" and appikset: s1, f1 = db.mydbbegin(con, cur) print(s1,f1) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s <= 0: command = cur.mogrify(""" INSERT INTO ncapp.appdetail (appname, appusertype, redirecturi, postbackuri, description, starmfdet, appid, appkey, expirydate, approved, product, delflg, appuserid, octime, lmtime, entityid, countryid) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,CURRENT_DATE + INTERVAL'1 month', %s, %s, 'N',%s,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,%s,%s); """,(appname, appusertype, redirecturi, postbackuri, description, starmfdet, appid, appkey, approved, product, userid, entityid, cntryid,)) print(command) print(appname,appusertype,redirecturi,postbackuri,description,starmfdet,userid) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s > 0: s, f, t= errhand.get_status(s, 200, f, "SIGNUP update failed", t, "no") print('Insert or update is successful') if s <= 0: con.commit() #validate PAN adn store PAN number if s <= 0 and operation == "update": s1, f1 = db.mydbbegin(con, cur) print(s1,f1) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s <= 0: command = cur.mogrify(""" UPDATE ncapp.appdetail SET redirecturi = %s, postbackuri = %s, description = %s, starmfdet = %s, lmtime = CURRENT_TIMESTAMP WHERE appname = %s AND appusertype = %s AND appid =%s AND appkey = %s AND product = %s AND appuserid = %s AND entityid = %s AND countryid = %s; """,(redirecturi, postbackuri, description, starmfdet, appname, appusertype, appid, appkey, product, userid, entityid, cntryid,)) print(command) print(appname,appusertype,redirecturi,postbackuri,description,starmfdet,userid) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s > 0: s, f, t= errhand.get_status(s, 200, f, "APP details update failed", t, "no") print('Insert or update is successful') if s <= 0: con.commit() print("commit done") #validate PAN adn store PAN number if s <= 0 and operation == "delete": s1, f1 = db.mydbbegin(con, cur) print(s1,f1) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s <= 0: command = cur.mogrify(""" UPDATE ncapp.appdetail SET delflg = 'Y', lmtime = CURRENT_TIMESTAMP WHERE appname = %s AND appusertype = %s AND appid =%s AND appkey = %s AND product = %s AND appuserid = %s AND entityid = %s AND countryid = %s; """,(appname, appusertype, appid, appkey, product, userid, entityid, cntryid,)) print(command) print(appname,appusertype,redirecturi,postbackuri,description,starmfdet,userid) cur, s1, f1 = db.mydbfunc(con,cur,command) s, f, t= errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None if s > 0: s, f, t= errhand.get_status(s, 200, f, "APP details update failed", t, "no") print('Insert or update is successful') if s <= 0: con.commit() #validate PAN adn store PAN number usrmg_fstr = None if s > 0: res_to_send = 'fail' result_date = [] response = { 'result_data' : result_date, 'status': res_to_send, 'status_code': s, 'usrmsg': errhand.error_msg_reporting(s, t) } else: res_to_send = 'success' result_date = [{'appname': appname, 'appid': appid}] print("**********************") print(operation) print("**********************") if operation == "create": usrmg_fstr = ") creation is successful" elif operation == "update": usrmg_fstr = ") updation is successful" elif operation == "delete": usrmg_fstr = ") deletion is successful" response = { 'result_data' : result_date, 'status': res_to_send, 'status_code': 0, 'usrmsg': 'App (' + appname + usrmg_fstr } print(res_to_send, response) return (res_to_send, response)
def login(): if request.method == "GET": print("oentity") attempted_entityname = request.get_json(force=True)['entityName'] s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_entityname) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') aentityname = attempted_entityname name = 'mangu' signupemail = '*****@*****.**' userstatus = 'A' entityid = 'bansss' countryid = '473874' entitystatus = 'A' if s <= 0: command = cur.mogrify( """ SELECT json_agg(a) FROM ( SELECT entityid,entityname FROM unihot.ownentity WHERE entitystatus = %s AND entityname = %s ) as a """, ( entitystatus, attempted_entityname, )) print(command) cur, s, f1 = db.mydbfunc(con, cur, command) if s <= 0: if s < 0: f.append(f1) print('fetch is successful') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) # print(db_rec[0]) if db_rec is None: print('do something over here') t = 'data couldnt be extracted from fetch results' redata = [{"t": t}] res = make_response(jsonify(redata), 200) return res else: # db_rec = db_rec[0] print("fetch results extracted") pass print(s, f, t) print(db_rec) if s <= 0: # redata = [{"uId": db_rec['userid'], "uName": db_rec['username']}] redata = db_rec res = make_response(jsonify(redata), 200) return res else: return jsonify(False) elif request.method == "POST": print("oentity") attempted_username = request.get_json(force=True)['username'] attempted_password = request.get_json(force=True)['password'] s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username, attempted_password) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') userid = attempted_username name = 'mangu' signupemail = '*****@*****.**' userstatus = 'A' entityid = 'bansss' countryid = '473874' if s <= 0: command = cur.mogrify( """ INSERT INTO unihot.ownentity (userid, username, useremail, userstatus, userstatlstupdt, octime, lmtime,logintype, usertype) VALUES (%s,%s,%s,%s,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP, %s, %s); """, ( userid, name, signupemail, userstatus, 'S', 'A', )) print(command) cur, s, f1 = db.mydbfunc(con, cur, command) if s <= 0: if s < 0: f.append(f1) con.commit() print('Insert or update is successful') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) if s <= 0: db_rec = {'userid': userid, 'username': name} print(db_rec) print(len(db_rec)) # print(db_rec[0]) if db_rec is None: print('do something over here') else: # db_rec = db_rec[0] print("auth.py line 136 user auth successfully") pass print(s, f, t) print(db_rec) if s <= 0: redata = [{"uId": db_rec['userid'], "uName": db_rec['username']}] res = make_response(jsonify(redata), 200) return res else: return jsonify(False)
def entity_branch(): """ This method will handle GET, POST, UPDATE, DELETE request made from the frontend for an entity's branch. GET : It will return all the related entity's branches of a provided userid. POST : It will insert a new branch details in entitybranch table for an entity as well as it will assign that entity to the given useriid in useraccess table, if an entry exists for entitybranchid in useraccess table for tha same userid and it is't dummy then a new record will be inserted otherwise the entitybranchid field will be updated """ if request.method == "GET": print( "oentitybranch GET Call For Listing ALl Entitiy Branches Except 'PUBLIC' Entity " ) # attempted_username = request.get_json(force=True)['username'] # attempted_entityid = request.get_json(force=True)['entityid'] attempted_username = '******' attempted_entityid = 'EN1910201916' s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') entitybranchstatus = 'A' getuserentitybranches = {} getuserentitybranches['keys'] = {} getuserentitybranches['keys']['userid'] = attempted_username getuserentitybranches['keys']['entityid'] = attempted_entityid getuserentitybranches['keys'][ 'entitybranchstatus'] = entitybranchstatus if s <= 0: cur, s, f1 = processdb.get_user_entity_branches( con, cur, getuserentitybranches) if s <= 0: if s < 0: f.append(f1) print('fetch is successful') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) # print(db_rec[0]) if db_rec is None: print('do something over here') t = 'data couldnt be extracted from fetch results' redata = [{"t": t}] res = make_response(jsonify(redata), 200) return res else: # db_rec = db_rec[0] print("fetch results extracted") pass print(s, f, t) print(db_rec) if s <= 0: # redata = [{"uId": db_rec['userid'], "uName": db_rec['username']}] redata = db_rec res = make_response(jsonify(redata), 200) return res else: return jsonify(False) elif request.method == "POST": print("entitybranch POST Call For Insert New Entity Branch") # attempted_username = request.get_json(force=True)['username'] attempted_entityid = request.get_json(force=True)['entityid'] attempted_entitybranchaddline1 = request.get_json( force=True)['entitybranchaddline1'] attempted_entitybranchaddline2 = request.get_json( force=True)['entitybranchaddline2'] attempted_entitybranchcategory = request.get_json( force=True)['entitybranchcategory'] attempted_entitybranchcity = request.get_json( force=True)['entitybranchcity'] attempted_entitybranchcountry = request.get_json( force=True)['entitybranchcountry'] attempted_entitybranchdescription = request.get_json( force=True)['entitybranchdescription'] attempted_entitybranchemail = request.get_json( force=True)['entitybranchemail'] attempted_entitybranchfax = request.get_json( force=True)['entitybranchfax'] attempted_entitybranchimageurl = request.get_json( force=True)['entitybranchimageurl'] attempted_entitybranchmobile = request.get_json( force=True)['entitybranchmobile'] attempted_entitybranchname = request.get_json( force=True)['entitybranchname'] attempted_entitybranchphone = request.get_json( force=True)['entitybranchphone'] attempted_entitybranchpincode = request.get_json( force=True)['entitybranchpincode'] attempted_entitybranchshortname = request.get_json( force=True)['entitybranchshortname'] attempted_entitybranchstartdate = request.get_json( force=True)['entitybranchstartdate'] attempted_entitybranchstate = request.get_json( force=True)['entitybranchstate'] attempted_entitybranchstatus = request.get_json( force=True)['entitybranchstatus'] attempted_entitybranchwebsite = request.get_json( force=True)['entitybranchwebsite'] attempted_muserid = request.get_json(force=True)['muserid'] attempted_roleid = request.get_json(force=True)['roleid'] attempted_logintype = request.get_json(force=True)['logintype'] attempted_usertype = request.get_json(force=True)['usertype'] print('muserid', attempted_muserid) s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') userid = attempted_username insertentitybranch = {} insertentitybranch['values'] = {} insertentitybranch['values']['entityid'] = attempted_entityid insertentitybranch['values'][ 'entitybranchaddline1'] = attempted_entitybranchaddline1 insertentitybranch['values'][ 'entitybranchaddline2'] = attempted_entitybranchaddline2 insertentitybranch['values'][ 'entitybranchcategory'] = attempted_entitybranchcategory insertentitybranch['values'][ 'entitybranchcity'] = attempted_entitybranchcity insertentitybranch['values'][ 'entitybranchcountry'] = attempted_entitybranchcountry insertentitybranch['values'][ 'entitybranchdescription'] = attempted_entitybranchdescription insertentitybranch['values'][ 'entitybranchemail'] = attempted_entitybranchemail insertentitybranch['values'][ 'entitybranchfax'] = attempted_entitybranchfax insertentitybranch['values'][ 'entitybranchimageurl'] = attempted_entitybranchimageurl insertentitybranch['values'][ 'entitybranchmobile'] = attempted_entitybranchmobile insertentitybranch['values'][ 'entitybranchname'] = attempted_entitybranchname insertentitybranch['values'][ 'entitybranchphone'] = attempted_entitybranchphone insertentitybranch['values'][ 'entitybranchpincode'] = attempted_entitybranchpincode insertentitybranch['values'][ 'entitybranchshortname'] = attempted_entitybranchshortname insertentitybranch['values'][ 'entitybranchstartdate'] = attempted_entitybranchstartdate insertentitybranch['values'][ 'entitybranchstate'] = attempted_entitybranchstate insertentitybranch['values'][ 'entitybranchstatus'] = attempted_entitybranchstatus insertentitybranch['values'][ 'entitybranchwebsite'] = attempted_entitybranchwebsite insertentitybranch['values']['muserid'] = attempted_muserid if s <= 0: cur, s, f1 = processdb.insert_entity_branch( con, cur, insertentitybranch) if s <= 0: if s < 0: f.append(f1) entitybranchid = cur.fetchone()[0] print('last entitybranch id =', entitybranchid) print('entitybranch database insert results:', s, f, t) getuserentitybranches = {} getuserentitybranches['keys'] = {} getuserentitybranches['keys']['userid'] = attempted_username getuserentitybranches['keys']['entityid'] = attempted_entityid getuserentitybranches['keys']['entitybranchstatus'] = 'A' if s <= 0: cur, s, f1 = processdb.get_user_entity_branches( con, cur, getuserentitybranches) if s <= 0: if s < 0: f.append(f1) print('fetch is successful for entitybranch') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) # print(db_rec[0]) insertuseraccess = dict() insertuseraccess['values'] = dict() insertuseraccess['values']['userid'] = attempted_username insertuseraccess['values'][ 'logintype'] = attempted_logintype insertuseraccess['values']['usertype'] = attempted_usertype insertuseraccess['values']['entityid'] = attempted_entityid insertuseraccess['values'][ 'entitybranchid'] = entitybranchid insertuseraccess['values']['defaultindicator'] = 'N' insertuseraccess['values']['roleid'] = attempted_roleid insertuseraccess['values'][ 'entitywebsite'] = attempted_entitybranchwebsite insertuseraccess['values']['accessstatus'] = 'A' if db_rec is None: print('do something over here') insertuseraccess['action'] = 'update entitybranch' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('update is successful') redata = [{ "userid": userid, "entityid": attempted_entityid, "entitybranchid": entitybranchid }] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: print("fetch results extracted") insertuseraccess['action'] = 'insert' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('Insert is successful') redata = [{ "userid": userid, "entityid": attempted_entityid, "entitybranchid": entitybranchid }] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) elif request.method == "PUT": print("entitybranch PUT Call For Modify Existing Entity Branch") attempted_username = request.get_json(force=True)['username'] attempted_entityid = request.get_json(force=True)['entityid'] attempted_entitybranchaddline1 = request.get_json( force=True)['entitybranchaddline1'] attempted_entitybranchaddline2 = request.get_json( force=True)['entitybranchaddline2'] attempted_entitybranchcategory = request.get_json( force=True)['entitybranchcategory'] attempted_entitybranchcity = request.get_json( force=True)['entitybranchcity'] attempted_entitybranchcountry = request.get_json( force=True)['entitybranchcountry'] attempted_entitybranchdescription = request.get_json( force=True)['entitybranchdescription'] attempted_entitybranchemail = request.get_json( force=True)['entitybranchemail'] attempted_entitybranchfax = request.get_json( force=True)['entitybranchfax'] attempted_entitybranchimageurl = request.get_json( force=True)['entitybranchimageurl'] attempted_entitybranchmobile = request.get_json( force=True)['entitybranchmobile'] attempted_entitybranchname = request.get_json( force=True)['entitybranchname'] attempted_entitybranchphone = request.get_json( force=True)['entitybranchphone'] attempted_entitybranchpincode = request.get_json( force=True)['entitybranchpincode'] attempted_entitybranchshortname = request.get_json( force=True)['entitybranchshortname'] attempted_entitybranchstartdate = request.get_json( force=True)['entitybranchstartdate'] attempted_entitybranchstate = request.get_json( force=True)['entitybranchstate'] attempted_entitybranchstatus = request.get_json( force=True)['entitybranchstatus'] attempted_entitybranchwebsite = request.get_json( force=True)['entitybranchwebsite'] attempted_muserid = request.get_json(force=True)['muserid'] attempted_roleid = request.get_json(force=True)['roleid'] attempted_logintype = request.get_json(force=True)['logintype'] attempted_usertype = request.get_json(force=True)['usertype'] print('muserid', attempted_muserid) s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') userid = attempted_username modifyentitybranch = {} modifyentitybranch['values'] = {} modifyentitybranch['values']['entityid'] = attempted_entityid modifyentitybranch['values'][ 'entitybranchaddline1'] = attempted_entitybranchaddline1 modifyentitybranch['values'][ 'entitybranchaddline2'] = attempted_entitybranchaddline2 modifyentitybranch['values'][ 'entitybranchcategory'] = attempted_entitybranchcategory modifyentitybranch['values'][ 'entitybranchcity'] = attempted_entitybranchcity modifyentitybranch['values'][ 'entitybranchcountry'] = attempted_entitybranchcountry modifyentitybranch['values'][ 'entitybranchdescription'] = attempted_entitybranchdescription modifyentitybranch['values'][ 'entitybranchemail'] = attempted_entitybranchemail modifyentitybranch['values'][ 'entitybranchfax'] = attempted_entitybranchfax modifyentitybranch['values'][ 'entitybranchimageurl'] = attempted_entitybranchimageurl modifyentitybranch['values'][ 'entitybranchmobile'] = attempted_entitybranchmobile modifyentitybranch['values'][ 'entitybranchname'] = attempted_entitybranchname modifyentitybranch['values'][ 'entitybranchphone'] = attempted_entitybranchphone modifyentitybranch['values'][ 'entitybranchpincode'] = attempted_entitybranchpincode modifyentitybranch['values'][ 'entitybranchshortname'] = attempted_entitybranchshortname modifyentitybranch['values'][ 'entitybranchstartdate'] = attempted_entitybranchstartdate modifyentitybranch['values'][ 'entitybranchstate'] = attempted_entitybranchstate modifyentitybranch['values'][ 'entitybranchstatus'] = attempted_entitybranchstatus modifyentitybranch['values'][ 'entitybranchwebsite'] = attempted_entitybranchwebsite modifyentitybranch['values']['muserid'] = attempted_muserid if s <= 0: cur, s, f1 = processdb.modify_entity_branch( con, cur, modifyentitybranch) if s <= 0: if s < 0: f.append(f1) entitybranchid = cur.fetchone()[0] print('last entitybranch id =', entitybranchid) print('entitybranch database insert results:', s, f, t) getuserentitybranches = {} getuserentitybranches['keys'] = {} getuserentitybranches['keys']['userid'] = attempted_username getuserentitybranches['keys']['entityid'] = attempted_entityid getuserentitybranches['keys']['entitybranchstatus'] = 'A' if s <= 0: cur, s, f1 = processdb.get_user_entity_branches( con, cur, getuserentitybranches) if s <= 0: if s < 0: f.append(f1) print('fetch is successful for entitybranch') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) # print(db_rec[0]) insertuseraccess = dict() insertuseraccess['values'] = dict() insertuseraccess['values']['userid'] = attempted_username insertuseraccess['values'][ 'logintype'] = attempted_logintype insertuseraccess['values']['usertype'] = attempted_usertype insertuseraccess['values']['entityid'] = attempted_entityid insertuseraccess['values'][ 'entitybranchid'] = entitybranchid insertuseraccess['values']['defaultindicator'] = 'N' insertuseraccess['values']['roleid'] = attempted_roleid insertuseraccess['values'][ 'entitywebsite'] = attempted_entitybranchwebsite insertuseraccess['values']['accessstatus'] = 'A' if db_rec is None: print('do something over here') insertuseraccess['action'] = 'update entitybranch' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('update is successful') redata = [{ "userid": userid, "entityid": attempted_entityid, "entitybranchid": entitybranchid }] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: print("fetch results extracted") insertuseraccess['action'] = 'insert' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('Insert is successful') redata = [{ "userid": userid, "entityid": attempted_entityid, "entitybranchid": entitybranchid }] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) elif request.method == "DELETE": print("oentitybranch DELETE Call For Deleting Existing EntityBranch") attempted_entityId = request.args.get('entityid') attempted_entityBranchId = request.args.get('entitybranchid') print(attempted_entityId) print(attempted_entityBranchId) s = 0 f = [] # logs for tech guys t = None # message to front end f1 = None # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username) print("here") # if s <= 0: # con, cur, s1, f1 = db.mydbopncon() # s, f, t = errhand.get_status(s, s1, f, f1, t, "no") # s1, f1 = 0, None # print("DB connection established", s, f, t) if s <= 0: con, cur, s, f1 = db.mydbopncon() if s <= 0: if s < 0: f.append(f1) print("DB connection established", s, f, t) else: print("DB connection not established", s, f, t) f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') userid = attempted_username if s <= 0: cur, s, f1 = processdb.delete_entity_branch( con, cur, attempted_userid, attempted_entityId, attempted_entityBranchId) if s <= 0: if s < 0: f.append(f1) entitybranchid = cur.fetchone()[0] print('last entitybranch id =', entitybranchid) print('entitybranch database insert results:', s, f, t) getuserentitybranches = {} getuserentitybranches['keys'] = {} getuserentitybranches['keys']['userid'] = attempted_username getuserentitybranches['keys']['entityid'] = attempted_entityid getuserentitybranches['keys']['entitybranchstatus'] = 'A' if s <= 0: cur, s, f1 = processdb.get_user_entity_branches( con, cur, getuserentitybranches) if s <= 0: if s < 0: f.append(f1) print('fetch is successful for entitybranch') else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) # print(db_rec[0]) insertuseraccess = dict() insertuseraccess['values'] = dict() insertuseraccess['values']['userid'] = attempted_username insertuseraccess['values'][ 'logintype'] = attempted_logintype insertuseraccess['values']['usertype'] = attempted_usertype insertuseraccess['values']['entityid'] = attempted_entityid insertuseraccess['values'][ 'entitybranchid'] = entitybranchid insertuseraccess['values']['defaultindicator'] = 'N' insertuseraccess['values']['roleid'] = attempted_roleid insertuseraccess['values'][ 'entitywebsite'] = attempted_entitybranchwebsite insertuseraccess['values']['accessstatus'] = 'A' if db_rec is None: print('do something over here') insertuseraccess['action'] = 'update entitybranch' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('update is successful') redata = [{ "userid": userid, "entityid": attempted_entityid, "entitybranchid": entitybranchid }] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: print("fetch results extracted") insertuseraccess['action'] = 'insert' cur, s, f1 = processdb.insert_update_useraccess( con, cur, insertuseraccess) print('useraccess database insert results:', f, t) if s <= 0: if s < 0: f.append(f1) con.commit() print('Insert is successful') redata = [{ "userid": userid, "entityid": attempted_entityid, "entitybranchid": entitybranchid }] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res else: f.append(f1) t = errhand.set_t(s) redata = [{"f": f, "t": t}] res = make_response(jsonify(redata), 200) return res f.append('warning 1 : testing') print('here 2 s,f,t', s, f, t) print(cur)
def login(): if request.method == "POST": print("osignup") attempted_username = request.get_json(force=True)['username'] attempted_password = request.get_json(force=True)['password'] s = 0 f = None t = None # message to front end # attempted_username = '******' # attempted_password = '******' branchid = "test" hotelid = "test" print(attempted_username, attempted_password) print("here") if s <= 0: con, cur, s1, f1 = db.mydbopncon() s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print("DB connection established", s, f, t) if s <= 0: command = cur.mogrify( """ INSERT INTO ncusr.userlogin (userid, username, useremail, userstatus, userstatlstupdt, octime, lmtime, entityid, countryid) VALUES (%s,%s,%s,%s,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,%s,%s); """, ( userid, name, sinupemail, userstatus, entityid, countryid, )) print(command) cur, s1, f1 = db.mydbfunc(con, cur, command) s, f, t = errhand.get_status(s, s1, f, f1, t, "no") s1, f1 = 0, None print('----------------') print(s) print(f) print('----------------') if s > 0: s, f, t = errhand.get_status( s, 200, f, "App Name data fetch failed with DB error", t, "no") print(s, f) db_rec = None if s <= 0: db_rec = cur.fetchall()[0][0] print(db_rec) print(len(db_rec)) print(db_rec[0]) if db_rec == None or len(db_rec) > 1: s, f, t = errhand.get_status(s, 100, f, "User authentication failed", t, "yes") else: db_rec = db_rec[0] print("auth.py line 136 user auth successfully") pass print(s, f, t) print(db_rec) if s <= 0: redata = [{"uId": db_rec['uid'], "uName": db_rec['uname']}] res = make_response(jsonify(redata), 200) return res else: return jsonify(False)