feat: UI registration
This commit is contained in:
parent
7bb4ac17df
commit
e2c4bf6563
|
@ -1,8 +1,10 @@
|
|||
import re
|
||||
|
||||
import flet as ft
|
||||
from flet.core.page import RouteChangeEvent
|
||||
|
||||
from requests.board_games import get_sections, get_games
|
||||
from requests.auth import login as login_req
|
||||
from requests.auth import login as login_req, registration
|
||||
|
||||
|
||||
def root(page: ft.Page):
|
||||
|
@ -144,6 +146,7 @@ def login(page):
|
|||
# Back button handler
|
||||
def back_clicked(e):
|
||||
page.go("/")
|
||||
page.update()
|
||||
|
||||
# Email input field
|
||||
email_input = ft.TextField(
|
||||
|
@ -183,7 +186,66 @@ def login(page):
|
|||
|
||||
|
||||
def register(page):
|
||||
page.add(ft.Text("owo"))
|
||||
page.horizontal_alignment=ft.CrossAxisAlignment.CENTER
|
||||
|
||||
|
||||
def back_clicked(e):
|
||||
page.go("/")
|
||||
page.update()
|
||||
|
||||
# Поля для ввода данных
|
||||
first_name_input = ft.TextField(label="Имя", hint_text="Введите ваше имя")
|
||||
last_name_input = ft.TextField(label="Фамилия", hint_text="Введите вашу фамилию")
|
||||
middle_name_input = ft.TextField(label="Отчество", hint_text="Введите ваше отчество (опционально)")
|
||||
age_input = ft.TextField(label="Возраст", hint_text="Введите ваш возраст", keyboard_type=ft.KeyboardType.NUMBER)
|
||||
phone_input = ft.TextField(label="Телефон", hint_text="Введите ваш телефон", keyboard_type=ft.KeyboardType.PHONE)
|
||||
email_input = ft.TextField(label="Электронная почта", hint_text="Введите вашу электронную почту",
|
||||
keyboard_type=ft.KeyboardType.EMAIL)
|
||||
password_input = ft.TextField(label="Пароль", hint_text="Введите ваш пароль", password=True,
|
||||
can_reveal_password=True)
|
||||
|
||||
# Обработчик кнопки регистрации
|
||||
def register_clicked(e):
|
||||
first_name = first_name_input.value.strip()
|
||||
last_name = last_name_input.value.strip()
|
||||
middle_name = middle_name_input.value.strip()
|
||||
age = int(age_input.value.strip())
|
||||
phone = phone_input.value.strip()
|
||||
email = email_input.value.strip()
|
||||
password = password_input.value
|
||||
|
||||
user_id = registration(first_name, last_name, middle_name, age, phone, email, password)
|
||||
|
||||
page.client_storage.set("user_id", user_id)
|
||||
|
||||
page.go("/")
|
||||
|
||||
# Кнопка для регистрации
|
||||
register_button = ft.ElevatedButton("Зарегистрироваться", on_click=register_clicked)
|
||||
|
||||
# Добавление элементов на страницу
|
||||
back_button = ft.TextButton("Назад", on_click=back_clicked)
|
||||
|
||||
page.add(
|
||||
ft.Column(
|
||||
[
|
||||
ft.Text("Регистрация", size=24, weight=ft.FontWeight.BOLD),
|
||||
first_name_input,
|
||||
last_name_input,
|
||||
middle_name_input,
|
||||
age_input,
|
||||
phone_input,
|
||||
email_input,
|
||||
password_input,
|
||||
register_button,
|
||||
back_button
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.START,
|
||||
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
|
||||
spacing=10,
|
||||
width=600
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def profile(page):
|
||||
|
|
|
@ -2,7 +2,7 @@ from requests.connection import get_cursor
|
|||
|
||||
|
||||
def login(email, password):
|
||||
cursor = get_cursor()
|
||||
cursor = get_cursor()[0]
|
||||
|
||||
cursor.execute(f"select * from clients join auth using(client_id) where email='{email}' and password='{password}'")
|
||||
|
||||
|
@ -12,3 +12,19 @@ def login(email, password):
|
|||
return None
|
||||
else:
|
||||
return res[0]
|
||||
|
||||
def registration(first_name, last_name, middle_name, age, phone, email, password):
|
||||
(cursor, conn) = get_cursor()
|
||||
cursor.execute(f"""
|
||||
insert into clients (forename, surname, patronymic, age, phone_number, email)
|
||||
values ('{first_name}', '{last_name}', '{middle_name}', {age}, '{phone}', '{email}');
|
||||
""")
|
||||
conn.commit()
|
||||
cursor.execute(f"select (client_id) from clients where email='{email}'")
|
||||
user_id = cursor.fetchone()[0]
|
||||
cursor.execute(f"""
|
||||
insert into auth (client_id, password)
|
||||
values ('{user_id}', '{password}');
|
||||
""")
|
||||
conn.commit()
|
||||
return user_id
|
||||
|
|
|
@ -5,7 +5,7 @@ from requests.connection import get_cursor
|
|||
|
||||
|
||||
def get_sections():
|
||||
cursor = get_cursor()
|
||||
cursor = get_cursor()[0]
|
||||
|
||||
cursor.execute("select name from sections")
|
||||
|
||||
|
@ -13,7 +13,7 @@ def get_sections():
|
|||
|
||||
|
||||
def get_games(section = None):
|
||||
cursor = get_cursor()
|
||||
cursor = get_cursor()[0]
|
||||
|
||||
cursor.execute("SET lc_monetary TO 'ru_RU.UTF-8'")
|
||||
|
||||
|
|
|
@ -8,4 +8,4 @@ def get_cursor():
|
|||
if connection is None:
|
||||
connection = psycopg2.connect(database="postgres", user="postgres", password="not_admin", host="serafimdev.com", port=6000)
|
||||
|
||||
return connection.cursor()
|
||||
return (connection.cursor(), connection)
|
||||
|
|
Loading…
Reference in New Issue