def mydbfunc(con, cur, command): s = 0 f = None t = None try: cur.execute(command) except psycopg2.Error as e: print(e) """ print(type(e)) print(e.diag) print(e.args) print(e.cursor) print(e.pgcode) print(e.pgerror) myerror= {'natstatus':'error','statusdetails':''} """ s, f, t = errhand.get_status(s, 200, f, e.pgcode + e.pgerror, t, "no") except psycopg2.Warning as e: print(e) #myerror={'natstatus':'warning','statusdetails':''} #myerror = {'natstatus':'warning','statusdetails':e} s, f = errhand.get_status(s, -100, f, e.pgcode + e.pgerror, t, "no") finally: if s > 0: con.rollback() cur.close() con.close() return cur, s, f
def allow_regis_user(db_json_rec, pyld): print("inside allow_regis_user") s = 0 f = None t = None #message to front end stat = "success" usrmsg = None if db_json_rec: for rec in db_json_rec: if rec['userid'] != '': if rec['userid'] == pyld["uid"]: s, f, t= errhand.get_status(s, 100, f, "Userid Already exists for the Email id", t, "yes") stat = "fail" if rec['useremail'] != '': if rec['useremail'] == pyld["nc_email"]: s, f, t= errhand.get_status(s, 100, f, "Email Already registered", t, "yes") stat = "fail" ''' if stat != "fail": if rec['sinupadhaar'] != '': if rec['sinupadhaar'] == pyld["sinupadhaar"]: s, f, t= errhand.get_status(s, 100, f, "Adhaar Already registered", t, "no") if rec['sinuppan'] != '': if rec['sinuppan'] == pyld["sinuppan"]: s, f, t= errhand.get_status(s, 100, f, "PAN Already registered", t, "no") if rec['sinuparn'] != '': if rec['sinuparn'] == pyld["sinuparn"]: s, f, t= errhand.get_status(s, 100, f, "ARN Already registered", t, "no") if rec['sinupmobile'] != '': if rec['sinupmobile'] == pyld["sinupmobile"]: s, f, t= errhand.get_status(s, 100, f, "Mobile Already registered", t, "no") if s > 0: #incase one of the above already exists if rec["usercusttype"] == pyld["usercusttype"]: s, f, t= errhand.get_status(s, 100, f, "Userid Already exists with same Adhaar/PAN/ARN/MOBILE for selected cust type (ie...Resigter as)", t, "yes") stat = "fail" ''' else: print("no records satifying the current user inputs") print(pyld) print(db_json_rec) if stat == "fail": usrmsg = errhand.error_msg_reporting(s, t) return stat, usrmsg
def get_custom_token(uid): print("inside get_custom_token function") s = 0 f = None t = None #message to front end usrmsg = None rec_status ="fail" #create firebase custom token for users. #nc_usr_data #initialise the Firebase app try: print('inside try') default_app = firebase_admin.get_app('acfbapp') print('about inside try') except ValueError: print('inside value error') #cred = credentials.Certificate(os.path.dirname(__file__)+'/serviceAccountKey.json') cred = credentials.Certificate(settings.FBSERVICEAC) default_app = firebase_admin.initialize_app(credential=cred,name='acfbapp') s, f, t= errhand.get_status(s, 0, f, "Firebase app initialised", t, "no") else: pass print('app initialisation completed') if s <= 0: rec_status ="success" custom_token = auth.create_custom_token(uid,app=default_app) return custom_token.decode("utf-8")
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 mydbbegin(con, cur): s = 0 f = None t = None command = cur.mogrify("BEGIN;") cur, s, f = mydbfunc(con, cur, command) if cur.closed == True: s, f, t = errhand.get_status(s, 200, f, "BEGIN statement execution failed", t, "no") else: print("BEGIN statment execution successful") return s, f
def mydbopncon(): s = 0 f = None t = None try: con except NameError: print("con not defined so assigning as null") #conn_string = "host='localhost' dbname='postgres' user='******' password='******'" #conn_string = "host='assetscube.c5eo06dso01d.ap-south-1.rds.amazonaws.com' dbname='nawalcube' user='******' password='******'" conn_string = CON_STR[ENV] print('after conn string') try: print('preparing con') con = psycopg2.connect(conn_string) except Exception as e: print("unable to connect") s, f = errhand.get_status(s, 201, f, e.pgcode + e.pgerror, t, "no") print(e) finally: print("unable to connect finally") print('con') print(con) cur = con.cursor(cursor_factory=psycopg2.extras.DictCursor) print('cur') print(cur) else: if con.closed: #conn_string = "host='localhost' dbname='postgres' user='******' password='******'" #conn_string = "host='assetscube.c5eo06dso01d.ap-south-1.rds.amazonaws.com' dbname='nawalcube' user='******' password='******'" conn_string = CON_STR[ENV] try: print('preparing con') con = psycopg2.connect(conn_string) except Exception as e: print("unable to connect") print(e) else: cur = con.cursor(cursor_factory=psycopg2.extras.DictCursor) print('connection successful') return con, cur, s, f
def ncclbk_login_handler(pyldjson): print("inside ncclbk_login_handler function") s = 0 f = None t = None #message to front end usrmsg = None rec_status ="fail" callback_data = pyldjson print("nc ncclbk_login_handler handler") if callback_data["regdata"] == '401': # show error page print("login handler error") callbk_proc_data ={ "typ": "login", "regdata": "401", "msg": "Login failed. Please retry. If problem persists, please conatact support" } return "fail", callbk_proc_data else: #Get pass token from nawalcube data_for_passtkn = { "entityid" : callback_data["entityid"], "countryid" : callback_data["countryid"], "userauthtkn" : callback_data["regdata"] } status,linked_apps_lst = nc_pass_tkn(data_for_passtkn) if status > 0: s, f, t = errhand.get_status(s, 200, f, "NC pass token get failed", t, "no") if s <= 0: rec_status, callbk_proc_data = what_pg_to_show(linked_apps_lst) if s > 0: rec_status = "fail" callbk_proc_data = "" return rec_status, callbk_proc_data
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 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 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 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_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 == "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)
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 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 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 ncclbk_singup_handler(callback_data): # handler for nawalcube signup #callback_data #{type: "signup", callbkfrm: "nawalcube", regdata: "a96f2d792641cd049c974e3c9e330f99", msg: "success", "entityid": "ac", countryid: "IN"} print("inside ncclbk_singup_handler function") s = 0 f = None t = None #message to front end usrmsg = None rec_status ="fail" print("nc signup handler") if callback_data["regdata"] == '401': # show error page print("signup handler error") callbk_proc_data ={ "typ": "signup", "regdata": "401", "msg": "Registered failed. Please retry. If problem persists, please conatact support" } return "fail", callbk_proc_data else: # Please register user and confirm #Get data from nawalcube entityid = callback_data["entityid"] countryid = callback_data["countryid"] headers = {"entityid": entityid, "countryid": countryid} req_payload = {"userauthtkn": callback_data["regdata"], "appid": settings.NCAPPID[settings.LIVE],"appkey":settings.NCAPPKEY[settings.LIVE]} print("###########################") print(req_payload) print(type(req_payload)) print("###########################") r = requests.post(settings.NCSIGNUPDATAFETCHURL[settings.LIVE], headers=headers, data=json.dumps(req_payload)) nc_usr_data = json.loads(r.content.decode("utf-8") ) print(json.loads(r.content.decode("utf-8"))) # Response we get: # 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 # } print('i see') if nc_usr_data["status"] == "success": nc_email = nc_usr_data["emailid"] nc_userauthtkn = nc_usr_data["userauthtkn"] nc_tknexpiry = nc_usr_data["tknexpiry"] nc_usrid = nc_usr_data["userid"] nc_usrname = nc_usr_data["username"] uid = None #initialise the Firebase app try: print('inside try') default_app = firebase_admin.get_app('acfbapp') print('about inside try') except ValueError: print('inside value error') #cred = credentials.Certificate(os.path.dirname(__file__)+'/serviceAccountKey.json') cred = credentials.Certificate(settings.FBSERVICEAC) default_app = firebase_admin.initialize_app(credential=cred,name='acfbapp') s, f, t= errhand.get_status(s, 0, f, "Firebase app initialised", t, "no") else: pass print('app initialisation completed') #TO check if the email already exists useridex = False if s <= 0: try: user = auth.get_user_by_email(nc_email,app=default_app) except auth.AuthError as e: print(str(e.args)) s, f, t= errhand.get_status(s, 0, f, ''.join(e.args), t, "no") except Exception as inst: print(inst.args) print(inst) s, f, t= errhand.get_status(s, 0, f, inst, t, "no") else: print('Successfully fetched user data: {0}'.format(user.uid)) if user.uid != None or user.uid != "": useridex = True uid = user.uid print("user details fetch successful") s, f, t= errhand.get_status(s, 0, f, " email already registered.", t, "no") #usrmsg = "email already registered." print(useridex) #If email already exists skip fb user creation if s <= 0 and (not useridex): try: user = auth.create_user(email=nc_email,app=default_app) except auth.AuthError as e: print(auth.ErrorInfo) #e.code == "USER_CREATE_ERROR": print(e.code) print(e.detail) print("Auth error while creating user") s, f, t= errhand.get_status(s, 100, f, "User registration failed. Please cotact support [ac error]", t, "yes") except ValueError as e: print("value error while creating user") s, f, t= errhand.get_status(s, 0, f, "Firebase app user details fetch failed", t, "no") s, f, t= errhand.get_status(s, 100, f, "User registration failed. Please cotact support [ac error]", t, "yes") else: print(user.uid) print(format(user)) uid = user.uid print("inside callback singup success") else: s, f, t= errhand.get_status(s, 100, f, "User registration failed.<br> Please contact support [nc fetch].", t, "yes") if s <= 0: sav_usr = { "uid": uid, "nc_email" : nc_email, "nc_userauthtkn" : nc_userauthtkn, "nc_tknexpiry" : nc_tknexpiry, "nc_usrid" : nc_usrid, "nc_usrname" : nc_usrname, "nc_entity": "NAWALCUBE", "entityid" : entityid, "countryid": countryid } sav_status, sav_resp_rec = save_usr_details(sav_usr) if sav_status != "success": print(sav_resp_rec) s, f, t= errhand.get_status(s, 100, f, "User registration failed.<br> Please contact support [ac db update].", t, "yes") if s <= 0: rec_status ="success" if usrmsg == None: usrmsg = "User registered successfully. Please reset password before first login" else: usrmsg = "User registered successfully. Please reset password before first login. "+ usrmsg callbk_proc_data = { "typ": "signup", "regdata": "200", "email" : nc_email, "msg": usrmsg } else: rec_status ="fail" usrmsg = "Registration failed. Please retry. <br> If problem persists, please conatact support" callbk_proc_data ={ "typ": "signup", "regdata": "401", "email" : nc_email, "msg": usrmsg } return rec_status, callbk_proc_data
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 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 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