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

    # 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('system_admin_account.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 +
                                    '/device/admin_user/update_account/' +
                                    admin_key.get_key(),
                                    json=payload)
        except:
            flash("Unable to Connect to Server!", "danger")
            return redirect(url_for('error.register'))

        # 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('system_admin_account.account'))

    elif request.method == 'GET':
        form.username.data = payload.json()["username"]
        form.email.data = payload.json()["email"]
    return render_template('system_admin/account/account.html',
                           title='Account',
                           form=form,
                           payload=payload)
Esempio n. 2
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 +
                               '/device/admin_user/account_info/' +
                               admin_key.get_key())
    except:
        flash("Unable to Connect to Server!", "danger")
        return redirect(url_for('error.register'))

    # 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('system_admin_account.login'))

    user = User.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('system_admin_account.account'))
Esempio n. 3
0
def change_token_OLD(token):
    # !!!
    # These routes are depreciated because of non-working email
    return redirect(url_for('main.home'))

    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('system_admin_account.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 +
                                    '/device/admin_user/update_password/' +
                                    admin_key.get_key(),
                                    json=payload)
        except:
            flash("Unable to Connect to Server!", "danger")
            return redirect(url_for('error.register'))

        # 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('system_admin_account.login'))

        flash('Your password has been updated!', 'success')
        return redirect(url_for('system_admin_account.login'))
    return render_template('system_admin/account/reset_token.html',
                           title='Reset Password',
                           form=form)
Esempio n. 4
0
def settings():
    devi_id_number = Device_ID.query.first().id_number
    # Grab settings from site
    try:
        payload = requests.get(service_ip + '/device/get_settings/' +
                               devi_id_number)
    except:
        flash("Unable to Connect to Server!", "danger")
        return redirect(url_for('error.register'))

    # Check if registered
    if not payload.json()["registered"]:
        return redirect(url_for('register.home'))

    setting = payload.json()

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

        pl_send["toggle_pay"] = form.toggle_pay.data
        pl_send["price"] = form.price.data
        minutes = form.charge_time_min.data
        seconds = form.charge_time_sec.data
        pl_send["charge_time"] = minutes * 60 + seconds
        pl_send["time_offset"] = form.time_zone.data
        pl_send["location"] = form.location.data
        pl_send["aspect_ratio_width"] = float(
            form.aspect_ratio.data.split(":")[0])
        pl_send["aspect_ratio_height"] = float(
            form.aspect_ratio.data.split(":")[1])

        try:
            response = requests.put(service_ip + '/device/update_setting/' +
                                    devi_id_number + '/' + admin_key.get_key(),
                                    json=pl_send)
        except:
            flash("Unable to Connect to Server!", "danger")
            return redirect(url_for('error.register'))

        # 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('system_admin_account.login'))

        if response.status_code == 204 or response.status_code == 200:
            flash('Settings have been updated!', 'success')
        elif response.status_code == 400:
            flash('There was an error and settings were not updated', 'danger')
        else:
            flash('Something happened and settings were not updated.',
                  'danger')

        return redirect(url_for('system_admin_settings.settings'))
    elif request.method == 'GET':
        form.toggle_pay.data = setting["toggle_pay"]
        form.price.data = setting["price"]
        minutes, seconds = get_min_sec(seconds=setting["charge_time"])
        form.charge_time_min.data = minutes
        form.charge_time_sec.data = seconds
        form.time_zone.data = setting["time_offset"]
        form.location.data = setting["location"]
        form.aspect_ratio.data = str( int(setting["aspect_ratio_width"]) if (setting["aspect_ratio_width"]).is_integer() else setting["aspect_ratio_width"] ) \
               + ":" + str( int(setting["aspect_ratio_height"]) if (setting["aspect_ratio_height"]).is_integer() else setting["aspect_ratio_height"] )

    return render_template('system_admin/settings/settings.html',
                           title='Settings',
                           form=form)
Esempio n. 5
0
def remove_image():
	devi_id_number = Device_ID.query.first().id_number

	form = RemovePictureForm()
	if form.validate_on_submit():
		try:
			response = requests.delete(service_ip + '/device/remove_images/' + devi_id_number + '/' + form.removals.data + '/' + admin_key.get_key())
		except:
			flash("Unable to Connect to Server!", "danger")
			return redirect(url_for('error.register'))

		# 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('system_admin_account.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 the number of images the service has
	try:
		payload = requests.get(service_ip + '/device/img_count/' + devi_id_number)
	except:
		flash("Unable to Connect to Server!", "danger")
		return redirect(url_for('error.register'))

	pl_json = payload.json()

	# Check if registered
	if not pl_json["registered"]:
		return redirect(url_for('register.home')) 

	img_count = pl_json["image_count"]

	random_hex = secrets.token_hex(8)


	return render_template("system_admin/slide_show/remove_image.html", 
							title="Remove Images", 
							form=form,
							service_ip=service_ip,
							devi_id_number=devi_id_number,
							img_count=img_count,
							random_hex=random_hex)
Esempio n. 6
0
def upload_image():
	devi_id_number = Device_ID.query.first().id_number

	# Validate must be done first to allow the change of images before grabbing them again
	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 + '/device/images/upload/' + devi_id_number  + '/' + admin_key.get_key(), files=image_files)
		except:
			flash("Unable to Connect to Server!", "danger")
			return redirect(url_for('error.register'))

		# 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('system_admin_account.login'))

		flash('Pictures has been uploaded', 'success')
		return redirect(url_for('system_admin_slide_show.upload_image'))
	
	# Grab the number of images the service has
	try:
		payload = requests.get(service_ip + '/device/img_count/' + devi_id_number)
	except:
		flash("Unable to Connect to Server!", "danger")
		return redirect(url_for('error.register'))

	pl_json = payload.json()

	# Check if registered
	if not pl_json["registered"]:
		return redirect(url_for('register.home')) 

	img_count = pl_json["image_count"]

	random_hex = secrets.token_hex(8)

	return render_template("system_admin/slide_show/upload_image.html", 
							title="Upload Image", 
							form=form,
							service_ip=service_ip,
							devi_id_number=devi_id_number,
							img_count=img_count,
							random_hex=random_hex)
Esempio n. 7
0
def graph_all_years():
	# Sessions come with these variable:
	# {id, duration, power_used, amount_paid, date_initiated, location, port, increment_size, increments}
	# variable that have numerical values that only work with graph are:
	# {id, duration, power_used, amount_paid, date_initiated, increment_size, increments}
	

	devi_id_number = Device_ID.query.first().id_number

	# Grab the sessions
	try:
		payload = requests.get(service_ip + '/device/all_sessions/' + devi_id_number + '/' + admin_key.get_key())
	except:
		flash("Unable to Connect to Server!", "danger")
		return redirect(url_for('error.register'))

	# 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('system_admin_account.login'))

	pl_json = payload.json()

	# Check if registered
	if not pl_json["registered"]:
		return redirect(url_for('register.home'))

	# Get the sessions
	sess_list = pl_json["sessions"]
	settings = pl_json["settings"]

	# Delete old pic files
	remove_png()

	# This is what will be used for the bar graph
	date_strings = get_offset_dates_initiated(sessions=sess_list,
									time_offset=settings["time_offset"])

	# For every year, count how many sessions occured
	# Returns a dictionary
	years = count_years(dates=date_strings)

	create_bar_years(years=years)
	
	# Create the pic file to show
	pic_name = save_figure()

	return render_template("system_admin/data/graph_data_all_years.html", title="Years", pic_name=pic_name)
Esempio n. 8
0
def graph_day():
	form = DayForm()
	if form.validate_on_submit():

		devi_id_number = Device_ID.query.first().id_number

		# Grab the sessions
		try:
			payload = requests.get(service_ip + '/device/all_sessions/' + devi_id_number + '/' + admin_key.get_key())
		except:
			flash("Unable to Connect to Server!", "danger")
			return redirect(url_for('error.register'))
		
		# 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('system_admin_account.login'))

		pl_json = payload.json()

		# Check if registered
		if not pl_json["registered"]:
			return redirect(url_for('register.home'))

		# Get the sessions
		sess_list = pl_json["sessions"]
		settings = pl_json["settings"]

		# Delete old pic files
		remove_png()

		# This is what will be used for the bar graph
		date_strings = get_offset_dates_initiated(sessions=sess_list,
									time_offset=settings["time_offset"])


		# fix form.day.data (ex from 4 to 04)
		if int(form.day.data) < 10:
			form.day.data = '0' + str(int(form.day.data))

		# For every hour in a given day of a given month of a given year, count the sessions
		# Returns a dictionary
		hours = count_hours(dates=date_strings, day=form.day.data, month=form.month.data, year=form.year.data)

		create_bar_hours(hours=hours, day=form.day.data, month=form.month.data, year=form.year.data)

		# Create the pic file to show
		pic_name = save_figure()

		return render_template("system_admin/data/graph_data_day.html", title="Day", form=form, pic_name=pic_name)

	return render_template("system_admin/data/graph_data_day.html", title="Day", form=form)
Esempio n. 9
0
def view_data():

	devi_id_number = Device_ID.query.first().id_number

	page = request.args.get('page', 1, type=int)

	try:
		payload = requests.get(service_ip + '/device/sessions/' + devi_id_number + '/' + str(page) + '/' + admin_key.get_key())
	except:
		flash("Unable to Connect to Server!", "danger")
		return redirect(url_for('error.register'))

	# 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('system_admin_account.login'))

	pl_json = payload.json()

	# Check if registered
	if not pl_json["registered"]:
		return redirect(url_for('register.home'))

	sess_list = pl_json["sessions"]
	iter_pages = pl_json["iter_pages"]
	settings = pl_json["settings"]

	date_strings = get_offset_dates_initiated(sessions=sess_list,
									time_offset=settings["time_offset"])

	sessions_and_dates = zip(sess_list, date_strings) # Pack them together to iterate simultaniously
	return render_template("system_admin/data/list_data.html", title="List Data", iter_pages=iter_pages, 
							page=page, sessions_and_dates=sessions_and_dates)