Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -63,16 +63,18 @@ def register():
|
|
63 |
password = st.text_input("Password", type="password")
|
64 |
if st.button("Register"):
|
65 |
if username and email and password:
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
76 |
else:
|
77 |
st.error("Please fill all fields.")
|
78 |
|
@@ -82,12 +84,13 @@ def login():
|
|
82 |
username = st.text_input("Username")
|
83 |
password = st.text_input("Password", type="password")
|
84 |
if st.button("Login"):
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
91 |
|
92 |
# Dashboard Page
|
93 |
def dashboard():
|
@@ -97,8 +100,10 @@ def dashboard():
|
|
97 |
|
98 |
st.title("Dashboard")
|
99 |
user_id = st.session_state['user_id']
|
100 |
-
|
101 |
-
|
|
|
|
|
102 |
|
103 |
st.header("Your Issues")
|
104 |
for issue in user_issues:
|
@@ -126,9 +131,10 @@ def create_issue():
|
|
126 |
title = st.text_input("Issue Title")
|
127 |
description = st.text_area("Issue Description")
|
128 |
if st.button("Create Issue"):
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
132 |
st.success("Issue created successfully!")
|
133 |
|
134 |
# Invite Collaborators Page
|
@@ -141,21 +147,22 @@ def invite_collaborators():
|
|
141 |
issue_id = st.number_input("Issue ID", min_value=1, step=1)
|
142 |
emails = st.text_input("Collaborator Emails (comma-separated)")
|
143 |
if st.button("Send Invites"):
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
email
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
159 |
|
160 |
# Submit Solution Page
|
161 |
def submit_solution(issue_id):
|
@@ -166,15 +173,18 @@ def submit_solution(issue_id):
|
|
166 |
st.title(f"Submit Solution for Issue {issue_id}")
|
167 |
solution_content = st.text_area("Your Solution")
|
168 |
if st.button("Submit Solution"):
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
172 |
st.success("Solution submitted successfully!")
|
173 |
|
174 |
# Decide Page
|
175 |
def decide(issue_id):
|
176 |
-
|
177 |
-
|
|
|
|
|
178 |
if issue:
|
179 |
st.title(f"Decide on Issue: {issue.title}")
|
180 |
for solution in solutions:
|
@@ -198,7 +208,7 @@ def decide(issue_id):
|
|
198 |
decision = response.choices[0].message['content'].strip()
|
199 |
st.write(f"AI Decision: {decision}")
|
200 |
|
201 |
-
|
202 |
if 'user_id' not in st.session_state:
|
203 |
st.session_state['user_id'] = None
|
204 |
|
|
|
63 |
password = st.text_input("Password", type="password")
|
64 |
if st.button("Register"):
|
65 |
if username and email and password:
|
66 |
+
with app.app_context():
|
67 |
+
hashed_pw = bcrypt.generate_password_hash(password).decode('utf-8')
|
68 |
+
new_user = User(username=username, email=email, password=hashed_pw)
|
69 |
+
db.session.add(new_user)
|
70 |
+
db.session.commit()
|
71 |
+
|
72 |
+
st.success("Registration successful! Please check your email for further instructions.")
|
73 |
+
|
74 |
+
# Send registration email
|
75 |
+
msg = Message('Welcome to Sociocracy App', sender='your_email@example.com', recipients=[email])
|
76 |
+
msg.body = "Thank you for registering. You can now log in and start collaborating."
|
77 |
+
mail.send(msg)
|
78 |
else:
|
79 |
st.error("Please fill all fields.")
|
80 |
|
|
|
84 |
username = st.text_input("Username")
|
85 |
password = st.text_input("Password", type="password")
|
86 |
if st.button("Login"):
|
87 |
+
with app.app_context():
|
88 |
+
user = User.query.filter_by(username=username).first()
|
89 |
+
if user and bcrypt.check_password_hash(user.password, password):
|
90 |
+
st.session_state['user_id'] = user.id
|
91 |
+
st.success("Login successful!")
|
92 |
+
else:
|
93 |
+
st.error("Invalid username or password.")
|
94 |
|
95 |
# Dashboard Page
|
96 |
def dashboard():
|
|
|
100 |
|
101 |
st.title("Dashboard")
|
102 |
user_id = st.session_state['user_id']
|
103 |
+
|
104 |
+
with app.app_context():
|
105 |
+
user_issues = Issue.query.filter_by(created_by=user_id).all()
|
106 |
+
collaboration_issues = Issue.query.join(Collaborator).filter(Collaborator.user_id == user_id).all()
|
107 |
|
108 |
st.header("Your Issues")
|
109 |
for issue in user_issues:
|
|
|
131 |
title = st.text_input("Issue Title")
|
132 |
description = st.text_area("Issue Description")
|
133 |
if st.button("Create Issue"):
|
134 |
+
with app.app_context():
|
135 |
+
new_issue = Issue(title=title, description=description, created_by=st.session_state['user_id'])
|
136 |
+
db.session.add(new_issue)
|
137 |
+
db.session.commit()
|
138 |
st.success("Issue created successfully!")
|
139 |
|
140 |
# Invite Collaborators Page
|
|
|
147 |
issue_id = st.number_input("Issue ID", min_value=1, step=1)
|
148 |
emails = st.text_input("Collaborator Emails (comma-separated)")
|
149 |
if st.button("Send Invites"):
|
150 |
+
with app.app_context():
|
151 |
+
issue = Issue.query.get(issue_id)
|
152 |
+
if issue:
|
153 |
+
for email in emails.split(','):
|
154 |
+
email = email.strip()
|
155 |
+
user = User.query.filter_by(email=email).first()
|
156 |
+
if user:
|
157 |
+
new_collaborator = Collaborator(issue_id=issue_id, user_id=user.id)
|
158 |
+
db.session.add(new_collaborator)
|
159 |
+
msg = Message('Collaboration Invite', sender='[email protected]', recipients=[email])
|
160 |
+
msg.body = f"You have been invited to collaborate on the issue: {issue.title}."
|
161 |
+
mail.send(msg)
|
162 |
+
db.session.commit()
|
163 |
+
st.success("Invitations sent successfully!")
|
164 |
+
else:
|
165 |
+
st.error("Issue not found.")
|
166 |
|
167 |
# Submit Solution Page
|
168 |
def submit_solution(issue_id):
|
|
|
173 |
st.title(f"Submit Solution for Issue {issue_id}")
|
174 |
solution_content = st.text_area("Your Solution")
|
175 |
if st.button("Submit Solution"):
|
176 |
+
with app.app_context():
|
177 |
+
new_solution = Solution(content=solution_content, issue_id=issue_id, created_by=st.session_state['user_id'])
|
178 |
+
db.session.add(new_solution)
|
179 |
+
db.session.commit()
|
180 |
st.success("Solution submitted successfully!")
|
181 |
|
182 |
# Decide Page
|
183 |
def decide(issue_id):
|
184 |
+
with app.app_context():
|
185 |
+
issue = Issue.query.get(issue_id)
|
186 |
+
solutions = Solution.query.filter_by(issue_id=issue_id).all()
|
187 |
+
|
188 |
if issue:
|
189 |
st.title(f"Decide on Issue: {issue.title}")
|
190 |
for solution in solutions:
|
|
|
208 |
decision = response.choices[0].message['content'].strip()
|
209 |
st.write(f"AI Decision: {decision}")
|
210 |
|
211 |
+
### Main Flow
|
212 |
if 'user_id' not in st.session_state:
|
213 |
st.session_state['user_id'] = None
|
214 |
|