コード例 #1
0
def book_appointment(token: str, adata, appointment, rooms, user, mail):
    date = adata['date'] + ' Aug'
    token_data = decode_jwt(token)
    # userdata = user.find({"_id": ObjectId(token_data)})

    try:
        appointment.insert_one({
            "userid": ObjectId(token_data),
            "postid": adata['postid'],
            "date": date,
            "time": adata["time"],
            "email": adata['email']
        })
        email1 = adata['email']
        email2 = adata['owneremail']
        time = adata['time']
        msg = Message('Appointment Booked', recipients=[email1, email2])
        msg.html = (
            '<h2>Appointment details</h2>'
            '<p>Your appointment is booked on <b>' + date + ' 2020 on ' +
            time + ' PM.</b></p>'
            '<p><i><b>Note:</b>If you want to cancel or reschedule the appointment please visit our website.</i></P>'
        )
        mail.send(msg)
        return dumps({"msg": 'Appointment Booked'}), 200
    except Exception as e:
        return dumps({
            "msg": 'Some internal error occurred!',
            "error": str(e)
        }), 500
コード例 #2
0
def add_post(token: str, data, rooms) -> str:
    token_data = decode_jwt(token)
    images = []
    for item in data['images']:
        images.append(item['dataURL'])
    try:
        rooms.insert({
            "userID": ObjectId(token_data),
            "images": images,
            "title": data['headline'],
            "ratings": 4,
            "reviews": [],
            "description": data['detail'],
            "rent": data['rent'],
            "isPromoted": data['promoted'],
            "isPetAllowed": data['petFriendly'],
            "isFurnished": data['furnishing'],
            "Amenities": data['amenities'],
            "Location": data['location'],
            "Availability": data['date'],
            "Bedrooms": data['bedrooms'],
            "Bathrooms": data['bathrooms'],
            "disabled": data['disabled']
        })
        return dumps({"msg": "Post added successfully!"}), 200
    except Exception as e:
        return dumps({
            "msg": 'Some internal error occurred while adding post!',
            "error": str(e)
        }), 500
コード例 #3
0
    def token_auth(*args, **kwargs):
        try:
            app.logger.info('Authenticating User')
            token = request.headers['Authorization']

            if not token:
                app.logger.info('Checking Token Availability')
                return dumps({"msg": "Please Login First!"}), 401

            token_data = decode_jwt(token)
            if token_data == "Signature expired. Please log in again." or token_data == 'Invalid token. Please log in again.':
                app.logger.info('Validating Token')
                return dumps({"msg": "Please Login First!"}), 401

            if database.deniedTokens.count_documents({"token": token}) != 0:
                app.logger.info('Invalid Token Found')
                return dumps({"msg": "Please Login First!"}), 401

            return auth(*args, **kwargs)
        except Exception as e:

            app.logger.info('Exception Occurred in Token Validation')
            return dumps({
                "msg": 'Some internal error occurred!',
                "error": str(e)
            }), 500
コード例 #4
0
def logout_user(token: str, user, deniedToken) -> str:
    token_data = decode_jwt(token)
    try:
        user.update_one({"_id": ObjectId(token_data)}, {'$set': {"token": ""}})
        deniedToken.insert_one(
            {"token": token, "denied_time": str(datetime.now())}).inserted_id
    except Exception as e:
        return dumps({"msg": 'Some internal error occurred!', "error": str(e)}), 500
    return dumps({"msg": "Logout Success!"}), 200
コード例 #5
0
def get_appointments(token: str, appointment, mail):
    token_data = decode_jwt(token)
    appointments_list = []

    appointment_data = appointment.find({"userid": ObjectId(token_data)})
    for i in appointment_data:
        data = {
            'id': dumps(i['_id'], default=str),
            'postid': i['postid'],
            'date': i['date'],
            'time': i['time'],
            'email': i['email']
        }
        appointments_list.append(data)
        data = {}
    print(appointments_list)
    response = Response(json.dumps(appointments_list),
                        status=200,
                        mimetype="application/json")

    return response
コード例 #6
0
    def token_auth(*args, **kwargs):
        try:
            # print(request.json)
            token = request.json['headers']['Authorization']

            if not token:
                return jsonify({"msg": "Please Login First!"}), 403

            token_data = decode_jwt(token)
            if token_data == "Signature expired. Please log in again." or token_data == 'Invalid token. Please log in again.':
                return jsonify({"msg": "Please Login First!"}), 403

            if database.deniedTokens.count_documents({"token": token}) != 0:
                return jsonify({"msg": "Please Login First!"}), 403

            return auth(*args, **kwargs)
        except Exception as e:
            return jsonify({
                "msg": 'Some internal error occurred!',
                "error": str(e)
            })
コード例 #7
0
def get_rooms(token: str, rooms) -> str:
    print("fetching")
    token_data = decode_jwt(token)
    rooms_list = []
    try:
        data = rooms.find({"userID": ObjectId(token_data)})
        for room in data:
            roomID = dumps(room['_id'], default=str)
            userID = dumps(room['userID'], default=str)
            description = room['description']
            amenities = dumps(room['Amenities'], default=str)
            disabled = room['disabled']
            title = room['title']
            image = room['images'][0]
            rating = dumps(str(room['ratings']))
            isPromoted = room['isPromoted']
            rent = room['rent']
            dict_room = {
                'roomID': roomID,
                'userID': userID,
                'image': image,
                'title': title,
                'rating': loads(rating),
                'isPromoted': isPromoted,
                'rent': rent,
                'disabled': disabled,
                'amenities': loads(amenities),
                'description': description
            }
            rooms_list.append(dict_room)
        return dumps(rooms_list), 200
    except Exception as e:
        return dumps({
            "msg":
            'Some internal error occurred while getting rooms for user!',
            "error": str(e)
        }), 500