def eventInformation(): try: dic = Dbconnection.DBConnection() apartmentId="ADADA" username = "******" today = datetime.now() myquery = {'apartmentId': apartmentId,"eventId": request.get_json()['eventId'].strip()} mydoc = dic['eventId'].find(myquery) print(mydoc.count()) if mydoc.count() != 0: myUserJson={ "$set":{ "apartmentId": apartmentId, "eventId": request.get_json()['eventId'].strip(), "eventName": request.get_json()['eventName'].strip(), "budget": request.get_json()['budget'].strip(), "eventDate": request.get_json()['eventDate'].strip() } } dic['eventId'].update_one(myquery,myUserJson) task = {'status': 'Successfull updated'} res2 = json.dumps(task) res1=json.loads(res2) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response else: myquery1 = {'apartmentId': apartmentId,"eventId": request.get_json()['eventId'].strip(),"latestEvent": 1} mydoc1 = dic['eventId'].find(myquery) myUserJson11={ "$set":{ "latestEvent": 0 } } if mydoc1.count() != 0: dic['eventId'].update_one(myquery1,myUserJson1) myUserJson= [{ "apartmentId": apartmentId, "eventId": request.get_json()['eventId'].strip(), "eventName": request.get_json()['eventName'].strip(), "latestEvent": 1, "ownerName": username, "createOrUpdate": str(today.strftime('%Y-%m-%d %H:%M:%S')) }] x = dic['eventId'].insert_many(myUserJson) task = {'status': 'Success',"message":"Sucessfully Update"} res = json.dumps(task) res1=json.loads(res) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in post data %s' % e} res2 = json.dumps(task) res1=json.loads(res2) response=make_response(res1,404) response.headers.add('Access-Control-Allow-Origin', '*') return response
def read(): """ This function responds to a request for /api/Inventory with the complete lists of Inventory :return: sorted list of Inventory """ # Create the list of Inventory from our data # return jsonify(INVENTORY) user = session.get('username') #apartmentId = session.get('apartmentId') apartmentId="ADADA" myquery = {'apartmentId': apartmentId} print(session) print(str(user)) if user == '': task = {'status': 'Redirect to login page'} return jsonify(task) try: dic = Dbconnection.DBConnection() task = dumps(dic['guest'].find(myquery)) res = json.dumps(task) res1=json.loads(res) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in GET data %s' % e} #abort(404) res = json.dumps(task) res1=json.loads(res) response=make_response(res1,401) response.headers.add('Access-Control-Allow-Origin', '*') return jsonify(task)
def login(): try: if not validators.length(request.get_json()['username'].strip(), min=2) or not validators.length( request.get_json()['password'].strip(), min=2): task = {'status': 'username and password should not be null'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 400) response.headers.add('Access-Control-Allow-Origin', '*') return response dic = Dbconnection.DBConnection() today = datetime.now() key = Fernet.generate_key() #apartmentId = session.get('apartmentId') myquery = {'username': request.get_json()['username'].strip()} mydoc = dic['user'].find(myquery) print(mydoc.count()) if mydoc.count() == 0: task = {'status': 'Invalid username and password'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 400) response.headers.add('Access-Control-Allow-Origin', '*') return response task = dumps(mydoc) res = json.dumps(task) res1 = json.loads(res).strip('[]') res2 = eval(res1) password = res2.get('password') f = Fernet(res2.get('key')) if f.decrypt(password) == request.get_json()['password'].strip(): session['username'] = res2.get('username') session['apartmentId'] = res2.get('apartmentId') task = {'status': 'Success'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 200) response.headers.add('Access-Control-Allow-Origin', '*') return response else: task = {'status': 'Invalid username and password'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 400) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in post data %s' % e} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 404) response.headers.add('Access-Control-Allow-Origin', '*') return response
def pushElectionInformation(): try: dic = Dbconnection.DBConnection() today = datetime.now() #apartmentId = session.get('apartmentId') apartmentId = "ADADA" print(apartmentId) myquery1 = { 'apartmentId': apartmentId, 'notificationId': request.get_json()['notificationId'].strip(), "latestValue": 1 } mydoc1 = dic['notificationInformation'].find(myquery1) if mydoc1.count() != 0: myUserJson = { "$push": { "approval": { "flatNo": request.get_json()['flatNo'], "status": request.get_json()['status'], "candidateId": request.get_json()['candidateId'] } } } dic['electionInformation'].update_one(myquery1, myUserJson) task = {'status': 'Successfull updated'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 200) response.headers.add('Access-Control-Allow-Origin', '*') return response else: task = { 'status': 'Failed', "message": "Notification Information not latest" } res = json.dumps(task) res1 = json.loads(res) response = make_response(res1, 404) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in post data %s' % e} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 404) response.headers.add('Access-Control-Allow-Origin', '*') return response
def vehicalInforamtion(): try: dic = Dbconnection.DBConnection() today = datetime.now() #apartmentId = session.get('apartmentId') apartmentId="ADADA" print(apartmentId) myquery1 = { 'apartmentId': apartmentId,'notificationId': request.get_json()['notificationId'].strip()} mydoc1 = dic['vehicalInforamtion'].find(myquery1) if mydoc1.count() != 0: myUserJson={ "$set":{ "vehicalType": request.get_json()['vehicalType'], "vehicalNumber": request.get_json()['vehicalNumber'], "parkingNo": request.get_json()['parkingNo'] } } dic['vehicalInforamtion'].update_one(myquery1,myUserJson) task = {'status': 'Successfull updated'} res2 = json.dumps(task) res1=json.loads(res2) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response else: myUserJson= [{ "apartmentId": apartmentId, "ownerFlatNo":request.get_json()['ownerFlatNo'].strip(), "vehicalType": request.get_json()['vehicalType'], "vehicalNumber": request.get_json()['vehicalNumber'], "parkingNo": request.get_json()['parkingNo'], "createDate": str(today.strftime('%Y-%m-%d %H:%M:%S')) }] x = dic['vehicalInforamtion'].insert_many(myUserJson) task = {'status': 'Success',"message":"Sucessfully Update"} res = json.dumps(task) res1=json.loads(res) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in post data %s' % e} res2 = json.dumps(task) res1=json.loads(res2) response=make_response(res1,404) response.headers.add('Access-Control-Allow-Origin', '*') return response
def run(self): time.sleep(3) while self.stop_var: crimedatalist = [] latlong = db.get_latest_user_location(self.table_name) if len(latlong) > 0: latlonglist = [float(latlong[0][0]), float(latlong[0][1])] record_time = latlong[0][2] current_time = datetime.now() crimedata = db.get_all_records(CRIME_DATA) for data in crimedata: crimedatalist.append(tuple([float(data[1]), float(data[2])])) latlongtuple = tuple(latlonglist) timediff = (current_time - record_time).total_seconds() if timediff > 30 and self.is_not_safe(latlongtuple, crimedatalist, self.threshold): if self.self_thread: continue else: contacts = db.get_emergency_contacts(self.threadID) self.send_message(latlonglist, contacts, "time") self.self_thread = True elif self.is_not_safe(latlongtuple, crimedatalist, self.threshold): if self.self_thread: contacts = db.get_emergency_contacts(self.threadID) self.send_message(latlonglist, contacts, "time") self.self_thread = False else: db.set_alert_flag(self.threadID) else: if self.self_thread: contacts = db.get_emergency_contacts(self.threadID) self.send_message(latlonglist, contacts, "return") self.self_thread = False else: time.sleep(3) db.deset_alert_flag(self.threadID) continue time.sleep(3)
def main_thread(): global previous_records, polling_threads db.initiate() while True: records_count = db.get_records_count(USERS_DATA) if records_count > previous_records: records = db.get_topic_n_records(USERS_DATA, records_count - previous_records) for record in records: db.create_users_navigation_table(str.lower(str(record[5])) + str(record[0])) polling_navigation_table(str(record[0]), str(record[1]), str(str.lower(record[5])) + str(record[0]), record[9]) previous_records = records_count users_data = db.get_all_records(USERS_DATA); for user in users_data: key = str.lower(str(user[5])) + str(user[0]) if user[7] == "FALSE": if key in polling_threads: polling_threads[key].stop() polling_threads.pop(key, None) else: if key not in polling_threads: thread_temp = pollingThread(str(user[0]), str.lower(str(user[5])), key, user[9], True) thread_temp.start() polling_threads[key] = thread_temp
def guestInformation(): try: dic = Dbconnection.DBConnection() today = datetime.now() key = Fernet.generate_key() f = Fernet(key) #apartmentId = session.get('apartmentId') apartmentId="ADADA" print(apartmentId) myquery1 = { 'apartmentId': apartmentId,'username': request.get_json()['username'].strip()} mydoc1 = dic['user'].find(myquery1) if mydoc1.count() != 0: myUserJson={ "$set":{ "apartmentId": apartmentId, "fullName": request.get_json()['fullName'].strip(), "vehicalId": request.get_json()['vehicalId'], "permanentIdName": request.get_json()['permanentIdName'].strip(), "permanentId": request.get_json()['permanentId'].strip(), "mobile": request.get_json()['mobile'].strip(), "purpose": request.get_json()['purpose'].strip(), "ownerFlatNo": request.get_json()['ownerFlatNo'].strip(), "employeeId": request.get_json()['employeeId'].strip(), "status": request.get_json()['status'].strip(), "startDate": request.get_json()['startDate'].strip(), "endDate": request.get_json()['endDate'].strip(), "createDate": str(today.strftime('%Y-%m-%d %H:%M:%S')) } } dic['guest'].update_one(myquery1,myUserJson) task = {'status': 'Successfull updated'} res2 = json.dumps(task) res1=json.loads(res2) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response else: myUserJson= [{ "apartmentId": apartmentId, "fullName": request.get_json()['fullName'].strip(), "vehicalId": request.get_json()['vehicalId'], "permanentIdName": request.get_json()['permanentIdName'].strip(), "permanentId": request.get_json()['permanentId'].strip(), "mobile": request.get_json()['mobile'].strip(), "employeeId": request.get_json()['employeeId'].strip(), "purpose": request.get_json()['purpose'].strip(), "ownerFlatNo": request.get_json()['ownerFlatNo'].strip(), "status": request.get_json()['status'].strip(), "startDate": request.get_json()['startDate'].strip(), "endDate": request.get_json()['endDate'].strip(), "createDate": str(today.strftime('%Y-%m-%d %H:%M:%S')) }] x = dic['guest'].insert_many(myUserJson) task = {'status': 'Success',"message":"Sucessfully Update"} res = json.dumps(task) res1=json.loads(res) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in post data %s' % e} res2 = json.dumps(task) res1=json.loads(res2) response=make_response(res1,404) response.headers.add('Access-Control-Allow-Origin', '*') return response
def equipmentInfomation(): dic = Dbconnection.DBConnection() apartmentId = "ADADA" username = "******" today = datetime.now() myquery = { 'apartmentId': apartmentId, "equipmentId": request.get_json()['equipmentId'].strip() } mydoc = dic['equipment'].find(myquery) myquery1 = { 'apartmentId': apartmentId, 'ownerName': username, "latestValue": 1 } mydoc1 = dic['bankBalanceInformation'].find(myquery1) if mydoc1.count() == 0: task = {'status': 'Failed', "message": "Insufficent balance"} res = json.dumps(task) res1 = json.loads(res) response = make_response(res1, 402) response.headers.add('Access-Control-Allow-Origin', '*') return response task = dumps(mydoc1) res = json.dumps(task) res1 = json.loads(res).strip('[]') res2 = eval(res1) currentAmount = res2.get('currentAmount') print(currentAmount) if int(currentAmount) < int(request.get_json()['equipmentPrice'].strip()): task = {'status': 'Failed', "message": "Insufficent balance"} res = json.dumps(task) res1 = json.loads(res) response = make_response(res1, 402) response.headers.add('Access-Control-Allow-Origin', '*') return response print(currentAmount) if mydoc.count() != 0: task1 = dumps(mydoc) res = json.dumps(task1) res1 = json.loads(res).strip('[]') res2 = eval(res1) equipmentPrice = res2.get('equipmentPrice') updateAmount = int(currentAmount) + int(equipmentPrice) myUserJson1 = { "$set": { "apartmentId": apartmentId, "currentAmount": str( int(updateAmount) - int(request.get_json()['equipmentPrice'].strip())) } } dic['bankBalanceInformation'].update_one(myquery1, myUserJson1) myUserJson = { "$set": { "apartmentId": apartmentId, "equipmentId": request.get_json()['equipmentId'].strip(), "equipmentName": request.get_json()['equipmentName'].strip(), "equipmentPrice": request.get_json()['equipmentPrice'].strip(), "equipmentType": request.get_json()['equipmentType'].strip(), "ownerid": username, "createOrUpdate": str(today.strftime('%Y-%m-%d %H:%M:%S')) } } dic['equipment'].update_one(myquery, myUserJson) task = {'status': 'Successfull updated'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 200) response.headers.add('Access-Control-Allow-Origin', '*') return response else: myUserJson1 = { "$set": { "apartmentId": apartmentId, "currentAmount": str( int(currentAmount) - int(request.get_json()['equipmentPrice'].strip())) } } dic['bankBalanceInformation'].update_one(myquery1, myUserJson1) myUserJson = [{ "apartmentId": apartmentId, "equipmentId": request.get_json()['equipmentId'].strip(), "equipmentName": request.get_json()['equipmentName'].strip(), "equipmentPrice": request.get_json()['equipmentPrice'].strip(), "equipmentType": request.get_json()['equipmentType'].strip(), "ownerid": username, "createOrUpdate": str(today.strftime('%Y-%m-%d %H:%M:%S')) }] x = dic['equipment'].insert_many(myUserJson) task = {'status': 'Success', "message": "Sucessfully Update"} res = json.dumps(task) res1 = json.loads(res) response = make_response(res1, 200) response.headers.add('Access-Control-Allow-Origin', '*') return response
def notificationInformation(): try: dic = Dbconnection.DBConnection() today = datetime.now() #apartmentId = session.get('apartmentId') apartmentId="ADADA" text='' statementName=apartmentId + str('-notificationStatements-')+str(today.strftime('%Y-%m-%d-%H-%M-%S'))+".jpg" print(apartmentId) if request.form['description'] == "": if not os.path.exists("/tmp/inventory/"): os.makedirs("/tmp/inventory/") if not os.path.exists("/tmp/inventory/{}".format(apartmentId)): os.makedirs("/tmp/inventory/{}".format(apartmentId)) if not os.path.exists("/tmp/inventory/{}/{}".format(apartmentId,"notification")): os.makedirs("/tmp/inventory/{}/{}".format(apartmentId,"notification")) if 'file' not in request.files: return "No file found" else: file = request.files['file'] file.save("/tmp/inventory/{}/notification/{}".format(apartmentId,statementName)) path="/tmp/inventory/{}/notification/{}".format(apartmentId,statementName) img=cv2.imread(path) text=pytesseract.image_to_string(img) print(text) else: text=request.form['description'] myquery1 = { 'apartmentId': apartmentId,'notificationId': request.form['notificationId'].strip()} mydoc1 = dic['notificationInformation'].find(myquery1) if mydoc1.count() != 0: myUserJson={ "$set":{ "notificationId": request.form['notificationId'].strip(), "description": text.strip() } } dic['notificationInformation'].update_one(myquery1,myUserJson) task = {'status': 'Successfull updated'} res2 = json.dumps(task) res1=json.loads(res2) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response else: myquery2 = {'apartmentId': apartmentId,"latestValue": 1} mydoc2 = dic['notificationInformation'].find(myquery2) if mydoc1.count != 0: myUserJson2= {"$set":{ "latestValue": 0, } } dic['notificationInformation'].update_one(myquery2,myUserJson2) myUserJson= [{ "apartmentId": apartmentId, "notificationId":request.form['notificationId'].strip(), "description": text.strip(), "latestValue":1, "createDate": str(today.strftime('%Y-%m-%d %H:%M:%S')) }] x = dic['notificationInformation'].insert_many(myUserJson) task = {'status': 'Success',"message":"Sucessfully Update"} res = json.dumps(task) res1=json.loads(res) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in post data %s' % e} res2 = json.dumps(task) res1=json.loads(res2) response=make_response(res1,404) response.headers.add('Access-Control-Allow-Origin', '*') return response
def paymentInformationInital(): try: dic = Dbconnection.DBConnection() apartmentId = "ADADA" username = "******" today = datetime.now() myquery = { 'apartmentId': apartmentId, "accountNumber": request.get_json()['accountNumber'].strip() } mydoc = dic['paymentInformation'].find(myquery) print(mydoc.count()) if mydoc.count() != 0: myUserJson = { "$set": { "apartmentId": apartmentId, "accountNumber": request.get_json()['accountNumber'].strip(), "ifscCode": request.get_json()['ifscCode'].strip(), "bankName": request.get_json()['bankName'].strip(), "bankAddress": request.get_json()['bankAddress'].strip(), "branchName": request.get_json()['branchName'].strip(), "pincode": request.get_json()['pincode'].strip(), "city": request.get_json()['city'].strip(), "state1": request.get_json()['state1'].strip(), "country": request.get_json()['country'].strip(), "ownerName": username, "createOrUpdate": str(today.strftime('%Y-%m-%d %H:%M:%S')) } } dic['paymentInformation'].update_one(myquery, myUserJson) task = {'status': 'Successfull updated'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 200) response.headers.add('Access-Control-Allow-Origin', '*') return response else: myUserJson = [{ "apartmentId": apartmentId, "accountNumber": request.get_json()['accountNumber'].strip(), "ifscCode": request.get_json()['ifscCode'].strip(), "bankName": request.get_json()['bankName'].strip(), "bankAddress": request.get_json()['bankAddress'].strip(), "branchName": request.get_json()['branchName'].strip(), "pincode": request.get_json()['pincode'].strip(), "city": request.get_json()['city'].strip(), "state1": request.get_json()['state1'].strip(), "country": request.get_json()['country'].strip(), "ownerName": username, "createOrUpdate": str(today.strftime('%Y-%m-%d %H:%M:%S')) }] x = dic['paymentInformation'].insert_many(myUserJson) task = {'status': 'Success', "message": "Sucessfully Update"} res = json.dumps(task) res1 = json.loads(res) response = make_response(res1, 200) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in post data %s' % e} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 404) response.headers.add('Access-Control-Allow-Origin', '*') return response
def upload_file(): print(request.files) print(request.form['depositAmount']) dic = Dbconnection.DBConnection() apartmentId = "ADADA" user = "******" today = datetime.now() statementName = apartmentId + str('-bankStatements-') + str( today.strftime('%Y-%m-%d-%H-%M-%S')) + ".jpg" myquery = {'apartmentId': apartmentId, 'username': user} mydoc = dic['bankBalanceInformation'].find(myquery) myquery1 = { 'apartmentId': apartmentId, 'ownerName': user, "latestValue": 1 } mydoc1 = dic['bankBalanceInformation'].find(myquery1) task = dumps(mydoc1) res = json.dumps(task) print(res) res1 = json.loads(res).strip('[]') res2 = eval(res1) currentAmount = res2.get('currentAmount') totalAmount = res2.get('totalAmount') print(currentAmount) if mydoc1.count != 0: myUserJson = { "$set": { "latestValue": 0, } } dic['bankBalanceInformation'].update_one(myquery1, myUserJson) user = "******" if user == '': task = {'status': 'Redirect to login page'} return jsonify(task) if not os.path.exists("/tmp/inventory/"): os.makedirs("/tmp/inventory/") if not os.path.exists("/tmp/inventory/{}".format(apartmentId)): os.makedirs("/tmp/inventory/{}".format(apartmentId)) if not os.path.exists("/tmp/inventory/{}/{}".format( apartmentId, "bankStatements")): os.makedirs("/tmp/inventory/{}/{}".format(apartmentId, "bankStatements")) if 'file' not in request.files: return "No file found" else: file = request.files['file'] file.save("/tmp/inventory/{}/bankStatements/{}".format( apartmentId, statementName)) if mydoc.count != 0: myUserJson = [{ "depositAmount": request.form['depositAmount'].strip(), "currentAmount": str( int(currentAmount) + int(request.form['depositAmount'].strip())), "totalAmount": str(int(totalAmount) + int(request.form['depositAmount'].strip())), "statementName": statementName, "amountType": request.form['amountType'].strip(), "ownerName": user, "depositOwnerFlatNo": request.form['depositOwnerFlatNo'].strip(), "apartmentId": apartmentId, "latestValue": 1, "statementDate": str(today.strftime('%Y-%m-%d %H:%M:%S')) }] x = dic['bankBalanceInformation'].insert_many(myUserJson) task = {'status': 'Success', "message": "Sucessfully Update"} res = json.dumps(task) res1 = json.loads(res) response = make_response(res1, 200) response.headers.add('Access-Control-Allow-Origin', '*') return response task = {'status': 'Sucessfully updated record'} return jsonify(task)
def employeePaymentInformation(): try: dic = Dbconnection.DBConnection() today = datetime.now() key = Fernet.generate_key() f = Fernet(key) #apartmentId = session.get('apartmentId') apartmentId="ADADA" print(apartmentId) myquery1 = { 'apartmentId': apartmentId,'username': request.get_json()['username'].strip()} mydoc1 = dic['user'].find(myquery1) if mydoc1.count() != 0: myUserJson={ "$set":{ "apartmentId": apartmentId, "fullName": request.get_json()['fullName'].strip(), "username": request.get_json()['username'].strip(), "password": f.encrypt(bytes(request.get_json()['password'].strip())), "employeeId": request.get_json()['employeeId'], "employeeAddress": request.get_json()['employeeAddress'], "pincode": request.get_json()['pincode'], "state": request.get_json()['state'], "nationality": request.get_json()['nationality'], "employeeIdProof": request.get_json()['employeeIdProof'], "emailId": request.get_json()['emailId'].strip(), "mobile": request.get_json()['mobile'].strip(), "altmobile": request.get_json()['altmobile'].strip(), "occupation": request.get_json()['occupation'].strip(), "type": request.get_json()['type'].strip(), "status": request.get_json()['status'].strip(), "startDate": request.get_json()['startDate'].strip(), "endDate": request.get_json()['endDate'].strip(), "key": key, "createDate": str(today.strftime('%Y-%m-%d %H:%M:%S')) } } dic['equipment'].update_one(myquery1,myUserJson) task = {'status': 'Successfull updated'} res2 = json.dumps(task) res1=json.loads(res2) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response else: myUserJson= [{ "apartmentId": apartmentId, "fullName": request.get_json()['fullName'].strip(), "username": request.get_json()['username'].strip(), "password": f.encrypt(bytes(request.get_json()['password'].strip())), "employeeId": request.get_json()['employeeId'], "employeeAddress": request.get_json()['employeeAddress'], "pincode": request.get_json()['pincode'], "state": request.get_json()['state'], "nationality": request.get_json()['nationality'], "employeeIdProof": request.get_json()['employeeIdProof'], "emailId": request.get_json()['emailId'].strip(), "mobile": request.get_json()['mobile'].strip(), "occupation": request.get_json()['occupation'].strip(), "type": request.get_json()['type'].strip(), "status": request.get_json()['status'].strip(), "startDate": request.get_json()['startDate'].strip(), "endDate": request.get_json()['endDate'].strip(), "key": key, "createDate": str(today.strftime('%Y-%m-%d %H:%M:%S')) }] x = dic['employee'].insert_many(myUserJson) task = {'status': 'Success',"message":"Sucessfully Update"} res = json.dumps(task) res1=json.loads(res) response=make_response(res1,200) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in post data %s' % e} res2 = json.dumps(task) res1=json.loads(res2) response=make_response(res1,404) response.headers.add('Access-Control-Allow-Origin', '*') return response
def adminRegister(): try: if not validators.length( request.get_json()['username'].strip(), min=2) or not validators.length( request.get_json()['password'].strip(), min=2) or not validators.length( request.get_json()['fullName'].strip(), min=2) or not validators.length( request.get_json()['flatNo'].strip(), min=2) or not validators.email(request.get_json( )['emailId'].strip()) or not validators.length( request.get_json()['mobile'].strip(), min=2): task = {'status': 'All Fields are manditory'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 400) response.headers.add('Access-Control-Allow-Origin', '*') return response if not validators.length( request.get_json()['apartmentId'].strip(), min=2) or not validators.length( request.get_json()['apartmentName'].strip(), min=2) or not validators.length( request.get_json()['address'].strip(), min=2) or not validators.length( request.get_json()['city'].strip(), min=2) or not validators.length( request.get_json()['state'].strip(), min=2): task = {'status': 'All Fields are manditory'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 400) response.headers.add('Access-Control-Allow-Origin', '*') return response today = datetime.now() dic = Dbconnection.DBConnection() key = Fernet.generate_key() f = Fernet(key) myquery = {'apartmentId': request.get_json()['apartmentId'].strip()} mydoc = dic['admin'].find(myquery) print(mydoc.count()) if mydoc.count() != 0: task = {'status': 'Already apartmentId exist'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 404) response.headers.add('Access-Control-Allow-Origin', '*') return response else: myAdminJson = [{ "apartmentId": request.get_json()['apartmentId'].strip(), "apartmentName": request.get_json()['apartmentName'].strip(), "address": request.get_json()['address'].strip(), "city": request.get_json()['city'].strip(), "state": request.get_json()['state'].strip(), "createDate": str(today.strftime('%Y-%m-%d %H:%M:%S')) }] x = dic['admin'].insert_many(myAdminJson) time.sleep(5) myUserJson = [{ "apartmentId": request.get_json()['apartmentId'].strip(), "fullName": request.get_json()['fullName'].strip(), "username": request.get_json()['username'].strip(), "password": f.encrypt(bytes(request.get_json()['password'].strip())), "flatNo": request.get_json()['flatNo'], "emailId": request.get_json()['emailId'].strip(), "mobile": request.get_json()['mobile'].strip(), "type": "President", "key": key, "createDate": str(today.strftime('%Y-%m-%d %H:%M:%S')) }] x = dic['user'].insert_many(myUserJson) task = {'status': 'Success', "message": "Success"} res = json.dumps(task) res1 = json.loads(res) response = make_response(res1, 200) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in post data %s' % e} abort(404) return jsonify(task)
def updateUserRegister(): try: if not validators.length( request.get_json()['username'].strip(), min=2) or not validators.length( request.get_json()['password'].strip(), min=2) or not validators.length( request.get_json()['fullName'].strip(), min=2) or not validators.length( request.get_json()['flatNo'].strip(), min=2) or not validators.email(request.get_json( )['emailId'].strip()) or not validators.length( request.get_json()['mobile'].strip(), min=2): task = {'status': 'All Fields are manditory'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 400) response.headers.add('Access-Control-Allow-Origin', '*') return response dic = Dbconnection.DBConnection() today = datetime.now() key = Fernet.generate_key() f = Fernet(key) apartmentId = "ADADA" myquery = { 'apartmentId': apartmentId, 'username': request.get_json()['username'].strip() } print(myquery) #apartmentId = session.get('apartmentId') apartmentId = "ADADA" if apartmentId == "": print(apartmentId) task = {'status': 'redirect to login'} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 404) response.headers.add('Access-Control-Allow-Origin', '*') return response else: myUserJson = { '$set': { "apartmentId": apartmentId, "fullName": request.get_json()['fullName'].strip(), "username": request.get_json()['username'].strip(), "password": f.encrypt(bytes(request.get_json()['password'].strip())), "flatNo": request.get_json()['flatNo'], "emailId": request.get_json()['emailId'].strip(), "mobile": request.get_json()['mobile'].strip(), "type": request.get_json()['type'].strip(), "key": key, "createDate": str(today.strftime('%Y-%m-%d %H:%M:%S')) } } dic['user'].update_one(myquery, myUserJson) task = {'status': 'Success', "message": "Sucessfully Update"} res = json.dumps(task) res1 = json.loads(res) response = make_response(res1, 200) response.headers.add('Access-Control-Allow-Origin', '*') return response except BulkWriteError as e: task = {'status': 'Someting went wrong in post data %s' % e} res2 = json.dumps(task) res1 = json.loads(res2) response = make_response(res1, 404) response.headers.add('Access-Control-Allow-Origin', '*') return response