Exemplo n.º 1
0
def account():
    # Get account info from service
    try:
        payload = requests.get(service_ip + '/site/admin_user/account_info/' +
                               admin_key.get_key())
    except:
        flash("Unable to Connect to Server!", "danger")
        return redirect(url_for('error.server_error'))

    # Check admin Key is good
    if payload.status_code == 401:
        if current_user.is_authenticated:
            logout_user()
        flash('Please login to access this page.', 'info')
        return redirect(url_for('admin_user.admin_login'))

    form = UpdateAccountForm()
    if form.validate_on_submit():
        payload = {}

        # pack the updated account info
        payload["username"] = form.username.data
        payload["email"] = form.email.data

        # Send the updated account
        try:
            response = requests.put(service_ip +
                                    '/site/admin_user/update_account/' +
                                    admin_key.get_key(),
                                    json=payload)
        except:
            flash("Unable to Connect to Server!", "danger")
            return redirect(url_for('error.server_error'))

        # Check admin Key is good
        if response.status_code == 401:
            if current_user.is_authenticated:
                logout_user()
            flash('Please login to access this page.', 'info')
            return redirect(url_for('admin_user.admin_login'))

        # Check response
        if response.status_code == 204 or response.status_code == 200:
            flash('Account has been updated!', 'success')
        else:
            flash('Something happened and settings were not updated.',
                  'danger')

        return redirect(url_for('admin_user.account'))

    elif request.method == 'GET':
        form.username.data = payload.json()["username"]
        form.email.data = payload.json()["email"]

    return render_template("admin_user/account.html",
                           title="Account Information",
                           form=form,
                           payload=payload)
Exemplo n.º 2
0
def remove(id, location):
    form = RemovePictureForm()
    if form.validate_on_submit():
        # Post a delete image files here
        try:
            response = requests.delete(service_ip + '/site/remove_images/' +
                                       str(id) + '/' + form.removals.data +
                                       '/' + admin_key.get_key())
        except:
            flash("Unable to Connect to Server!", "danger")
            return redirect(url_for('error.server_error'))

        # Check admin Key is good
        if response.status_code == 401:
            if current_user.is_authenticated:
                logout_user()
            flash('Please login to access this page.', 'info')
            return redirect(url_for('admin_user.admin_login'))

        if response.status_code == 204:
            flash('Images have been successfuly removed!', 'success')
        elif response.status_code == 400:
            flash('Image was not found in the server!', 'danger')
        else:
            flash("Oops! Something happened and the images were not deleted.",
                  "danger")

    # Grab device location and image count
    try:
        payload = requests.get(service_ip + '/site/image_count/' + str(id) +
                               '/' + admin_key.get_key())
    except:
        flash("Unable to Connect to Server!", "danger")
        return redirect(url_for('error.server_error'))

    # Check admin Key is good
    if payload.status_code == 401:
        if current_user.is_authenticated:
            logout_user()
        flash('Please login to access this page.', 'info')
        return redirect(url_for('admin_user.admin_login'))

    image_count = payload.json()["image_count"]

    random_hex = secrets.token_hex(8)

    return render_template("slide_show/remove.html",
                           title="Picture Removal",
                           location=location,
                           form=form,
                           service_ip=service_ip,
                           id=id,
                           image_count=image_count,
                           random_hex=random_hex)
Exemplo n.º 3
0
def upload(id, location):
    # Grab device image count
    try:
        payload = requests.get(service_ip + '/site/image_count/' + str(id) +
                               '/' + admin_key.get_key())
    except:
        flash("Unable to Connect to Server!", "danger")
        return redirect(url_for('error.server_error'))

    # Check admin Key is good
    if payload.status_code == 401:
        if current_user.is_authenticated:
            logout_user()
        flash('Please login to access this page.', 'info')
        return redirect(url_for('admin_user.admin_login'))

    image_count = payload.json()["image_count"]

    form = SlideShowPicsForm()
    if form.validate_on_submit():
        image_files = []
        for file in form.picture.data:
            image_files.append(('image', (file.filename, file.read())))

        # Do the post here
        try:
            response = requests.post(service_ip + '/site/images/upload/' +
                                     str(id) + '/' + admin_key.get_key(),
                                     files=image_files)
        except:
            flash("Unable to Connect to Server!", "danger")
            return redirect(url_for('error.server_error'))

        # Check admin Key is good
        if response.status_code == 401:
            if current_user.is_authenticated:
                logout_user()
            flash('Please login to access this page.', 'info')
            return redirect(url_for('admin_user.admin_login'))

        flash('Pictures has been uploaded', 'success')
        return redirect(url_for('slide_show.upload', id=id, location=location))

    random_hex = secrets.token_hex(8)

    return render_template("slide_show/upload.html",
                           title="Picture Upload",
                           location=location,
                           form=form,
                           service_ip=service_ip,
                           id=id,
                           image_count=image_count,
                           random_hex=random_hex)
Exemplo n.º 4
0
def change_request_OLD():
    # !!!
    # These routes are depreciated because of non-working email
    return redirect(url_for('main.home'))

    # Get account info from service
    try:
        payload = requests.get(service_ip + '/site/admin_user/account_info/' +
                               admin_key.get_key())
    except:
        flash("Unable to Connect to Server!", "danger")
        return redirect(url_for('error.server_error'))

    # Verify admin key
    if payload.status_code == 401:
        if current_user.is_authenticated:
            logout_user()
        flash('Please login to access this page.', 'info')
        return redirect(url_for('admin_user.admin_login'))

    user = AdminUser.query.first()
    send_reset_email(email=payload.json()["email"], user=user, logged_in=True)

    flash('An email has been sent with instructions to reset your password.',
          'info')
    return redirect(url_for('admin_user.account'))
Exemplo n.º 5
0
def home():
    try:
        payload = requests.get(service_ip + '/site/get_all/' +
                               admin_key.get_key())
    except:
        flash("Unable to Connect to Server!", "danger")
        return redirect(url_for('error.server_error'))

    # Check admin Key is good
    if payload.status_code == 401:
        if current_user.is_authenticated:
            logout_user()
        flash('Please login to access this page.', 'info')
        return redirect(url_for('admin_user.admin_login'))

    device_id_list = payload.json()["device_id"]
    location_list = payload.json()["location"]

    devices = zip(location_list, device_id_list)

    return render_template("home.html", title="Home", devices=devices)
Exemplo n.º 6
0
def change_token_OLD(token):
    # !!!
    # These routes are depreciated because of non-working email
    return redirect(url_for('main.home'))

    user = AdminUser.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('admin_user.admin_login'))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        payload = {}
        payload["hashed_password"] = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')

        try:
            response = requests.put(service_ip +
                                    '/site/admin_user/update_password/' +
                                    admin_key.get_key(),
                                    json=payload)
        except:
            flash("Unable to Connect to Server!", "danger")
            return redirect(url_for('error.server_error'))

        # Verify admin key
        if response.status_code == 401:
            if current_user.is_authenticated:
                logout_user()
            flash('Please login to access this page.', 'info')
            return redirect(url_for('admin_user.admin_login'))

        flash('Your password has been updated!', 'success')
        return redirect(url_for('admin_user.admin_login'))
    return render_template('admin_user/reset_token.html',
                           title='Reset Password',
                           form=form)
Exemplo n.º 7
0
def device_settings(id):

    form = SettingsForm()
    if form.validate_on_submit():
        payload = {}

        payload["toggle_pay"] = form.toggle_pay.data
        payload["price"] = form.price.data

        minutes = form.charge_time_min.data
        seconds = form.charge_time_sec.data
        payload["charge_time"] = minutes * 60 + seconds

        payload["time_offset"] = form.time_zone.data
        payload["location"] = form.location.data

        payload["aspect_ratio_width"] = float(
            form.aspect_ratio.data.split(":")[0])
        payload["aspect_ratio_height"] = float(
            form.aspect_ratio.data.split(":")[1])

        try:
            response = requests.put(service_ip + '/site/settings/update/' +
                                    str(id) + '/' + admin_key.get_key(),
                                    json=payload)
        except:
            flash("Unable to Connect to Server!", "danger")
            return redirect(url_for('error.server_error'))

        # Check admin Key is good
        if response.status_code == 401:
            if current_user.is_authenticated:
                logout_user()
            flash('Please login to access this page.', 'info')
            return redirect(url_for('admin_user.admin_login'))

        if response.status_code == 204 or response.status_code == 200:
            flash('Settings have been updated!', 'success')
        elif response.status_code == 400:
            flash('Server could not find device!', 'danger')
        else:
            flash('Something happened and settings were not updated.',
                  'danger')

        return redirect(url_for('settings.device_settings', id=id))
    elif request.method == 'GET':
        # Grab device settings
        try:
            payload = requests.get(service_ip + '/site/settings/' + str(id) +
                                   '/' + admin_key.get_key())
        except:
            flash("Unable to Connect to Server!", "danger")
            return redirect(url_for('error.server_error'))

        # Check admin Key is good
        if payload.status_code == 401:
            if current_user.is_authenticated:
                logout_user()
            flash('Please login to access this page.', 'info')
            return redirect(url_for('admin_user.admin_login'))

        settings = payload.json()

        form.toggle_pay.data = settings["toggle_pay"]
        form.price.data = settings["price"]
        minutes, seconds = get_min_sec(seconds=settings["charge_time"])
        form.charge_time_min.data = minutes
        form.charge_time_sec.data = seconds
        form.time_zone.data = settings["time_offset"]
        form.location.data = settings["location"]
        form.aspect_ratio.data = str( int(settings["aspect_ratio_width"]) if (settings["aspect_ratio_width"]).is_integer() else settings["aspect_ratio_width"] ) \
               + ":" + str( int(settings["aspect_ratio_height"]) if (settings["aspect_ratio_height"]).is_integer() else settings["aspect_ratio_height"] )

    return render_template("settings/settings.html",
                           title="Settings",
                           form=form)
Exemplo n.º 8
0
def confirm_removal(id, location):
    form = LoginForm()
    if form.validate_on_submit():
        json_send = {}
        json_send["username"] = form.username.data
        json_send["password"] = form.password.data

        # Contact the server
        try:
            payload = requests.get(service_ip + '/site/admin_user/verify_user',
                                   json=json_send)
        except:
            flash("Unable to Connect to Server!", "danger")
            return redirect(url_for('error.server_error'))

        if payload.json()["user_verified"]:
            # Admin key changed after check
            admin_key.set_key(payload.json()["admin_key"])

            # remove the device
            try:
                response = requests.delete(service_ip +
                                           '/site/remove_device/' + str(id) +
                                           '/' + admin_key.get_key())
            except:
                flash("Unable to Connect to Server!", "danger")
                return redirect(url_for('error.server_error'))

            # Check admin Key is good
            if response.status_code == 401:
                if current_user.is_authenticated:
                    logout_user()
                flash('Please login to access this page.', 'info')
                return redirect(url_for('admin_user.admin_login'))

            # Check the other response codes
            if response.status_code == 204:
                flash('Device has been successfuly removed!', 'success')
            elif response.status_code == 400:
                flash('Device was not found in the server!', 'danger')
            else:
                flash(
                    "Oops! Something happened and the device was not deleted.",
                    "danger")

            return redirect(url_for('main.home'))

    return render_template("device/remove_confirm.html",
                           title="Confirm Removal",
                           form=form,
                           location=location)


# # Depretiated
# # Remove a device from the service
# @device.route("/device/remove/<int:id>")
# @login_required
# def remove_device(id):
# 	# remove the device
# 	try:
# 		response = requests.delete(service_ip + '/site/remove_device/' + str(id))
# 	except:
# 		flash("Unable to Connect to Server!", "danger")
# 		return redirect(url_for('error.server_error'))

# 	if response.status_code == 204:
# 		flash('Device has been successfuly removed!', 'success')
# 	elif response.status_code == 400:
# 		flash('Device was not found in the server!', 'danger')
# 	else:
# 		flash("Oops! Something happened and the device was not deleted.", "danger")

# 	return redirect(url_for('main.home'))