def get(self): client = Database.connect() users = Database.get_collection(client, "Testing", "Users") filter = {"username": request.args.get("username")} fields = {"_id": False, "first_name": True, "last_name": True, "password": True} findUser = users.find_one(filter, fields) Database.disconnect(client) if findUser.get("password") == request.args.get("password"): del findUser["password"] response = flask.make_response(jsonify(user=findUser)) response.headers["content-type"] = "application/json" return response else: return jsonify(login={"Error": "Authentication Failure"})
def post(self): data = request.json try: json.loads(json.dumps(data)) except ValueError: response = flask.make_response(jsonify(status={"Error": "User data invalid!"})) response.headers["content-type"] = "application/json" return response else: goService = True errorLog = {"error": "Attributes required.!"} errorAtt = ["email", "password", "first_name", "last_name", "address", "mobile"] for att in errorAtt: if att not in data: errorLog.update({att: "Missing"}) goService = False if goService: client = Database.connect() driver = Database.get_collection(client, "OmegaDB", "DriverData") filter = {"email": data.get("email")} fields = {"_id": True} find_user = driver.find_one(filter, fields) if find_user is not None: if "_id" in find_user: Database.disconnect(client) response = flask.make_response(jsonify(status={"error": "User already exists"})) response.headers["content-type"] = "application/json" return response else: driver.insert_one(data) Database.disconnect(client) response = flask.make_response(jsonify(status={"message": "Data Inserted Successfully"})) response.headers["content-type"] = "application/json" return response else: response = flask.make_response(jsonify(status=errorLog)) response.headers["content-type"] = "application/json" return response def validate_driverlicense(self, license): url = "https://tph.tfl.gov.uk/TfL/SearchDriverLicence.page?org.apache.shale.dialog.DIALOG_NAME=TPHDriverLicence&Param=lg2.TPHDriverLicence&menuId=6" form_data = {"_id173:DriverLicenceNo": "2151"} params = urllib.urlencode(form_data) response = urllib.urlopen(url, params) data = response.read()