Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,88 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import
|
4 |
-
from git import Repo
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
return project_dir
|
23 |
|
24 |
-
def
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
return
|
32 |
|
|
|
33 |
def main():
|
34 |
-
st.title("
|
35 |
-
st.write("Upload your project files or clone a GitHub repository.")
|
36 |
|
37 |
-
#
|
38 |
-
|
39 |
-
"Choose an option:",
|
40 |
-
("Upload Files", "Clone GitHub Repository")
|
41 |
-
)
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
st.success(f"Repository cloned to {repo_path}")
|
61 |
-
except Exception as e:
|
62 |
-
st.error(f"Error cloning repository: {e}")
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
main()
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import sqlite3
|
3 |
+
import hashlib
|
|
|
4 |
|
5 |
+
# Database setup
|
6 |
+
DB_FILE = "users.db"
|
7 |
|
8 |
+
def create_user_table():
|
9 |
+
conn = sqlite3.connect(DB_FILE)
|
10 |
+
cursor = conn.cursor()
|
11 |
+
cursor.execute("""
|
12 |
+
CREATE TABLE IF NOT EXISTS users (
|
13 |
+
username TEXT PRIMARY KEY,
|
14 |
+
password TEXT
|
15 |
+
)
|
16 |
+
""")
|
17 |
+
conn.commit()
|
18 |
+
conn.close()
|
19 |
|
20 |
+
def add_user(username, password):
|
21 |
+
conn = sqlite3.connect(DB_FILE)
|
22 |
+
cursor = conn.cursor()
|
23 |
+
hashed_password = hashlib.sha256(password.encode()).hexdigest()
|
24 |
+
try:
|
25 |
+
cursor.execute("INSERT INTO users (username, password) VALUES (?, ?)", (username, hashed_password))
|
26 |
+
conn.commit()
|
27 |
+
except sqlite3.IntegrityError:
|
28 |
+
st.error("Username already exists. Please choose a different username.")
|
29 |
+
conn.close()
|
|
|
30 |
|
31 |
+
def authenticate_user(username, password):
|
32 |
+
conn = sqlite3.connect(DB_FILE)
|
33 |
+
cursor = conn.cursor()
|
34 |
+
hashed_password = hashlib.sha256(password.encode()).hexdigest()
|
35 |
+
cursor.execute("SELECT * FROM users WHERE username = ? AND password = ?", (username, hashed_password))
|
36 |
+
user = cursor.fetchone()
|
37 |
+
conn.close()
|
38 |
+
return user
|
39 |
|
40 |
+
# Main application
|
41 |
def main():
|
42 |
+
st.title("Welcome to Your Streamlit App")
|
|
|
43 |
|
44 |
+
# Initialize database
|
45 |
+
create_user_table()
|
|
|
|
|
|
|
46 |
|
47 |
+
# Authentication state
|
48 |
+
if "authenticated" not in st.session_state:
|
49 |
+
st.session_state.authenticated = False
|
50 |
+
|
51 |
+
# Central login/register interface
|
52 |
+
if not st.session_state.authenticated:
|
53 |
+
st.subheader("Please Log In or Register to Continue")
|
54 |
+
auth_mode = st.radio("Choose an Option", ["Log In", "Register"], horizontal=True)
|
55 |
+
|
56 |
+
if auth_mode == "Log In":
|
57 |
+
st.subheader("Log In")
|
58 |
+
username = st.text_input("Username", key="login_username")
|
59 |
+
password = st.text_input("Password", type="password", key="login_password")
|
60 |
|
61 |
+
if st.button("Log In"):
|
62 |
+
if authenticate_user(username, password):
|
63 |
+
st.success(f"Welcome back, {username}!")
|
64 |
+
st.session_state.authenticated = True
|
65 |
+
st.session_state.username = username
|
66 |
+
else:
|
67 |
+
st.error("Invalid username or password. Please try again.")
|
|
|
|
|
|
|
68 |
|
69 |
+
elif auth_mode == "Register":
|
70 |
+
st.subheader("Register")
|
71 |
+
username = st.text_input("Create Username", key="register_username")
|
72 |
+
password = st.text_input("Create Password", type="password", key="register_password")
|
73 |
+
|
74 |
+
if st.button("Register"):
|
75 |
+
if username and password:
|
76 |
+
add_user(username, password)
|
77 |
+
st.success("Account created successfully! You can now log in.")
|
78 |
+
else:
|
79 |
+
st.error("Please fill in all fields.")
|
80 |
+
|
81 |
+
# Authenticated user workspace
|
82 |
+
if st.session_state.authenticated:
|
83 |
+
st.subheader(f"Hello, {st.session_state.username}!")
|
84 |
+
st.write("This is your workspace. All your saved work will appear here.")
|
85 |
|
86 |
if __name__ == "__main__":
|
87 |
main()
|
88 |
+
|