Exemplo n.º 1
0
def updateServiceContact():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    _req = request.json
    try:
        if apiAuth.apiAuth(token, userid) == True:
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute(
                "update servicecontactinfo set name=%s, phone=%s, cell=%s, fax=%s, tollfree=%s, email=%s, website=%s, facebook=%s, twitter=%s, instagram=%s, youtube=%s where idserviceContactInfo=%s",
                (_req['conPerson'], _req['conPhone'], _req['conMobile'],
                 _req['conFax'], _req['conTollfree'], _req['conEmail'],
                 _req['conWebsite'], _req['conFacebook'], _req['conTwitter'],
                 _req['conInstagram'], _req['conYoutube'], _req['conId']))
            conn.commit()
            response = jsonify("success")
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 200
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 2
0
def addService():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    _req = request.json
    try:
        if apiAuth(token, userid) == True:
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            serviceid = validateServiceId(conn, cur)
            if _req['company'] == "true":
                companyid = _req["companyid"]
                if (serviceid != 0):
                    cur.execute(
                        "insert into services(idservices, name, building, street, landmark, area, pincode, state, country, companyid, serviceUserFK,verified,city) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                        (serviceid, _req['sname'], _req['sbuilding'],
                         _req['sstreet'], _req['slandmark'], _req['sarea'],
                         _req['spincode'], _req['sstate'], _req['scountry'],
                         companyid, userid, 0, _req['scity']))
                    conn.commit()
                    data = {
                        "serviceId": serviceid,
                        "status": "Service added successfully"
                    }
                    response = jsonify(data)
                    response.status_code = 200
                    return response
                else:
                    data = {
                        "serviceId": serviceid,
                        "status": "Creation unsuccessful"
                    }
                    response = jsonify(data)
                    response.status_code = 200
                    return response
            else:
                cur.execute(
                    "insert into services(idservices, name, building, street, landmark, area, pincode, state, country, companyid, serviceUserFK) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, %s)",
                    (serviceid, _req['sname'], _req['sbuilding'],
                     _req['sstreet'], _req['slandmark'], _req['sarea'],
                     _req['spincode'], _req['sstate'], _req['scountry'], 0,
                     userid))
                conn.commit()
                data = {
                    "serviceId": serviceid,
                    "status": "Service added successfully"
                }
                response = jsonify(data)
                response.status_code = 200
                return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        response = jsonify("Database Error")
        response.status_code = 200
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 3
0
def getScheduleInfo():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    schId = request.args.get('schId')
    pId = request.args.get('pId')
    try:
        if apiAuth.apiAuth(token, userid):
            _req = request.json
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute("select * from scheduletable where scheduleId=%s",
                        schId)
            response = {"schedule": cur.fetchall()}
            cur.execute(
                "select * from paymentoptions where idpaymentoptions=%s",
                int(pId))
            response["payment"] = cur.fetchall()
            response = jsonify(response)
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 500
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 4
0
def getCompanyServices():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    try:
        if apiAuth.apiAuth(token, userid) == True:
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute("select * from companydetails where emailKey=%s",(userid))
            companies = cur.fetchall()
            response = {"companyCount":len(companies), "companiesList" :companies}
            cur.execute("select * from services where serviceUserFK=%s",(userid))
            services = cur.fetchall()
            for i in services:
                i["image"] = "";
            response["serviceCount"] = len(services)
            response["serviceList"] = services
            response = jsonify(response)
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 500
        return response
    finally:
        cur.close();
        conn.close();
Exemplo n.º 5
0
def getMyMoreInfo():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    serviceid = request.args.get('serviceId')
    try:
        if apiAuth.apiAuth(token, userid):
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute(
                "select * from servicecontactinfo where servicecontackfk=%s",
                (serviceid))
            response = {"contact": cur.fetchall()}
            cur.execute("select * from scheduletable where serviceId=%s",
                        (serviceid))
            response["schedule"] = cur.fetchall()
            cur.execute("select * from keywords where servicekeywordsfk=%s",
                        (serviceid))
            response["keywords"] = cur.fetchall()
            response = jsonify(response)
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 500
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 6
0
def reviewwriting():
    try:
        conn = mysql.connect()
        cur = conn.cursor(pymysql.cursors.DictCursor)
        formdata = request.json
        print(formdata)
        userid = request.args.get('userid')
        token = request.args.get('tok')
        if apiAuth.apiAuth(userid,token) == True :
            serviceid = request.args.get('serviceid')
            reviewid = validateReviewId(conn, cur);
            cur.execute("insert into review(review_key,r_userid,r_serviceid,r_stars,r_header,r_content) values(%s,%s,%s,%s,%s,%s)",
                        (reviewid, userid, serviceid, formdata['star'], formdata['header'], formdata['content']))
            conn.commit()
            response = jsonify("Review added successfully")
            response.status_code = 200
            return response
        else:
            response = jsonify("unauthorised")
            response.status_code = 403
            return response
    except Exception as e:
        print(e)
        response = jsonify('Error occured')
        response.status_code = 500
        return response
    finally:
        conn.close()
        cur.close()
Exemplo n.º 7
0
def updateKeywords():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    try:
        if apiAuth.apiAuth(token, userid):
            _req = request.json
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute(
                "update keywords set keywordstext=%s where keywordsid=%s", (
                    _req['keywords'],
                    _req['keywordid'],
                ))
            conn.commit()
            response = jsonify("success")
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 500
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 8
0
def updateServiceSchedule():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    _req = request.json
    try:
        if apiAuth.apiAuth(token, userid) == True:
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            scheduleid = _req['schid']
            paymentid = _req['pid']
            cur.execute("update scheduletable set monStart=%s, monEnd=%s, tueStart=%s, tueEnd=%s, wedStart=%s, wedEnd=%s, thurStart=%s, thurEnd=%s, friStart=%s, friEnd=%s, satStart=%s, satEnd=%s, sunStart=%s, sunEnd=%s where scheduleId=%s",
                        (_req['monBeg'], _req['monEnd'], _req['tueBeg'], _req['tueEnd'], _req['wedBeg'], _req['wedEnd'], _req['thurBeg'], _req['thurEnd'],
                         _req['friBeg'],_req['friEnd'],_req['satBeg'], _req['satEnd'], _req['sunBeg'], _req['sunEnd'], scheduleid))
            conn.commit()
            cur.execute("update paymentoptions set cash=%s,card=%s,onlinepayments=%s where idpaymentoptions=%s",
                        (_req['cash'], _req['card'], _req['digi'], paymentid))
            conn.commit()
            response = jsonify("success")
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error"+e)
        response.status_code = 500
        return response
    finally:
        cur.close();
        conn.close();
Exemplo n.º 9
0
def findService():
    try:
        _req = request.json
        text = _req["searchText"]
        print(text)
        tokens = getKeywords(text)
        resultServices = []
        serviceData = []
        conn = mysql.connect()
        cur = conn.cursor(pymysql.cursors.DictCursor)
        for i in tokens:
            cur.execute(
                "select servicekeywordsfk from keywords where keywordstext like '%"
                + i + "%'")
            temp = cur.fetchall()
            for i in temp:
                resultServices.append(i["servicekeywordsfk"])
        resultServices = list(set(resultServices))
        for i in resultServices:
            cur.execute(
                "SELECT * FROM nilgiriconnect.services join nilgiriconnect.servicecontactinfo on nilgiriconnect.services.idservices = nilgiriconnect.servicecontactinfo.servicecontackfk join nilgiriconnect.scheduletable on nilgiriconnect.scheduletable.serviceId = nilgiriconnect.services.idservices  where nilgiriconnect.services.idservices = %s",
                (i))
            serviceData.append(cur.fetchall()[0])
        response = jsonify(serviceData)
        return response
    except Exception as e:
        print(e)
Exemplo n.º 10
0
def updateServiceInfo():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    try:
        if apiAuth.apiAuth(token, userid):
            _req = request.json
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute(
                "update services set name = %s, building=%s, street=%s, landmark=%s, area=%s, pincode=%s, state=%s, country=%s where idservices=%s",
                (_req['sname'], _req['sbuilding'], _req['sstreet'],
                 _req['slandmark'], _req['sarea'], _req['spincode'],
                 _req['sstate'], _req['scountry'], _req['servId']))
            conn.commit()
            response = jsonify("success")
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 500
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 11
0
def getContactInfo():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    contactId = request.args.get('conId')
    try:
        if apiAuth.apiAuth(token, userid):
            _req = request.json
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute(
                "select * from servicecontactinfo where idserviceContactInfo=%s",
                contactId)
            response = jsonify(cur.fetchall())
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 500
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 12
0
def updateCompany():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    try:
        if apiAuth.apiAuth(token, userid):
            _req = request.json
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute(
                "update companydetails set name = %s, city = %s, phone = %s, mobile = %s, firstName = %s, lastName = %s where idcompany = %s",
                (_req['compName'], _req['compCity'], _req['compPhone'],
                 _req['compMob'], _req['compFName'], _req['compLName'],
                 _req['compId']))
            conn.commit()
            response = jsonify("success")
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 500
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 13
0
def updateCompanyGrouping():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    try:
        if apiAuth.apiAuth(token, userid):
            _req = request.json
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute(
                "update services set companyId = %s where idservices=%s",
                (_req['compId'], _req['servId']))
            conn.commit()
            response = jsonify("success")
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 500
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 14
0
def addServiceSchedule():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    _req = request.json
    try:
        if apiAuth(token, userid) == True:
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            scheduleid = validateScheduleId(conn, cur)
            paymentid = validatePaymentId(conn, cur)
            serviceid = _req["serviceid"]
            if (scheduleid != 0 and paymentid != 0):
                cur.execute(
                    "insert into scheduletable(scheduleId, serviceId, monStart, monEnd, tueStart, tueEnd, wedStart, wedEnd, thurStart, thurEnd, friStart, friEnd, satStart, satEnd, sunStart, sunEnd) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                    (scheduleid, serviceid, _req['monBeg'], _req['monEnd'],
                     _req['tueBeg'], _req['tueEnd'], _req['wedBeg'],
                     _req['wedEnd'], _req['thurBeg'], _req['thurEnd'],
                     _req['friBeg'], _req['friEnd'], _req['satBeg'],
                     _req['satEnd'], _req['sunBeg'], _req['sunEnd']))
                conn.commit()
                cur.execute(
                    "update services set scheduleid = %s where idservices = %s",
                    (scheduleid, serviceid))
                conn.commit()
                cur.execute(
                    "Insert into paymentoptions(idpaymentoptions,idservice,cash,card,onlinepayments) values(%s,%s,%s,%s,%s)",
                    (paymentid, serviceid, _req['cash'], _req['card'],
                     _req['digi']))
                conn.commit()
                cur.execute(
                    "update services set paymentid = %s where idservices = %s",
                    (paymentid, serviceid))
                conn.commit()
                data = {
                    "serviceId": serviceid,
                    "status": "Schedule and payment added successfully"
                }
                response = jsonify(data)
                response.status_code = 200
                return response
            else:
                data = {
                    "serviceId": serviceid,
                    "status": "Creation unsuccessful"
                }
                response = jsonify(data)
                response.status_code = 200
                return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 200
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 15
0
def userAuth():
    try:
        conn = mysql.connect()
        cur = conn.cursor(pymysql.cursors.DictCursor)
        cur.execute("select password,role from user where email = '" +
                    request.json['userid'] + "';")
        rows = cur.fetchall()
        if len(rows) == 0:
            response = jsonify('InvalidUser')
        else:
            check = auth.check_encrypted_password(request.json['password'],
                                                  rows[0]['password'])
            if check == True:
                response = {
                    "key": generateKey(request.json['userid']),
                    "role": rows[0]['role']
                }
                response = jsonify(response)
                print(response)
                if response == False:
                    response = jsonify('False')
            else:
                response = jsonify('AuthenticationFailed')
        response.status_code = 200
        return response
    except Exception as e:
        response = jsonify('Error occured')
        response.status_code = 500
        print(e)
        return response
    finally:
        conn.close()
        cur.close()
Exemplo n.º 16
0
def findService():
    try:
        _req = request.json
        text = _req["searchText"]
        print(text)
        tokens = getKeywords(text)
        resultServices = []
        serviceData = []
        print(tokens)
        conn = mysql.connect()
        cur = conn.cursor(pymysql.cursors.DictCursor)
        for i in tokens:
            cur.execute(
                "select servicekeywordsfk from keywords where keywordstext like '%"
                + i + "%'")
            temp = cur.fetchall()
            for i in temp:
                print(i["servicekeywordsfk"])
                resultServices.append(i["servicekeywordsfk"])
        resultServices = list(set(resultServices))
        for i in resultServices:
            cur.execute(
                "SELECT idservices, services.name, building, street, landmark, area, pincode, state, country, companyid, serviceUserFK FROM services join servicecontactinfo on services.idservices = servicecontactinfo.servicecontackfk join scheduletable on scheduletable.serviceId = services.idservices  where services.idservices = %s",
                (i))
            serviceData.append(cur.fetchall()[0])
        print(serviceData)
        response = jsonify(serviceData)
        return response
    except Exception as e:
        print(e)
Exemplo n.º 17
0
def getApCompanies():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    try:
        if apiAuth.apiAuth(token, userid) == True:
            if request.args.get('role') == "AP":
                conn = mysql.connect()
                cur = conn.cursor(pymysql.cursors.DictCursor)
                _req = request.json
                cur.execute(
                    "select idservices, name, building, street, landmark, area, pincode, state, country, companyid, serviceUserFK from services where verified=0;"
                )
                conn.commit()
                response = jsonify(cur.fetchall())
                response.status_code = 200
                return response
            else:
                response = jsonify("false")
                response.status_code = 200
                return response
        else:
            response = jsonify('Unauthorized Access')
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify('Server Error')
        response.status_code = 500
        return response
Exemplo n.º 18
0
def changePassword():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    try:
        if apiAuth.apiAuth(token, userid) == True:
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            _req = request.json
            cur.execute("select password from user where email = %s;",
                        (userid))
            rows = cur.fetchall()
            check = auth.check_encrypted_password(_req['curPass'],
                                                  rows[0]['password'])
            if check == True:
                _encrpass = auth.encrypt_password(_req['newPass'])
                cur.execute("update user set password = %s where email = %s",
                            (_encrpass, userid))
                conn.commit()
                response = jsonify("success")
            elif check == False:
                response = jsonify("invalid")
                response.status_code = 200
            return response
        else:
            response = jsonify('Unauthorized Access')
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify('Server Error')
        response.status_code = 500
        return response
Exemplo n.º 19
0
def getServiceImage():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    sid = request.args.get('sid')
    try:
        if apiAuth.apiAuth(token, userid) == True:
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute("select image from services where idservices=%s",
                        (sid))
            image = cur.fetchall()
            img = Image.open(io.BytesIO(image[0]["image"]), mode='r')
            img_byte_arr = io.BytesIO()
            img.save(img_byte_arr, format='PNG')
            my_encoded_img = base64.encodebytes(
                img_byte_arr.getvalue()).decode('ascii')
            return jsonify(my_encoded_img)
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 500
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 20
0
def getKeywords():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    kId = request.args.get('kId')
    try:
        if apiAuth.apiAuth(token, userid):
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            cur.execute("select * from keywords where keywordsid=%s", kId)
            response = cur.fetchall()
            response = jsonify(response)
            response.status_code = 200
            return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 500
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 21
0
def getServiceInfo():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    sid = request.args.get('sid')
    try:
        if apiAuth.apiAuth(token, userid) == True:
            if request.args.get('role') == "AP":
                conn = mysql.connect()
                cur = conn.cursor(pymysql.cursors.DictCursor)
                cur.execute("select * from services where idservices=%s;",
                            (sid))
                rows = cur.fetchall()
                cur.execute("select * from companydetails where idcompany=%s",
                            (rows[0]["companyId"]))
                rowsDat = cur.fetchall()
                response = {"company": rowsDat}
                cur.execute(
                    "select * from servicecontactinfo where idserviceContactInfo=%s",
                    (rows[0]["contactid"]))
                rowsDat = cur.fetchall()
                response["contactInfo"] = rowsDat
                cur.execute("select * from scheduletable where scheduleId=%s",
                            (rows[0]["scheduleid"]))
                rowsDat = cur.fetchall()
                response["schedule"] = rowsDat
                cur.execute(
                    "select * from paymentoptions where idpaymentoptions=%s",
                    (rows[0]["paymentid"]))
                rowsDat = cur.fetchall()
                response["payment"] = rowsDat
                cur.execute("select * from keywords where keywordsid=%s",
                            (rows[0]["keywordsid"]))
                rowsDat = cur.fetchall()
                response["keywords"] = rowsDat
                cur.execute(
                    "select firstName,lastName,phone from user where email=%s",
                    (rows[0]["serviceUserFK"]))
                rowsDat = cur.fetchall()
                response["user"] = rowsDat
                response["service"] = rows
                response = jsonify(response)
                response.status_code = 200
                return response
            else:
                response = jsonify("false")
                response.status_code = 200
                return response
        else:
            response = jsonify('Unauthorized Access')
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify('Server Error')
        response.status_code = 500
        return response
Exemplo n.º 22
0
def imageFunction():
    sid = request.args.get('sid')
    conn = mysql.connect()
    cur = conn.cursor(pymysql.cursors.DictCursor)
    _req = request.files['myFile'].read()
    print(_req)
    cur.execute("update services set image = %s where idservices = %s",
                (_req, sid))
    conn.commit()
    response = jsonify("success")
    response.status_code = 200
    return response
Exemplo n.º 23
0
def addServiceContact():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    _req = request.json
    try:
        if apiAuth(token, userid) == True:
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            contactid = validateContactId(conn, cur)
            serviceid = _req["serviceid"]
            if (contactid != 0):
                cur.execute(
                    "insert into servicecontactinfo(idserviceContactInfo, name, phone, cell, fax, tollfree, email, website, facebook, twitter, instagram, youtube, servicecontackfk) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                    (contactid, _req['conPerson'], _req['conPhone'],
                     _req['conMobile'], _req['conFax'], _req['conTollfree'],
                     _req['conEmail'], _req['conWebsite'], _req['conFacebook'],
                     _req['conTwitter'], _req['conInstagram'],
                     _req['conYoutube'], serviceid))
                conn.commit()
                cur.execute(
                    "update services set contactid = %s where idservices = %s",
                    (contactid, serviceid))
                conn.commit()
                data = {
                    "serviceId": serviceid,
                    "status": "Contact added successfully"
                }
                response = jsonify(data)
                response.status_code = 200
                return response
            else:
                data = {
                    "serviceId": serviceid,
                    "status": "Creation unsuccessful"
                }
                response = jsonify(data)
                response.status_code = 200
                return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 200
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 24
0
def user():
    try:
        conn = mysql.connect()
        cur = conn.cursor(pymysql.cursors.DictCursor)
        cur.execute("select * from user")
        rows = cur.fetchall()
        response = jsonify(rows)
        response.status_code = 200
        return response
    except Exception as e:
        return e
    finally:
        cur.close()
        conn.close()
Exemplo n.º 25
0
def getphone():
    userid = request.args.get('userid')
    try:
        conn = mysql.connect()
        cur = conn.cursor(pymysql.cursors.DictCursor)
        cur.execute("select phone from user where email = %s;", (userid))
        rows = cur.fetchall()
        conn.commit()
        response = jsonify(rows)
        return response
    except Exception as e:
        print(e)
        response = jsonify('Server Er7ror')
        response.status_code = 500
        return response
Exemplo n.º 26
0
def apiAuth(token, user):
    try:
        conn = mysql.connect()
        cur = conn.cursor(pymysql.cursors.DictCursor)
        cur.execute("select * from user where email = '" + user +
                    "' and token = '" + token + "';")
        rows = cur.fetchall()
        if len(rows) == 0:
            return False
        else:
            return True
    except Exception as e:
        return False
    finally:
        conn.close()
        cur.close()
Exemplo n.º 27
0
def generateKey(user):
    rand = ''.join([
        random.choice(string.ascii_letters + string.digits) for n in range(12)
    ])
    try:
        conn = mysql.connect()
        cur = conn.cursor(pymysql.cursors.DictCursor)
        cur.execute("update user set token = %s where email = '" + user + "';",
                    rand)
        conn.commit()
        return rand
    except Exception as e:
        print(e)
        return False
    finally:
        conn.close()
        cur.close()
Exemplo n.º 28
0
def serviceReviewDashboard():
    try:
        conn = mysql.connect()
        cur = conn.cursor(pymysql.cursors.DictCursor)
        serviceid = request.args.get('serviceid')
        cur.execute('select * from review where r_serviceid = %s', serviceid)
        conn.commit()
        response = jsonify(cur.fetchall())
        response.status_code = 200
        return response
    except Exception as e:
        response = jsonify('Error occured')
        response.status_code = 500
        return response
    finally:
        conn.close()
        cur.close()
Exemplo n.º 29
0
def addServiceKeywords():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    _req = request.json
    try:
        if apiAuth(token, userid) == True:
            conn = mysql.connect()
            cur = conn.cursor(pymysql.cursors.DictCursor)
            keywordsid = validateKeywordsId(conn, cur)
            serviceid = _req["serviceid"]
            if (keywordsid != 0):
                cur.execute(
                    "insert into keywords(keywordsid,keywordstext,servicekeywordsfk) values(%s,%s,%s)",
                    (keywordsid, _req['keywords'], serviceid))
                cur.execute(
                    "update services set keywordsid = %s where idservices = %s",
                    (keywordsid, serviceid))
                conn.commit()
                data = {
                    "serviceId": serviceid,
                    "status": "Keywords added successfully"
                }
                response = jsonify(data)
                response.status_code = 200
                return response
            else:
                data = {
                    "serviceId": serviceid,
                    "status": "Keywords unsuccessful"
                }
                response = jsonify(data)
                response.status_code = 200
                return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 200
        return response
    finally:
        cur.close()
        conn.close()
Exemplo n.º 30
0
def addCompany():
    userid = request.args.get('userid')
    token = request.args.get('tok')
    _req = request.json
    try:
        if apiAuth(token, userid) == True:
            if _req['company'] == "true":
                conn = mysql.connect()
                cur = conn.cursor(pymysql.cursors.DictCursor)
                companyid = validateCompanyId(conn, cur)
                if companyid != 0:
                    cur.execute(
                        "insert into companydetails(idcompany, name,city,phone,mobile,firstName,lastName,emailKey) values(%s, %s, %s, %s, %s, %s, %s, %s)",
                        (companyid, _req['cname'], _req['ccity'],
                         _req['cphone'], _req['cmobile'], _req['cfname'],
                         _req['clname'], userid))
                    conn.commit()
                    data = {
                        "companyId": companyid,
                        "status": "Company added successfully"
                    }
                    response = jsonify(data)
                    response.status_code = 200
                    return response
                else:
                    data = {
                        "companyId": companyid,
                        "status": "Creation unsuccessful"
                    }
                    response = jsonify(data)
                    response.status_code = 200
                    return response
            else:
                response = jsonify("No Company")
                response.status_code = 200
                return response
        else:
            response = jsonify("Not Authorized")
            response.status_code = 401
            return response
    except Exception as e:
        print(e)
        response = jsonify("Database Error")
        response.status_code = 200
        return response