def reset_pwd(token): try: serializer = URLSafeTimedSerializer(app.config['SECRET_KEY']) email = serializer.loads(token, salt=app.config['SECRET_KEY']) except: flash('Reset link is invalid or expired') return redirect(url_for('login')) form = PasswordForm() if form.validate_on_submit(): form.password.data = form.password.data.strip() user = DB.find_one(collection="User", query={"email": email}) if user is None: flash('Invalid account!') return redirect(url_for('login')) else: new_password = generate_password_hash(form.password.data) DB.update_one(collection="User", filter={"email": email}, data={"$set": { "password": new_password }}) return redirect(url_for('login')) return render_template('reset-password-token.html', form=form, token=token, email=email)
def delete_poll(poll): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) toDelete = DB.find_one(collection='Poll', query={'_id': ObjectId(poll)}) if toDelete is None: flash('Please contact admin, DB error!') return redirect(url_for('polls')) for voter in toDelete['voters']: toRemove = DB.find_one(collection="Profile", query={"_id": voter}) if toRemove is None: flash('Please contact admin, DB error!') return redirect(url_for('polls')) DB.update_one(collection="Profile", filter={'_id': voter}, data={"$pull": { "polls": ObjectId(poll) }}) DB.update_one(collection="Profile", filter={'_id': user['_id']}, data={"$pull": { "polls": ObjectId(poll) }}) DB.remove(collection="Poll", condition={"_id": ObjectId(poll)}) flash('Deleted Poll!') return redirect(url_for('polls'))
def invite_voter(poll, email): friend = DB.find_one(collection="Profile", query={"email": email}) if friend is None: flash(f'Friend {email} not found!') return redirect(url_for('add_voter', poll=poll)) sent = DB.find_one(collection="Poll", query={ '$and': [{ '_id': ObjectId(poll) }, { 'voters': ObjectId(friend['_id']) }] }) if sent is not None: flash(f'Already added {email} as voter!') return redirect(url_for('add_voter', poll=poll)) DB.update_one(collection="Poll", filter={'_id': ObjectId(poll)}, data={'$push': { 'voters': ObjectId(friend['_id']) }}) DB.update_one(collection="Profile", filter={'_id': ObjectId(friend['_id'])}, data={'$push': { 'polls': ObjectId(poll) }}) flash(f'Successfully added {email} as voter!') return redirect(url_for('add_voter', poll=poll))
def delete_request(profile_id): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) # only can add user with a profile friend = DB.find_one(collection="Profile", query={"_id": ObjectId(profile_id)}) if friend is None: flash('User not found!') return redirect(url_for('friends')) for f in user['friends']: if friend['_id'] == f['friend_id'] and f['status'] == 'pending': DB.update_one(collection="Profile", filter={"_id": user['_id']}, data={'$pull': { "friends": f }}) flash('Friend request ' + friend['email'] + ' cancelled!') return redirect(url_for('friends')) for f in friend['friends']: if user['_id'] == f['friend_id'] and f['status'] == 'pending': DB.update_one(collection="Profile", filter={"_id": friend['_id']}, data={'$pull': { "friends": f }}) flash('Friend request ' + friend['email'] + ' rejected!') return redirect(url_for('friends')) flash('Please contact admin, DB issues!') return redirect(url_for('friends'))
def insert(self): if not DB.find_one("Profile", {"polls._id": self.creator}): poll = DB.insert(collection='Poll', data=self.json()) DB.update_one(collection='Profile', filter={'_id': self.creator}, data={'$push': { 'polls': poll.inserted_id }}) return poll.inserted_id
def delete_friend(profile_id): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) added = DB.find_one(collection="Profile", query={ "$and": [{ "_id": user['_id'] }, { "friends": { "$elemMatch": { "friend_id": ObjectId(profile_id), "status": "accepted" } } }] }) added2 = DB.find_one(collection="Profile", query={ "$and": [{ "_id": ObjectId(profile_id) }, { "friends": { "$elemMatch": { "friend_id": user['_id'], "status": "accepted" } } }] }) if added is not None and added2 is not None: myFriendList = get_list(toFilterList=added['friends'], key="friend_id", query=ObjectId(profile_id)) DB.update_one(collection="Profile", filter={"_id": user['_id']}, data={'$pull': { "friends": myFriendList[0] }}) theirFriendList = get_list(toFilterList=added2['friends'], key="friend_id", query=user['_id']) DB.update_one(collection="Profile", filter={"_id": ObjectId(profile_id)}, data={'$pull': { "friends": theirFriendList[0] }}) flash(f'Delete friend successful!') return redirect(url_for('friends')) else: flash(f'Delete friend failed!') flash('pontential DB issue pls contact admin') return redirect(url_for('friends'))
def insert(self,userEmail,userId): event = DB.insert(collection='Events', data=self.json()) DB.update_one(collection='Profile',filter={'email':userEmail}, data = {'$push': {'events':event.inserted_id}}) profilePic = DB.find_one(collection = "Profile", query = {"email": userEmail}, projection = {"pictureDir" : 1, 'firstName':1, 'lastName':1}) DB.update_one(collection = "Events", filter ={'_id':event.inserted_id}, data = {'$push': {"invitees": {"id":userId, "email": userEmail, "status": "going", "profilePic":profilePic['pictureDir'], "name":profilePic['firstName'] + " " + profilePic['lastName']}}}) return event.inserted_id
def update_vote(poll): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) toUpdate = DB.find_one(collection='Poll', query={'_id': ObjectId(poll)}) if toUpdate is None: flash('Please contact admin, DB error!') return redirect(url_for('polls')) options = request.form.getlist('date') if request.form.get('add') == 'add': for dates in options: # dates = dates.split(' ')[0] dt = datetime.strptime(dates, "%Y-%m-%d %H:%M:%S") # test = DB.find_one(collection='Poll', query={'options': dt}) # print(test) index = get_index_1key(arrayList=toUpdate, key='options', query=dt) print(index) index = "options." + str(index) + ".voters" check = DB.find_one(collection='Poll', query={index: user['email']}) if check is not None: flash(f'You Already voted for {dt}') return redirect(url_for('polls')) DB.update_one(collection='Poll', filter={'_id': ObjectId(poll)}, data={'$push': { index: user['email'] }}) return redirect(url_for('polls')) elif request.form.get('del') == 'del': for dates in options: dt = datetime.strptime(dates, "%Y-%m-%d %H:%M:%S") index = get_index_1key(arrayList=toUpdate, key='options', query=dt) print(index) index = "options." + str(index) + ".voters" check = DB.find_one(collection='Poll', query={index: user['email']}) if check is None: flash(f'You haven\'t voted for {dt}') return redirect(url_for('polls')) DB.update_one(collection='Poll', filter={'_id': ObjectId(poll)}, data={'$pull': { index: user['email'] }}) return redirect(url_for('polls')) flash(f'Pick an option') return redirect(url_for('polls'))
def updatecertificate(): if request.method == 'POST': username = session.get('user') updatetext = request.form['updatetxt'] collection = 'Certifications' query = {'Email': username} newvalues = {"$push": {'certificates': updatetext}} DB.update_one(collection, query, newvalues) flash("Certificate Successfully Updated") return render_template('home.html', username=session.get('user'), personal=None, academic=None)
def updateacademic(): if request.method == 'POST': print(session.get('user')) username = session.get('user') updatecol = request.form['updateinfo'] updatetext = request.form['updatetxt'] collection = 'AcademicInfo' query = {'Email': username} newvalues = {"$set": {updatecol: updatetext}} print(updatecol, updatetext) DB.update_one(collection, query, newvalues) flash(updatecol + " Successfully Updated") return render_template('home.html', username=session.get('user'), personal=None, academic=None)
def edit_event(eventId): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) event = DB.find_one(collection="Events", query={"_id": ObjectId(eventId)}) if event is None: flash('Please contact admin, DB issues!') return redirect(url_for('view_events')) form = EventForm() if form.validate_on_submit(): if form.pictureDir.data is not None: if event['pictureDir'] == 'event.jpg': filename = photos.save(form.pictureDir.data, name='event/' + str(event['_id']) + '.') filename = filename.split('/')[1] else: # delete existing photo filename = "app/static/images/event/" + event['pictureDir'] os.remove(os.path.join(filename)) filename = photos.save(form.pictureDir.data, name='event/' + str(event['_id']) + '.') filename = filename.split('/')[1] DB.update_one(collection="Events", filter={"_id": event['_id']}, data={"$set": { "pictureDir": filename }}) if form.eventType.data == 'private': event_type = True else: event_type = False DB.update_one(collection="Events", filter={"_id": event['_id']}, data={"$set": { "name": form.name.data.strip() }}) DB.update_one( collection="Events", filter={"_id": event['_id']}, data={"$set": { "description": form.description.data.strip() }}) DB.update_one(collection="Events", filter={"_id": event['_id']}, data={"$set": { "private": event_type }}) return redirect(url_for('view_events')) return render_template('edit-event.html', title="Edit Event Details", form=form, event=event)
def confirm_email(token): try: serializer = URLSafeTimedSerializer(app.config['SECRET_KEY']) email = serializer.loads(token, salt=app.config['SECRET_KEY']) print(email) except: flash('Confirmation link is invalid or expired') return redirect(url_for('login')) user = DB.find_one(collection="User", query={"email": email}) if user['confirmed']: flash('Account already confirmed. Please login!') else: DB.update_one(collection="User", filter={"email": email}, data={"$set": { "confirmed": True }}) flash('Thank you for confirming your email. Please login!') return redirect(url_for('login'))
def accept_request(profile_id): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) # only can add user with a profile friend = DB.find_one(collection="Profile", query={"_id": ObjectId(profile_id)}) if friend is None: flash('User not found!') return redirect(url_for('friends')) if friend['friends'] != []: index = get_index_2key(arrayList=friend['friends'], key='friend_id', query=user['_id'], key2='status', query2='pending') if index == -1: flash('invalid request') return redirect(url_for('friends')) else: friend_status = "friends." + str(index) + ".status" DB.update_one(collection="Profile", filter={"_id": friend['_id']}, data={"$set": { friend_status: "accepted" }}) DB.update_one(collection="Profile", filter={"_id": user['_id']}, data={ "$push": { "friends": { "friend_id": friend['_id'], "status": "accepted" } } }) flash('Accepted %s\'s friend request!' % friend['email']) return redirect(url_for('friends')) flash('pontential DB issue pls contact admin') return redirect(url_for('friends'))
def delete_event(id): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) #delete the event from the id #first go through all the users that is associated with that id x = DB.find_one(collection="Events", query={"_id": ObjectId(id)}) profileList = x['invitees'] # Delete the event from all users in profile for profile in profileList: DB.update_one(collection="Profile", filter={"email": profile['email']}, data={"$pull": { "events": ObjectId(id) }}) #delete the actual event from the database DB.remove(collection="Events", condition={"_id": ObjectId(id)}) return redirect(url_for("view_events"))
def addPeople(userId=None, id=None): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) # we have the email and id of the user & event we want to invite, # we need to update the number of people in the invitees (add the profile to it) # also update the profile's thingy profileEvents = DB.find_one(collection="Profile", query={"_id": ObjectId(userId)}) pics = profileEvents email = profileEvents['email'] profileEvents = profileEvents['events'] if ObjectId(id) not in profileEvents: DB.update_one(collection="Events", filter={'_id': ObjectId(id)}, data={ '$push': { "invitees": { "id": ObjectId(userId), "email": email, "status": "invited", "profilePic": pics['pictureDir'], "name": pics['firstName'] + " " + pics['lastName'] } } }) DB.update_one(collection="Profile", filter={"email": email}, data={"$push": { "events": ObjectId(id) }}) return redirect(url_for("display_event", id=id))
def send_request(profile_id): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) # only can add user with a profile friend = DB.find_one(collection="Profile", query={"_id": ObjectId(profile_id)}) if friend is None: flash('User not found!') return redirect(url_for('friends')) for f in user['friends']: if friend['_id'] == f['friend_id'] and f['status'] == 'accepted': flash('%s has already accepted your friend request!' % friend['email']) return redirect(url_for('friends')) elif friend['_id'] == f['friend_id'] and f['status'] == 'pending': flash('Already sent %s a friend request!' % friend['email']) return redirect(url_for('friends')) for f in friend['friends']: if user["_id"] == f['friend_id']: flash('%s already sent you a friend request!' % friend['email']) return redirect(url_for('friends')) DB.update_one(collection="Profile", filter={"_id": user['_id']}, data={ "$push": { "friends": { "friend_id": friend['_id'], "status": "pending" } } }) flash('Friend request sent to ' + friend['email'] + '!') return redirect(url_for('friends'))
def update_attendance(eventId): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) if request.method == 'POST': attendance = request.form['statusType'] print(attendance) # update the status of the invididual DB.update_one(collection="Events", filter={ "_id": ObjectId(eventId), "invitees": { "$elemMatch": { "email": current_user.email } } }, data={'$set': { "invitees.$.status": attendance }}) return redirect(url_for('display_event', id=eventId))
def delete_cohost(userId, eventId): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) # Add the userId to the event invitePrivleges #check whether a valid cohost value = DB.update_one( collection="Events", filter={"_id": ObjectId(eventId)}, data={"$pull": { "invitePrivleges": { "cohostId": ObjectId(userId) } }}) if value is None: flash('The user you have tried to remove is not an admin!') return redirect(url_for('display_event', id=eventId))
def deleteInvite(eventId, userId): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) # Delete user from the Event model from invitees # Get the list of invitees from Event model # also delete them from invitePrivleges if DB.find_one(collection="Events", query={ "_id": ObjectId(eventId), "invitePrivleges": { "$elemMatch": { "cohostId": ObjectId(userId) } } }): print("ASGASGASG") DB.update_one(collection="Events", filter={"_id": ObjectId(eventId)}, data={ "$pull": { "invitePrivleges": { "cohostId": ObjectId(userId) } } }) userEmail = DB.find_one(collection="Profile", query={"_id": ObjectId(userId)}, projection={"email": 1}) DB.update_one(collection="Events", filter={"_id": ObjectId(eventId)}, data={"$pull": { "invitees": { "id": ObjectId(userId) } }}) DB.update_one(collection="Profile", filter={"_id": ObjectId(userId)}, data={"$pull": { "events": ObjectId(eventId) }}) return redirect(url_for("display_event", id=eventId))
def insert(self): if not DB.find_one("users", {"name": self.name}): DB.insert(collection='users', data=self.insert_json()) else: DB.update_one("users", {"name": self.name}, self.update_json())
def edit_profile(): form = ProfileForm() profile = DB.find_one(collection="Profile", query={"email": current_user.email}) if form.validate_on_submit(): user = DB.find_one(collection="User", query={"email": current_user.email}) if user is None: flash("Sign Up Failed") return redirect(url_for('register')) else: profile = DB.find_one(collection="Profile", query={"email": user['email']}) if profile is None: # https://pythonise.com/feed/flask/flask-uploading-files # can possibly add more checks (e.g. file extension) # can't seem to get secure_filename() to work # file = secure_filename(form.pictureDir.data.filename) # file = os.path.join(app.config['UPLOADED_PHOTOS_DEST'], file) # print(file) # credit: default female and male image from w3schools.com if form.pictureDir.data is None: if form.gender.data == "male": filename = "male.jpg" else: filename = "female.jpg" else: filename = photos.save(form.pictureDir.data, name='profile/' + user['email'] + '.') filename = filename.split('/')[1] profile_obj = Profile(email=user['email'], firstName=form.firstName.data, lastName=form.lastName.data, descriptions=form.descriptions.data, gender=form.gender.data, pictureDir=filename) profile_obj.insert() else: # update existing profile # Don't need to check if None since it is required in form # if form.firstName.data is not None: DB.update_one( collection="Profile", filter={"email": current_user.email}, data={"$set": { "firstName": form.firstName.data }}) # if form.lastName.data is not None: DB.update_one(collection="Profile", filter={"email": current_user.email}, data={"$set": { "lastName": form.lastName.data }}) # if form.descriptions.data is not None: DB.update_one( collection="Profile", filter={"email": current_user.email}, data={"$set": { "descriptions": form.descriptions.data }}) # if form.gender.data is not None: DB.update_one(collection="Profile", filter={"email": current_user.email}, data={"$set": { "gender": form.gender.data }}) if form.pictureDir.data is not None: if profile['pictureDir'] == "male.jpg" or profile[ 'pictureDir'] == "female.jpg": filename = photos.save(form.pictureDir.data, name='profile/' + current_user.email + '.') filename = filename.split('/')[1] else: # delete existing photo filename = "app/static/images/profile/" + profile[ 'pictureDir'] os.remove(os.path.join(filename)) filename = photos.save(form.pictureDir.data, name='profile/' + current_user.email + '.') filename = filename.split('/')[1] DB.update_one(collection="Profile", filter={"email": current_user.email}, data={"$set": { "pictureDir": filename }}) else: if profile['pictureDir'] == "male.jpg" or profile[ 'pictureDir'] == "female.jpg": filename = form.gender.data + ".jpg" DB.update_one(collection="Profile", filter={"email": current_user.email}, data={"$set": { "pictureDir": filename }}) return redirect('/profile') return render_template('edit-profile.html', title='Edit profile', form=form, profile=profile)
def add_post_by_id(event_id, post_id): DB.update_one(collection='Events',filter={'_id':event_id}, data={'$push': {'eventPosts':post_id}})
def addProfile(self, newProfile,eventId ): DB.update_one(collection='Profile', filter = {'_id':eventId}, data = {'$push':{'invitees':newProfile}}) return None
def poll_create_event(poll): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) my_poll = DB.find_one(collection="Poll", query={"_id": ObjectId(poll)}) if my_poll is None: flash('Please contact admin, DB issues!') return redirect(url_for('polls')) date1 = None largest = 0 for option in my_poll['options']: if 'voters' in option: if len(list(option['voters'])) > largest: largest = len(list(option['voters'])) date1 = option['date'] event_obj = Event(name=my_poll['name'], description=my_poll['description'], start=date1, end=None, host=user['_id'], invitees=[], pictureDir='events.jpg', private=True).json() form = EventForm() if form.validate_on_submit(): form.starttime.data = form.starttime.data.split(' ') time1 = form.starttime.data[0].split(':') if form.starttime.data[1] == 'PM': time1[0] = int(time1[0]) + 12 if time1[0] == 24: time1[0] = 0 time1 = time(int(time1[0]), int(time1[1])) form.endtime.data = form.endtime.data.split(' ') time2 = form.endtime.data[0].split(':') if form.endtime.data[1] == 'PM': time2[0] = int(time2[0]) + 12 if time2[0] == 24: time2[0] = 0 time2 = time(int(time2[0]), int(time2[1])) date1 = datetime((form.start.data).year, (form.start.data).month, (form.start.data).day, time1.hour, time1.minute) date2 = datetime((form.end.data).year, (form.end.data).month, (form.end.data).day, time2.hour, time2.minute) # check date and time if date1 < datetime.now(): flash('Start has to be today or later!') return render_template('poll-create-event.html', title="Create Your Event", form=form, poll=poll, event=event_obj) elif date2 < date1: flash('End cannot be earlier than Start!') return render_template('poll-create-event.html', title="Create Your Event", form=form, poll=poll, event=event_obj) elif date1 == date2: flash('Start and End cannot be the same!') return render_template('poll-create-event.html', title="Create Your Event", form=form, poll=poll, event=event_obj) if form.pictureDir.data is None: filename = "event.jpg" else: filename = photos.save(form.pictureDir.data, name='event/' + str(user['_id']) + '.') filename = filename.split('/')[1] form.name.data = form.name.data.strip() form.description.data = form.description.data.strip() if form.eventType.data == 'private': event_type = True else: event_type = False inviteesList = [] for voter in my_poll['voters']: voter_obj = DB.find_one(collection='Profile', query={'_id': voter}) voter_dict = {'email': voter_obj['email'], 'status': 'going'} inviteesList.append(voter_dict) updated_event = Event(name=form.name.data, description=form.description.data, start=date1, end=date2, host=user['_id'], invitees=inviteesList, pictureDir=filename, private=event_type) eventid = updated_event.insert(user['email'], user['_id']) for invitees in inviteesList: DB.update_one(collection="Profile", filter={"email": invitees['email']}, data={"$push": { "events": ObjectId(eventid) }}) return redirect(url_for('delete_poll', poll=poll)) return render_template('poll-create-event.html', title="Create Your Event", form=form, poll=poll, event=event_obj)
def add_cohost(userId, eventId): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) # Add the userId to the event invitePrivleges person = DB.find_one(collection="Events", query={ "_id": ObjectId(eventId), "invitePrivleges": { "$elemMatch": { "cohostId": ObjectId(userId) } } }) if person is None: #check if the user has been invited #if not any(person['email'] == current_user.email for person in eventDetails['invitees']): userDetails = DB.find_one(collection="Profile", query={"_id": ObjectId(userId)}, projection={ "email": 1, "firstName": 1, "lastName": 1, "pictureDir": 1 }) if DB.find_one(collection="Events", query={ "_id": ObjectId(eventId), "invitees": { "$elemMatch": { "id": ObjectId(userId) } } }) is None: DB.update_one(collection="Events", filter={"_id": ObjectId(eventId)}, data={ "$push": { "invitees": { "id": ObjectId(userId), "email": userDetails['email'], "status": "invited", "profilePic": userDetails['pictureDir'], "name": userDetails['firstName'] + " " + userDetails['lastName'] } } }) DB.update_one(collection="Events", filter={"_id": ObjectId(eventId)}, data={ "$push": { "invitePrivleges": { "email": userDetails['email'], "cohostId": ObjectId(userId), "pictureDir": userDetails['pictureDir'], "name": userDetails['firstName'] + " " + userDetails['lastName'] } } }) return redirect(url_for('display_event', id=eventId))
def acceptInvite(eventId, acceptance): user = DB.find_one(collection="Profile", query={"email": current_user.email}) if user is None: flash('Please create your profile first!') return redirect(url_for('edit_profile')) #need to change the user to accepting that event id # check if the event is public isPublic = DB.find_one(collection="Events", query={"_id": ObjectId(eventId)}, projection={"private": 1}) if isPublic['private']: DB.update_one(collection="Events", filter={ "_id": ObjectId(eventId), "invitees": { "$elemMatch": { "email": current_user.email } } }, data={'$set': { "invitees.$.status": acceptance }}) else: #need to add to the event to the profile event list first userId = DB.find_one(collection="Profile", query={"email": current_user.email}, projection={ "_id": 1, "pictureDir": 1, "firstName": 1, "lastName": 1 }) print(type(userId['_id'])) # if you were invited if DB.find_one(collection="Profile", query={ "email": current_user.email, "events": ObjectId(eventId) }): DB.update_one(collection="Events", filter={ "_id": ObjectId(eventId), "invitees": { "$elemMatch": { "email": current_user.email } } }, data={'$set': { "invitees.$.status": acceptance }}) else: DB.update_one(collection="Profile", filter={"email": current_user.email}, data={"$push": { "events": ObjectId(eventId) }}) DB.update_one(collection="Events", filter={"_id": ObjectId(eventId)}, data={ "$push": { "invitees": { "id": userId['_id'], "email": current_user.email, "status": acceptance, "profilePic": userId['pictureDir'], "name": userId['firstName'] + " " + userId['lastName'] } } }) return redirect(url_for("display_event", id=eventId))