Example #1
0
def updateUserInfo(form):
    firstName = form.get('firstName', None)
    lastName = form.get('lastName', None)
    country = form.get('country', None)
    username = form.get('username', None)

    if checks.emptyCheck([firstName, lastName, country]):
        return jsonify({
            "message": "Please fill in all fields."
        }), 400, {'ContentType': 'application/json'}

    if checks.lengthSixtyFourCheck([firstName, lastName, country]):
        return jsonify({
            "message": "Please don't fill in more than 64 characters."
        }), 400, {'ContentType': 'application/json'}

    password = form.get('password', None)
    if password:
        check = checks.passwordLengthCheck(password)
        if check == [False, "short"]:
            return jsonify({
                "message": "Please make your password 5 characters or longer."
            }), 400, {'ContentType': 'application/json'}
        if check == [False, "long"]:
            return jsonify({
                "message": "Please keep your password shorter than 64 characters."
            }), 400, {'ContentType': 'application/json'}

    return persister.updateUserInfo(firstName, lastName, country, username, password)
Example #2
0
    def updateEvent(self, request):
        db = Session()
        form = request.args

        event = db.query(Event)\
            .filter(Event.id == form.get('eventId'))\
            .first()

        if event.owner == form.get('owner'):

            location = form.get('location').strip()
            name = form.get('name').strip()
            description = form.get('description').strip()
            startDate = form.get('startDate')
            startTime = form.get('startTime')
            endDate = form.get('endDate')
            endTime = form.get('endTime')
            owner = form.get('owner')
            lng = form.get('lng')
            lat = form.get('lat')

            if checks.emptyCheck([
                    location, name, description, startDate, startTime, endDate,
                    endTime, owner, lng, lat
            ]):
                return jsonify({"message":
                                "Please, fill in all fields."}), 400, {
                                    'ContentType': 'application/json'
                                }

            if checks.lengthSixtyFourCheck([name]):
                return jsonify({
                    "message":
                    "Please don't fill in more than 64 characters."
                }), 400, {
                    'ContentType': 'application/json'
                }

            if checks.dateTimeCheck(startDate, startTime, endDate, endTime):
                return jsonify({
                    "message":
                    "A problem occurred with regards to the dates and times of this event.<br>"
                    "Rules:<br>"
                    "- Events that start later than 1 year from now are not allowed.<br>"
                    "- The event's start date/time can't be later than the end date/time.<br>"
                    "- You can't enter dates earlier than today.<br>"
                    "- An event's length can't be longer than a year."
                }), 400, {
                    'ContentType': 'application/json'
                }

            if request.files.get('image'):
                file = request.files.get('image', None)
                img = str(time.time()).replace(".", "")
                ext = file.filename.partition(".")[-1]
                if not checks.imgExtensionCheck(ext):
                    return jsonify({
                        "message":
                        "Only .png, .jpg or .jpeg  images are valid!"
                    }), 400, {
                        'ContentType': 'application/json'
                    }
                img = img + "." + ext
                file.save(os.path.join('images\events', img))
            else:
                img = None

            temp = location.split(', ')
            country = None
            city = None
            address = None
            if len(temp) > 0:
                country = temp.pop()
            if len(temp) > 0:
                city = temp.pop()
                if len(city.split(" ")) > 2:
                    temp2 = city.split(" ")
                    city = temp2.pop()
                    address = ", " + " ".join(temp2)
            if len(temp) > 0:
                if address:
                    address = ', '.join(temp) + address
                else:
                    address = ', '.join(temp)

            event.name = name
            event.description = description
            event.address = address
            event.city = city
            event.country = country
            event.startDate = form.get('startDate')
            event.startTime = form.get('startTime')
            event.endDate = form.get('endDate')
            event.endTime = form.get('endTime')
            event.lat = form.get('lat')
            event.lng = form.get('lng')
            if img:
                event.image = img

        db.commit()
        db.close()

        return jsonify({"message": "Event updated!"}), 200, {
            'ContentType': 'application/json'
        }
Example #3
0
def registerSubmit(form, clearance):
    firstName = form.get('firstName', None)
    lastName = form.get('lastName', None)
    email = form.get('email', None)
    password = form.get('password', None)
    wordpresskey = form.get('wordpresskey', None)

    firstName = firstName.strip()
    lastName = lastName.strip()
    firstName = firstName.lower()
    lastName = lastName.lower()
    email = email.lower()
    password = password.lower()

    if checks.checkSpecialChars([firstName, lastName]):
        msg = "Gebruik alstublieft geen speciale karakters in uw naam!"
        return {"code": 400, "message": msg}

    if checks.checkSpecialCharsEmail(email):
        msg = "Gebruik alstublieft geen speciale karakters in uw email!"
        return {"code": 400, "message": msg}

    if checks.emptyCheck([firstName, lastName, email, password]):
        msg = "Vul alstublieft alle velden in."
        return {"code": 400, "message": msg}

    if checks.lengthSixtyFourCheck([firstName, lastName, email]):
        msg = "Vul alsublieft niet meer dan 64 karakters in."
        return {"code": 400, "message": msg}

    password = form.get('password', None)
    check = checks.passwordLengthCheck(password)

    if check == [False, "short"]:
        msg = "Uw wachtwoord moet langer dan 5 karakters zijn."
        return {"code": 400, "message": msg}

    if check == [False, "long"]:
        msg = "Uw wachtwoord moet korter zijn dan 64 karakters."
        return {"code": 400, "message": msg}

    if Persister.checkEmailExistance(email):
        msg = "Dit emailadres bestaat al."
        return {"code": 400, "message": msg}

    if (clearance == 0):
        person = Person(firstname=firstName,
                        lastname=lastName,
                        email=email,
                        password=password,
                        points=0,
                        clearance=0,
                        license=True,
                        authenticated=False)
        return Persister.persist_object(person)
    elif (clearance == 1):
        person = Person(firstname=firstName,
                        lastname=lastName,
                        email=email,
                        password=password,
                        points=0,
                        clearance=1,
                        wordpressKey=wordpresskey,
                        license=True,
                        authenticated=False,
                        biography=form.get('biography'),
                        profilePhoto=form.get('img'))
        return Persister.persist_object(person)
    else:
        return None
Example #4
0
def registerSubmit(form):
    # check if username en email there

    firstName = form.get('firstName', None)
    lastName = form.get('lastName', None)
    country = form.get('country', None)
    email = form.get('email', None)
    username = form.get('username', None)
    password = form.get('password', None)

    username = username.replace(" ", "")
    email = email.replace(" ", "")
    firstName = firstName.strip()
    lastName = lastName.strip()
    firstName = firstName.lower()
    lastName = lastName.lower()
    country = country.lower()
    email = email.lower()
    username = username.lower()
    password = password.lower()

    if checks.checkSpecialChars([username]):
        return jsonify({
            "message": "Please use no special characters in your username!"
        }), 400, {'ContentType': 'application/json'}

    if checks.checkSpecialCharsEmail(email):
        return jsonify({
            "message": "Please use no special characters in your email!"
        }), 400, {'ContentType': 'application/json'}

    if checks.emptyCheck([firstName, lastName, email, country, username, password]):
        return jsonify({
            "message": "Please fill in all fields."
        }), 400, {'ContentType': 'application/json'}

    if checks.lengthSixtyFourCheck([firstName, lastName, country, email, username]):
        return jsonify({
            "message": "Please don't fill in more than 64 characters."
        }), 400, {'ContentType': 'application/json'}

    password = form.get('password', None)
    check = checks.passwordLengthCheck(password)
    if check == [False, "short"]:
        return jsonify({
            "message": "Please make your password 5 characters or longer."
        }), 400, {'ContentType': 'application/json'}
    if check == [False, "long"]:
        return jsonify({
            "message": "Please keep your password shorter than 64 characters."
        }), 400, {'ContentType': 'application/json'}

    if persister.checkUserExistance(username, email):
        return jsonify({
            "message": "Username or email already exists."
        }), 400, {'ContentType': 'application/json'}

    user = User(
        username=username,
        email=email,
        firstName=firstName,
        lastName=lastName,
        password=pbkdf2_sha256.hash(password),
        country=country
    )

    persister.persist_object(user)
    persister.addFriend(username, "Never Travel Alone")

    return jsonify({
        "message": "Welcome to TravelBuddy! You are now a member."
    }), 200, {'ContentType': 'application/json'}