2023-02-16 18:19:58 +04:00
|
|
|
"""Admin routes"""
|
|
|
|
|
|
|
|
from flask import request, redirect
|
|
|
|
from flask import render_template
|
|
|
|
|
|
|
|
from . import routes
|
|
|
|
from . import forms
|
|
|
|
from . import db
|
|
|
|
|
|
|
|
|
|
|
|
class RouteAdmin(routes.Routes):
|
|
|
|
"""Admin endpoints: GET and POST /add"""
|
|
|
|
|
|
|
|
def add_routes(self) -> None:
|
|
|
|
"""Add admin routes"""
|
|
|
|
|
|
|
|
@self.app.route('/add', methods=['GET', 'POST'])
|
|
|
|
def add_person():
|
|
|
|
|
|
|
|
form = forms.AddForm()
|
|
|
|
|
|
|
|
if request.method == 'GET':
|
|
|
|
return render_template(
|
|
|
|
'admin.html',
|
|
|
|
form=form,
|
|
|
|
)
|
|
|
|
|
|
|
|
if form.pswd.data != '1234':
|
|
|
|
return 'Incorrect password', 403
|
|
|
|
|
|
|
|
cur = db.get_cursor()
|
|
|
|
cur.execute(
|
2023-02-16 18:25:40 +04:00
|
|
|
f'insert into {db.TABLE} '
|
2023-02-16 18:19:58 +04:00
|
|
|
'(email,name,age) values (%s,%s,%s)',
|
|
|
|
(
|
|
|
|
form.email.data,
|
|
|
|
form.name.data,
|
|
|
|
form.age.data,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
cur.close()
|
|
|
|
|
|
|
|
return redirect('/db')
|