-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
123 lines (99 loc) · 3.49 KB
/
app.py
File metadata and controls
123 lines (99 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import streamlit as st
import sqlite3
import hashlib
DB_NAME = "users.db" # Tüm fonksiyonlarda aynı veritabanı dosyası kullanılacak
def hash_password(password):
return hashlib.sha256(password.encode()).hexdigest()
def create_usertable():
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
c.execute('''
CREATE TABLE IF NOT EXISTS users (
email TEXT NOT NULL UNIQUE,
username TEXT NOT NULL,
password TEXT NOT NULL,
birthdate TEXT
)
''')
conn.commit()
conn.close()
def add_user(email, username, password, birthdate):
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
try:
c.execute('''
INSERT INTO users (email, username, password, birthdate)
VALUES (?, ?, ?, ?)
''', (email, username, hash_password(password), birthdate))
conn.commit()
except sqlite3.IntegrityError:
st.error("User with this email already exists.")
finally:
conn.close()
def login_user(email, password):
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
c.execute('SELECT * FROM users WHERE email = ? AND password = ?', (email, hash_password(password)))
user = c.fetchone()
conn.close()
return user is not None
if "page" not in st.session_state:
st.session_state.page = "home"
def go_to(page_name):
st.session_state.page = page_name
st.rerun()
if st.session_state.page == "home":
st.title("Hoş Geldiniz!")
st.write("Lütfen giriş yapın veya kayıt olun.")
if st.button("Giriş Yap"):
go_to("login")
if st.button("Kayıt Ol"):
go_to("register")
elif st.session_state.page == "login":
st.title("Giriş Yap")
email = st.text_input("Email")
password = st.text_input("Şifre", type="password")
if st.button("Giriş Yap"):
if login_user(email, password):
st.session_state.giris = True
st.session_state.kullanici = email
st.success("Giriş başarılı!")
go_to("app")
else:
st.write("Giriş başarısız! Lütfen bilgilerinizi kontrol edin.")
st.error("Giriş başarısız!")
st.rerun()
elif st.session_state.page == "register":
st.title("Kayıt Ol")
email = st.text_input("Email")
username = st.text_input("Kullanıcı Adı")
password = st.text_input("Şifre", type="password")
birthdate = st.date_input("Doğum Tarihi")
if st.button("Kayıt Ol"):
birthdate_str = birthdate.strftime("%Y-%m-%d")
add_user(email, username, password, birthdate_str)
st.success("Kayıt başarılı! Giriş yapabilirsiniz.")
if st.button("Giriş Sayfasına Dön"):
go_to("login")
if st.session_state.page == "app":
st.title("İstediğiniz Çiçeği Seçin")
# Çiçekler ve fiyatları
cicekler = {
"Gül": 150,
"Şakayık": 200,
"Lale": 100,
"Orkide": 250,
"Kaktüs": 80,
"Sukulent": 90,
"Sardunya": 120,
"Menekşe": 110
}
# Kullanıcıya sadece çiçek isimlerini göster
ciceksecim = st.selectbox("Çiçek Seç", list(cicekler.keys()))
# Seçilen çiçeğin fiyatını sözlükten çek
fiyat = cicekler[ciceksecim]
st.write(f"Seçtiğiniz çiçeğin fiyatı: {fiyat} TL")
st.write("Ödeme işlemini tamamlamak için aşağıdaki butona tıklayın.")
if st.button("Ödeme Yap"):
st.success("Ödeme başarılı! Teşekkür ederiz.")
go_to("home")