broken profile settings

This commit is contained in:
Xevion
2019-07-11 23:03:47 -05:00
parent e7b05ee4f9
commit 4b2d3aab53
4 changed files with 40 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
from app import app, db, login from app import app, db, login
from app.forms import ProfileSettingsForm from app.forms import ProfileSettingsForm, ProfilePictureForm
from app.models import User, Search from app.models import User, Search
from app.custom import require_role from app.custom import require_role
from flask import render_template, redirect, url_for, request, jsonify from flask import render_template, redirect, url_for, request, jsonify
@@ -13,8 +13,9 @@ def dashboard():
@app.route('/dashboard/profile_settings', methods=['GET']) @app.route('/dashboard/profile_settings', methods=['GET'])
@login_required @login_required
def profile_settings(): def profile_settings():
form = ProfileSettingsForm() psform = ProfileSettingsForm()
return render_template('/dashboard/profile_settings.html', form=form) ppform = ProfilePictureForm()
return render_template('/dashboard/profile_settings.html', psform=psform, ppform=ppform)
@app.route('/dashboard/profile_settings/submit', methods=['POST']) @app.route('/dashboard/profile_settings/submit', methods=['POST'])
@login_required @login_required

View File

@@ -28,7 +28,6 @@ class RegistrationForm(FlaskForm):
class ProfileSettingsForm(FlaskForm): class ProfileSettingsForm(FlaskForm):
show_email = RadioField('Show Email', default='registered', choices=[('public', 'Public'), ('registered', 'Registered Users Only'), ('hidden', 'Hidden')]) show_email = RadioField('Show Email', default='registered', choices=[('public', 'Public'), ('registered', 'Registered Users Only'), ('hidden', 'Hidden')])
submit = SubmitField('Save Profile Settings') submit = SubmitField('Save Profile Settings')
class ProfilePictureForm(FlaskForm): class ProfilePictureForm(FlaskForm):

View File

@@ -6,6 +6,7 @@ from werkzeug.urls import url_parse
from flask import render_template, redirect, url_for, flash, request, jsonify, abort, send_file from flask import render_template, redirect, url_for, flash, request, jsonify, abort, send_file
from flask_login import current_user, login_user, logout_user, login_required from flask_login import current_user, login_user, logout_user, login_required
from io import BytesIO from io import BytesIO
from textwrap import wrap
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
import requests import requests
import xmltodict import xmltodict
@@ -17,8 +18,7 @@ import json
fake = faker.Faker() fake = faker.Faker()
def strgen(length): strgen = lambda length, charset=string.ascii_letters, weights=None : ''.join(random.choices(list(charset), k=length, weights=weights))
return ''.join(random.choices(list(string.ascii_letters), k=length))
@app.errorhandler(401) @app.errorhandler(401)
def unauthorized(e): def unauthorized(e):
@@ -41,9 +41,18 @@ def create_panzer(string):
img = Image.open("./app/static/panzer.jpeg") img = Image.open("./app/static/panzer.jpeg")
draw = ImageDraw.Draw(img) draw = ImageDraw.Draw(img)
font1 = ImageFont.truetype('./app/static/arial.ttf', size=30) font1 = ImageFont.truetype('./app/static/arial.ttf', size=30)
font2 = ImageFont.truetype('./app/static/arial.ttf', size=30)
draw.text((10, 20), 'Oh panzer of the lake, what is your wisdom?', font=font1) draw.text((10, 20), 'Oh panzer of the lake, what is your wisdom?', font=font1)
draw.text((250, 500), string, font=font2)
font2 = ImageFont.truetype('./app/static/arial.ttf', size=30)
w, h = img.size
lines = wrap(string, width=400)
y_text = h
for line in lines:
width, height = font2.getsize(line)
draw.text(((w - width) / 2, y_text), line, font=font2)
y_text += height
# draw.text((250, 500), string, font=font2)
return img return img
@@ -57,6 +66,8 @@ def api():
return 'fuckoff bots' return 'fuckoff bots'
@app.route('/userinfo/') @app.route('/userinfo/')
@login_required
@require_role(roles=['Admin'])
def user_info(): def user_info():
prepare = { prepare = {
'id' : current_user.get_id(), 'id' : current_user.get_id(),
@@ -73,10 +84,14 @@ def user_info():
@app.route('/') @app.route('/')
def index(): def index():
content = [{'text': fake.paragraph(nb_sentences=15), # content = [{'text': fake.paragraph(nb_sentences=15),
# 'seed': random.randint(0, 1000),
# 'title': fake.word().title()}
# for _ in range(0)]
content = [{'title': 'Work in Progress',
'seed': random.randint(0, 1000), 'seed': random.randint(0, 1000),
'title': fake.word().title()} 'text': 'This portion of my website is still a work in progress. I don\'t know if and when it\'ll be done, or how it will turn out in the end. - Xevion @ (Jul-11-2019)'}
for _ in range(10)] for _ in range(1)]
return render_template('index.html', content=content) return render_template('index.html', content=content)
@app.route('/register/', methods=['GET', 'POST']) @app.route('/register/', methods=['GET', 'POST'])

View File

@@ -4,7 +4,7 @@
{{ super() }} {{ super() }}
<script> <script>
$(document).ready(function () { $(document).ready(function () {
$('#form-ajax').submit(function (e) { $('#psform-ajax').submit(function (e) {
var url = "{{ url_for('profile_settings_submit') }}"; // send the form data here. var url = "{{ url_for('profile_settings_submit') }}"; // send the form data here.
$.ajax({ $.ajax({
type: "POST", type: "POST",
@@ -20,7 +20,7 @@
$.ajaxSetup({ $.ajaxSetup({
beforeSend: function (xhr, settings) { beforeSend: function (xhr, settings) {
if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) { if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", "{{ form.csrf_token._value() }}") xhr.setRequestHeader("X-CSRFToken", "{{ psform.csrf_token._value() }}")
} }
} }
}) })
@@ -31,6 +31,11 @@
padding-left: 3rem; padding-left: 3rem;
} }
</style> </style>
<style type="text/css">
.tab-left {
padding-left: 3rem;
}
</style>
{% endblock head %} {% endblock head %}
{% block dashboard_body %} {% block dashboard_body %}
@@ -38,17 +43,17 @@
<h1 class="title">Profile Settings</h1> <h1 class="title">Profile Settings</h1>
<!-- Profile Email Settings Form --> <!-- Profile Email Settings Form -->
<form class="form-ajax" action="" method="POST" novalidate> <form class="form-ajax" action="" method="POST" novalidate>
{{ form.hidden_tag() }} {{ psform.hidden_tag() }}
<div class="field tab-left"> <div class="field tab-left">
<h4 class="title is-4">{{ form.show_email.label }}</h4> <h4 class="title is-4">{{ psform.show_email.label }}</h4>
{{ form.show_email(class="radio") }} {{ psform.show_email(class="radio") }}
</div> </div>
</form> </form>
<!-- Profile Picture Form --> <!-- Profile Picture Form -->
<form class="form-ajax" action="" method="POST" novalidate> <form class="form-ajax" action="" method="POST" novalidate>
{{ form.hidden_tag() }} {{ ppform.hidden_tag() }}
<h4 class="title is-4">{{ form.profile_picture_file.label }}</h4> <h4 class="title is-4">{{ ppform.profile_picture_file.label }}</h4>
{{ form.profile_picture_file(class="") }} {{ ppform.profile_picture_file(class="") }}
<div class="field tab-left"> <div class="field tab-left">
<div class="file"> <div class="file">
<label class="file-label"> <label class="file-label">
@@ -65,7 +70,7 @@
</div> </div>
</div> </div>
{{ form.submit(class="button is-danger") }} {{ ppform.submit(class="button is-danger") }}
</form> </form>
</section> </section>
{% endblock dashboard_body %} {% endblock dashboard_body %}