Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,43 +140,41 @@ elif st.session_state.user_type == "receiver":
|
|
| 140 |
st.session_state.user_type = None
|
| 141 |
st.session_state.username = ""
|
| 142 |
st.rerun()
|
| 143 |
-
import os
|
| 144 |
-
|
| 145 |
-
# زر لتحميل ملف قاعدة البيانات - يظهر دائمًا
|
| 146 |
-
if os.path.exists("complaints_system.db"):
|
| 147 |
-
with open("complaints_system.db", "rb") as db_file:
|
| 148 |
-
st.download_button(
|
| 149 |
-
label="📥 تحميل complaints_system.db",
|
| 150 |
-
data=db_file,
|
| 151 |
-
file_name="complaints_system.db",
|
| 152 |
-
mime="application/octet-stream"
|
| 153 |
-
)
|
| 154 |
-
else:
|
| 155 |
-
st.warning("⚠️ ملف قاعدة البيانات غير موجود في هذا المسار.")
|
| 156 |
-
# واجهة لإضافة مستخدمين جديدة - فقط للمشرف admin
|
| 157 |
if st.session_state.get("username") == "admin":
|
| 158 |
-
st.subheader("
|
| 159 |
|
| 160 |
-
|
| 161 |
-
new_password = st.text_input("🔑 كلمة المرور", type="password")
|
| 162 |
-
new_role = st.selectbox("🎭 الدور", ["sender", "receiver"])
|
| 163 |
|
| 164 |
-
if
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
# التحقق إذا المستخدم موجود مسبقًا
|
| 169 |
-
c.execute("SELECT * FROM users WHERE username=?", (new_username,))
|
| 170 |
-
if c.fetchone():
|
| 171 |
-
st.error("❌ اسم المستخدم موجود بالفعل.")
|
| 172 |
else:
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
|
|
|
|
|
|
| 180 |
|
|
|
|
|
|
|
| 181 |
|
| 182 |
|
|
|
|
| 140 |
st.session_state.user_type = None
|
| 141 |
st.session_state.username = ""
|
| 142 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
if st.session_state.get("username") == "admin":
|
| 144 |
+
st.subheader("📤 رفع ملف مستخدمين (Excel أو CSV)")
|
| 145 |
|
| 146 |
+
uploaded_file = st.file_uploader("اختر الملف", type=["csv", "xlsx"])
|
|
|
|
|
|
|
| 147 |
|
| 148 |
+
if uploaded_file is not None:
|
| 149 |
+
try:
|
| 150 |
+
if uploaded_file.name.endswith(".csv"):
|
| 151 |
+
df = pd.read_csv(uploaded_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
else:
|
| 153 |
+
df = pd.read_excel(uploaded_file)
|
| 154 |
+
|
| 155 |
+
st.write("📋 المعاينة:")
|
| 156 |
+
st.dataframe(df)
|
| 157 |
+
|
| 158 |
+
if st.button("✅ رفع المستخدمين"):
|
| 159 |
+
count_added = 0
|
| 160 |
+
for _, row in df.iterrows():
|
| 161 |
+
username = row["username"]
|
| 162 |
+
password = row["password"]
|
| 163 |
+
role = row["role"]
|
| 164 |
+
|
| 165 |
+
# التحقق من عدم وجود المستخدم
|
| 166 |
+
c.execute("SELECT * FROM users WHERE username=?", (username,))
|
| 167 |
+
if c.fetchone():
|
| 168 |
+
continue # تخطي المستخدم الموجود
|
| 169 |
+
hashed_pw = bcrypt.hash(str(password))
|
| 170 |
+
c.execute("INSERT INTO users (username, password, role) VALUES (?, ?, ?)",
|
| 171 |
+
(username, hashed_pw, role))
|
| 172 |
+
count_added += 1
|
| 173 |
|
| 174 |
+
conn.commit()
|
| 175 |
+
st.success(f"✅ تم إضافة {count_added} مستخدم جديد.")
|
| 176 |
|
| 177 |
+
except Exception as e:
|
| 178 |
+
st.error(f"❌ خطأ في قراءة الملف: {e}")
|
| 179 |
|
| 180 |
|