Пример #1
0
def delete_contact_info():
    contactID = request.json['contactID']
    contact = dq.getContactWithContactID(contactID)
    if contact is None:
        return jsonify({'reason': 'Contact info does not exist'}), 404

    contact.associatedUser = None
    dq.update(ContactInfo, 'associatedUser', contact)
    return jsonify({'reason': 'Contact info updated!'}), 200
Пример #2
0
def login():
    email = request.json['email']
    password = request.json['password']
    remember = True if request.json['remember'] == 'true' else False

    user = dq.getUserByEmail(email)

    if _validate(user, password):
        dq.update(user, 'deactivated', False)
        login_user(user, remember=remember)
        return jsonify({'userID': user.id, 'firstName': user.firstName}), 200
    else:
        return jsonify({'reason': "User/Password doesn't match"}), 400
Пример #3
0
def delete_roommate():
    rentalID = request.json['rentalID']
    email = request.json['email']
    user = dq.getUserByEmail(email)  # that is trying to get deleted
    if user.deactivated:
        return jsonify({'reason': "User is deactivated"}), 400

    roommatesID = dq.getRentalByRentalID(rentalID).roommates
    roommates = dq.getRentalRoommates(roommatesID)
    mates = list(filter(lambda x: x.startswith('room'), dir(roommates)))
    for ent in mates:
        if user.id == getattr(roommates, ent):
            dq.updateUserRentals(user, None)
            dq.update(roommates, ent, None)
            return jsonify({}), 201
    return jsonify({'reason': "Roommate isn't a roommate"}), 404
Пример #4
0
def change_calendar_event():
    eventID = request.json['eventID']
    event = dq.getEventByEventID(eventID)
    if event is None:
        return jsonify({'reason': 'Calendar event does not exist'}), 404

    if request.json['eventName'] is not None:
        dq.update(event, 'eventName', request.json['eventName'])
    if request.json['eventStartDT'] is not None:
        dq.update(event, 'eventStartDT', request.json['eventStartDT'])
    if request.json['eventEndDT'] is not None:
        dq.update(event, 'eventEndDT', request.json['eventEndDT'])
    if request.json['eventDescription'] is not None:
        dq.update(event, 'eventDescription', request.json['eventDescription'])
    if request.json['isDeleted'] is not None:
        dq.update(event, 'isDeleted', request.json['isDeleted'])

    return jsonify({}), 201
Пример #5
0
def add_roommate():
    '''This route is used to add a roommate to a given rental\n
    It can only be reached via POST request.\n
    The route expects that the data comes in with the following fields:\n
    item - JSON tag - description\n
    rentalID - 'rentalID' - ID of the rental to add the roommate to\n
    email - 'email' - email of the roommmate to add
    '''

    rentalID = request.json['rentalID']
    email = request.json['email']
    user = dq.getUserByEmail(email)
    if user is None:
        return jsonify({'reason': "User doesn't exist"}), 404

    if user.deactivated:
        return jsonify({'reason': "User is deactivated"}), 400

    rental = dq.getRentalByRentalID(rentalID)
    if rental is None:
        return jsonify({'reason': "Rental does not exist"}), 404

    roommates = dq.getRentalRoommates(rental.roommates)

    if roommates is not None:
        # Filter out the roommate attributes from the field
        mates = list(filter(lambda x: x.startswith('room'), dir(roommates)))
        for ent in mates:
            if getattr(roommates, ent) is None:
                dq.update(roommates, ent, user.id)
                dq.updateUserRentals(user, rentalID)
                return jsonify({}), 201
            elif getattr(roommates, ent) == user.id:
                return jsonify({'reason': "Roommate already entered"}), 400
        return jsonify({'reason': "Adding 6th Roommate is not allowed"}), 400
    else:
        err = "Roommates table somehow doesn't exist???"
        return jsonify({'reason': err}), 404
Пример #6
0
def add_lease():
    rentalID = request.json['rentalID']
    rental = dq.getRentalByRentalID(rentalID)
    landlordFirstName = request.json['landlordFirstName']
    landlordLastName = request.json['landlordLastName']
    landlordPhoneNumber = request.json['landlordPhoneNumber']
    landlordEmail = request.json['landlordEmail']
    rentCost = request.json['rentCost']
    if rentCost == "":
        rentCost = 0
    startDT = request.json['startDT']
    endDT = request.json['endDT']
    rentDueDate = request.json['rentDueDate']

    lease = Lease(landlordFirstName=landlordFirstName,
                  landlordLastName=landlordLastName,
                  landlordPhoneNumber=landlordPhoneNumber,
                  landlordEmail=landlordEmail,
                  rentCost=rentCost, startDT=startDT, endDT=endDT,
                  rentDueDate=rentDueDate)
    dq.add(lease)
    dq.update(rental, 'lease', lease.id)
    return jsonify({}), 201
Пример #7
0
def change_note_info():
    noteID = request.json['noteID']
    note = dq.getNoteByNoteID(noteID)
    if note is None:
        return jsonify({'reason': 'Note does not exist'}), 404

    if request.json['title'] is not None:
        dq.update(note, 'title', request.json['title'])
    if request.json['description'] is not None:
        dq.update(note, 'description', request.json['description'])
    if request.json['category'] is not None:
        dq.update(note, 'category', request.json['category'])
    if request.json['isDeleted'] is not None:
        dq.update(note, 'isDeleted', request.json['isDeleted'])

    return jsonify({}), 201
Пример #8
0
def change_contact_info():
    contactID = request.json['contactID']
    contact = dq.getContactWithContactID(contactID)
    if contact is None:
        return jsonify({'reason': 'Contact info does not exist'}), 404

    if request.json['name'] is not None:
        dq.update(contact, 'name', request.json['name'])
    if request.json['phoneNumber'] is not None:
        dq.update(contact, 'phoneNumber', request.json['phoneNumber'])
    if request.json['email'] is not None:
        dq.update(contact, 'email', request.json['email'])
    if request.json['relationship'] is not None:
        dq.update(contact, 'relationship', request.json['relationship'])

    return jsonify({}), 201
Пример #9
0
def change_user_info():
    userID = request.json['userID']
    user = dq.getUserById(userID)

    if user is None:
        return jsonify({'reason': 'User does not exist'}), 404

    if (request.json['email'] is not None and
            dq.getUserByEmail(request.json['email']) is None):
        dq.update(user, 'email', request.json['email'])
    if request.json['firstName'] is not None:
        dq.update(user, 'firstName', request.json['firstName'])
    if request.json['lastName'] is not None:
        dq.update(user, 'lastName', request.json['lastName'])
    if request.json['phoneNumber'] is not None:
        dq.update(user, 'phoneNumber', request.json['phoneNumber'])

    return jsonify({}), 201
Пример #10
0
def _change_password(user: Users, password: str):
    dq.update(user, 'password', pbkdf2_sha256.hash(password))
Пример #11
0
def clear_notes():
    notes = request.json['notes']
    for note in notes:
        n = dq.getNoteByNoteID(note)
        dq.update(n, 'isDeleted', True)
    return jsonify({}), 200
Пример #12
0
def change_lease_info():
    leaseID = request.json['leaseID']
    lease = dq.getLeaseByLeaseID(leaseID)
    if lease is None:
        return jsonify({'reason': 'Lease does not Exist'}), 404

    if request.json['landlordFirstName'] is not None:
        dq.update(lease, 'landlordFirstName',
                  request.json['landlordFirstName'])
    if request.json['landlordLastName'] is not None:
        dq.update(lease, 'landlordLastName', request.json['landlordLastName'])
    if request.json['landlordPhoneNumber'] is not None:
        dq.update(lease, 'landlordPhoneNumber',
                  request.json['landlordPhoneNumber'])
    if request.json['landlordEmail'] is not None:
        dq.update(lease, 'landlordEmail', request.json['landlordEmail'])
    if request.json['rentCost'] is not None:
        dq.update(lease, 'rentCost', request.json['rentCost'])
    if request.json['startDT'] is not None:
        dq.update(lease, 'startDT', request.json['startDT'])
    if request.json['endDT'] is not None:
        dq.update(lease, 'endDT', request.json['endDT'])
    if request.json['rentDueDate'] is not None:
        dq.update(lease, 'rentDueDate', request.json['rentDueDate'])

    return jsonify({}), 201
Пример #13
0
def deactivate():
    email = request.json['email']
    user = dq.getUserByEmail(email)
    dq.update(user, 'deactivated', True)
    logout_user()
    return jsonify({}), 201