Exemplo n.º 1
0
def update_pub_char(characterId):
    errors = ["An error occurred while updating your character."]
    if "image" not in request.files:
        return {"errors": errors}

    image = request.files["image"]
    charactername = request.form['charactername']
    characterlabel = request.form['characterlabel']

    if check_lengths(charactername, characterlabel):
        return {"errors": errors}

    if not allowed_file(image.filename):
        return {"errors": errors}

    image.filename = get_unique_filename(image.filename)

    upload = upload_file(image)

    if "url" not in upload:
        return {"errors": errors}

    url = upload["url"]

    old_char = PublicCharacter.query.get(characterId)
    key = old_char.get_url()

    if (key.startswith(get_s3_location())):
        key = key[39:]
        purge_aws_resource(key)

    old_char.update_character_data(url, charactername, characterlabel)
    db.session.add(old_char)
    db.session.commit()
    return {old_char.get_id(): old_char.to_dict()}
Exemplo n.º 2
0
def delete_char(characterId):
    the_character = PublicCharacter.query.get(characterId)
    key = the_character.get_url()
    if (key.startswith(get_s3_location())):
        key = key[39:]
        purge_aws_resource(key)
    db.session.delete(the_character)
    db.session.commit()
    return {"characterId": characterId}
Exemplo n.º 3
0
def delete_user(user_id):
    errors = ["An error occurred while deleting your profile."]
    if int(user_id) == int(current_user.get_id()):
        key = current_user.get_url()
        if (key.startswith(get_s3_location())):
            key = key[39:]
            purge_aws_resource(key)

        db.session.delete(current_user)
        db.session.commit()
        return {"success": "Your accont was successfully deleted."}
    else:
        return {"errors": errors}
Exemplo n.º 4
0
def update_user_info(user_id):
    errors = ["An error occurred while updating your profile."]
    if "new_avatar" not in request.files:
        return {"errors": errors}

    form = UpdateUserForm()
    name = form.data['new_name']
    email = form.data['new_email']
    password = form.data['new_password']
    bio = form.data['new_bio']
    location = form.data['new_location']
    birthdate = form.data['new_birthdate']
    avatar = request.files["new_avatar"]

    if not allowed_file(avatar.filename):
        return {"errors": errors}

    avatar.filename = get_unique_filename(avatar.filename)
    form['csrf_token'].data = request.cookies['csrf_token']

    if int(user_id) == int(current_user.get_id()):
        if check_lengths(name, email, password, bio, location, birthdate):
            return {"errors": errors}

        if form.validate_on_submit():
            upload = upload_file(avatar)

            if "url" not in upload:
                return {"errors": errors}

            url = upload["url"]
            key = current_user.get_url()
            if (key.startswith(get_s3_location())):
                key = key[39:]
                purge_aws_resource(key)

            current_user.update_user(name, email, password, bio, location, url,
                                     birthdate)
            db.session.add(current_user)
            db.session.commit()
            return {"user": current_user.to_dict()}

    return {"errors": errors}