add main blueprint

This commit is contained in:
Daniel afx 2022-02-04 22:43:04 +02:00
parent acf3a42fb2
commit 32d3c297d1
4 changed files with 93 additions and 4 deletions

View file

@ -19,16 +19,13 @@ from flask_mail import Mail
from flask_login import LoginManager
from flask_wtf.csrf import CSRFProtect, CSRFError
from flask_moment import Moment
#from flask_httpauth import import import HTTPBasicAuth
from werkzeug.contrib.fixers import ProxyFix
from config import config
sys.stderr.write("worker uid={} gid={}".format(os.getuid(), os.getgid()))
sys.stderr.flush()
app = Flask(__name__)
app.config.from_object("forest.config.Config")
db = SQLAlchemy(app)
#db = SQLAlchemy(session_options = { "autoflush": False })
db.init_app(app)
@ -70,6 +67,7 @@ app.register_blueprint(admin_blueprint, url_prefix='/' + app.config['ADMIN_PREFI
from .settings import settings as settings_blueprint
app.register_blueprint(settings_blueprint, url_prefix='/settings')
class CustomJSONEncoder(JSONEncoder):
"""This class adds support for lazy translation texts to Flask's
JSON encoder. This is necessary when flashing translated texts."""

View file

@ -0,0 +1,3 @@
from flask import Blueprint
main = Blueprint('main', __name__)
from . import routes

View file

@ -0,0 +1,26 @@
from flask_wtf import FlaskForm, RecaptchaField
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
from wtforms import validators, ValidationError
from wtforms.fields.html5 import EmailField
from ..models import User
class LoginForm(FlaskForm):
email = EmailField('', [validators.DataRequired(), validators.Length(1,64), validators.Email()], render_kw={"placeholder": "username"})
password = PasswordField('', [validators.DataRequired(), validators.Length(1,128)], render_kw={"placeholder": "password"})
remember_me = BooleanField('Remember?', render_kw={"placeholder": "remember"})
#recaptcha = RecaptchaField()
submit = SubmitField('Login', render_kw={"placeholder": "submit"})
class RegistrationForm(FlaskForm):
email = StringField('E-Mail', [validators.DataRequired(), validators.Length(6,35), validators.Email()])
def validate_email(self, field):
if User.query.filter_by(email=field.data).first():
raise ValidationError('Error. Please try again.')
password = PasswordField('Password', [validators.DataRequired(), validators.EqualTo('confirm', message='Both passwords must be equal')])
confirm = PasswordField('Your password again', [validators.DataRequired()])
accept_tos = BooleanField('I accept the <a href="/terms">Terms of Service</a>', [validators.DataRequired()])
recaptcha = RecaptchaField()
submit = SubmitField('REGISTER')

View file

@ -0,0 +1,62 @@
from flask import render_template, abort, redirect, url_for, abort, flash, request, current_app, make_response, g
from flask_login import login_required, login_user, logout_user, current_user
from flask_sqlalchemy import get_debug_queries
from . import main
from .forms import LoginForm, RegistrationForm
from .. import db
from ..email import send_email
from ..models import User, Permission, Server, Deployment, Service, Region, Address, Domain, contact_proxmaster
import base64
@main.after_app_request
def after_request(response):
for query in get_debug_queries():
if query.duration >= current_app.config['SLOW_DB_QUERY_TIME']:
current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
return response
#STATIC PAGES
@main.route("/", methods=['GET'])
def index():
form = LoginForm()
allservers = Server.query.filter_by(enabled=True)
return render_template('main/index.html', servers=allservers, form=form)
@main.route("/chat", methods=['GET'])
def chat():
return render_template('main/livechat.html')
#@main.route("/aboutus", methods=['GET'])
#def about():
# return render_template('main/aboutus.html')
@main.route('/domaincheck', methods=['GET'])
def domaincheck():
return render_template('main/domaincheck.html')
@main.route("/terms", methods=['GET'])
def terms():
return render_template('main/terms.html')
#APP STORE
@main.route('/market/<int:group_id>', methods=['GET'])
@login_required
def market(group_id=0):
page = { 'title': 'Market' }
allproducts = Product.get_products()
allgroups = current_app.config['GROUPS']
if group_id == 0:
return render_template('main/market.html', groups=allgroups, products=allproducts)
filtered_products = {}
for key, value in allproducts.items():
if value['group'] == group_id:
filtered_products[key] = value
if filtered_products == {}:
abort(404)
return render_template('main/marketgroup.html', groupname=allgroups[group_id], products=filtered_products)