first commit

This commit is contained in:
2025-09-17 08:36:17 +03:00
commit c2613de507
22 changed files with 1287 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

11
client/pages/auth/auth.py Normal file
View File

@@ -0,0 +1,11 @@
import flet as ft
from pages.auth.login import Login
class Auth:
def __init__(self, page: ft.Page):
self.page = page
self.login = Login(self.page, self)
self.placeholder = ft.Container(content=self.login.build())
def build(self):
return self.placeholder

View File

@@ -0,0 +1,41 @@
import flet as ft
class ForgotPassword:
def __init__(self, page: ft.Page, auth, login):
self.page = page
self.auth = auth
self.login = login
self.email = ft.TextField(label="E-mail")
self.code = ft.TextField(label="Code")
self.password = ft.TextField(
label="Password",
password=True,
can_reveal_password=True
)
self.confirm_password = ft.TextField(
label="Confirm Password",
password=True,
can_reveal_password=True
)
self.error = ft.Text(color=ft.Colors.RED)
def on_login_btn_click(self, e):
self.auth.placeholder.content.clean()
self.auth.placeholder.content = self.login.build()
self.auth.placeholder.update()
def build(self):
return ft.Container(
ft.Column(
[
ft.Text("Forgot Password?"),
self.email,
ft.Button("Recover"),
self.error,
ft.TextButton("Back to Login", on_click=self.on_login_btn_click)
],
spacing=20,
horizontal_alignment=ft.CrossAxisAlignment.CENTER
),
width=400,
)

View File

@@ -0,0 +1,76 @@
import flet as ft
from pages.auth.register import Register
from pages.auth.forgot_password import ForgotPassword
from models.users import Users
import hashlib
class Login:
def __init__(self, page: ft.Page, auth) -> None:
self.page = page
self.auth = auth
self.email = ft.TextField(label="E-mail")
self.password = ft.TextField(
label="Password",
password=True,
can_reveal_password=True
)
self.error = ft.Text(color=ft.Colors.RED)
def on_login_btn_click(self, e):
email = self.email.value
password = self.password.value
users = Users()
user = users.get_user_by_email(email)
if user['password'] == hashlib.md5(password.encode('utf-8')).hexdigest():
self.page.client_storage.set("is_authenticated", True)
self.page.client_storage.set('user_id', user['id'])
self.page.go('/')
else:
self.error.value = "Invalid credentials!"
self.error.update()
def on_register_btn_click(self, e):
register = Register(self.page, self.auth, self)
self.auth.placeholder.content.clean()
self.auth.placeholder.content = register.build()
self.auth.placeholder.update()
def on_forgot_password_btn_click(self, e):
forgot_password = ForgotPassword(self.page, self.auth, self)
self.auth.placeholder.content.clean()
self.auth.placeholder.content = forgot_password.build()
self.auth.placeholder.update()
def build(self):
return ft.Container(
ft.Column(
[
self.email,
self.password,
self.error,
ft.Button(
"Login",
width=150,
on_click=self.on_login_btn_click
),
ft.Row(
[
ft.TextButton(
"Register",
on_click=self.on_register_btn_click
),
ft.TextButton(
"Forgot Password",
on_click=self.on_forgot_password_btn_click
)
],
expand=True,
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
),
],
spacing=20,
horizontal_alignment=ft.CrossAxisAlignment.CENTER
),
width=400,
)

View File

@@ -0,0 +1,120 @@
import flet as ft
import time
import re
import hashlib
from models.users import Users
from pages.auth.forgot_password import ForgotPassword
class Register:
def __init__(self, page: ft.Page, auth, login) -> None:
self.page = page
self.auth = auth
self.login = login
self.email = ft.TextField(label="E-mail")
self.password = ft.TextField(
label="Password",
password=True,
can_reveal_password=True
)
self.confirm_password = ft.TextField(
label="Confirm Password",
password=True,
can_reveal_password=True
)
self.error = ft.Text(color=ft.Colors.RED)
def on_login_btn_click(self, e):
self.auth.placeholder.content.clean()
self.auth.placeholder.content = self.login.build()
self.auth.placeholder.update()
def on_register_btn_click(self, e):
if not self.verify_email():
self.error.value = "Please insert a valid email address!"
self.error.update()
return
if not self.verify_password():
self.error.value = "Please a stronger password!"
self.error.update()
return
if not self.verify_confirm_password():
self.error.value = "Password and confirm password do not match!"
self.error.update()
return
if not self.register_user():
self.error.value = "Email already registred!"
self.error.update()
return
self.error.value = "User registered, you can now login!"
self.error.color = ft.Colors.GREEN
self.error.update()
time.sleep(3)
self.auth.placeholder.content.clean()
self.auth.placeholder.content = self.login.build()
self.auth.placeholder.update()
def on_forgot_password_btn_click(self, e):
forgot_password = ForgotPassword(self.page, self.auth, self.login)
self.auth.placeholder.content.clean()
self.auth.placeholder.content = forgot_password.build()
self.auth.placeholder.update()
def verify_email(self):
email = self.email.value
if not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$", email):
return False
return True
def verify_password(self):
passwd = self.password.value
if len(passwd) >= 8 and re.search(r"\d", passwd) and re.search(r"[A-Z]", passwd):
return True
return False
def verify_confirm_password(self):
return True if self.password.value == self.confirm_password.value else False
def register_user(self):
email = self.email.value
password = self.password.value
users = Users()
if users.get_user_by_email(email) is not None:
return False
passwd_hash = hashlib.md5(password.encode('utf-8')).hexdigest()
users.insert_user(email, passwd_hash)
return True
def build(self):
return ft.Container(
ft.Column(
[
self.email,
self.password,
self.confirm_password,
self.error,
ft.Button(
"Register",
width=150,
on_click=self.on_register_btn_click
),
ft.Row(
[
ft.TextButton(
"Login",
on_click=self.on_login_btn_click
),
ft.TextButton(
"Forgot Password",
on_click=self.on_forgot_password_btn_click
)
],
expand=True,
alignment=ft.MainAxisAlignment.SPACE_BETWEEN
),
],
spacing=20,
horizontal_alignment=ft.CrossAxisAlignment.CENTER
),
width=400,
)