Beispiel #1
0
def delete_account(user_id):

    user = User.get_by_id(user_id)
    User.delete_user(user_id)

    images = Image.images_from_mongo(user.username)
    Image.delete_images(user.username)

    # delete images from folder
    for image in images:
        target = os.path.join(APP_ROOT,
                              'static/images/{}'.format(image.filename))
        os.remove(target)

    # delete the profile_pic as well
    if user.profile_image != 'Anonyymi.jpeg':
        target2 = os.path.join(
            APP_ROOT, "static/profile_pics/{}".format(user.profile_image))
        os.remove(target2)

    # log out
    session.clear()
    logout_user()

    flash('Your account and all images associated with it are now deleted',
          "success")
    return render_template("home.html", images=all_images())
def delete_user(user_id):
    user = User.get_user(user_id)
    if user is None:
        raise Error(StatusCode.NOT_FOUND, 'Cannot find user')
    User.delete_user(user_id)
    return jsonify({'status': True, 'message': 'Delete user successfully'})