コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
ファイル: appfuncs.py プロジェクト: natrayanp/nawalcubeserver
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)