Spaces:
Sleeping
Sleeping
Update app.py
#1
by foy55 - opened
4 unmodified lines5678891026 unmodified lines3738394142404142433 unmodified lines474849525354555650515250 unmodified lines1031041051131141151061071171181191081091211221231101111121131141151291301311321331341351361371381161171181191201431441211221231244 unmodified lines1291301311551561571581321331341351361631371381393 unmodified lines14314414514614714814921 unmodified lines1711721732001741751761771781792061802081811821831842121851861871882161891901911927 unmodified lines20020120223020320420531 unmodified lines2372382392682402412424 unmodified linesimport osimport jsonimport randomimport hashlib # ✅ أمان: لتشفير الكود
# 1. إعداد الواجهةst.set_page_config(page_title="تطبيق فرصة عمل", layout="centered")26 unmodified linesfor key, default in { "account_created": False, "otp_sent": False, "otp_code": None, # ✅ سيُخزّن مشفراً الآن "otp_attempts": 0, # ✅ أمان: عداد المحاولات "otp_code": None, "contact": "", "submitted": False, "user_profile": {},3 unmodified lines st.session_state[key] = default
# ✅ دالة تشفير الكود — لا يُخزّن الكود كنص عادي أبداًdef hash_code(code): return hashlib.sha256(code.encode()).hexdigest()
# ==========================================# دالة جلب ومطابقة الوظائف من Firestore# ==========================================50 unmodified lines if not st.session_state.otp_sent: if st.button("إرسال كود التحقق"): if contact: # أمان: تنظيف المدخلات contact_clean = contact.strip()[:100] st.session_state.contact = contact_clean st.session_state.contact = contact code = str(random.randint(1000, 9999)) # أمان: نخزّن الكود مشفراً فقط، لا يظهر للمستخدم st.session_state.otp_code = hash_code(code) st.session_state.otp_attempts = 0 st.session_state.otp_code = code st.session_state.otp_sent = True # في الإنتاج: أرسل الكود عبر SMS/Email # للاختبار فقط: احذف السطر التالي قبل النشر الحقيقي st.info(f" تم إرسال كود التحقق إلى: {contact_clean} (للاختبار: **{code}**)") st.info(f" تم إرسال كود التحقق (للاختبار: **{code}**)") st.rerun() else: st.warning("رجاءً أدخل البريد الإلكتروني أو رقم الجوال") else: st.info(f" تم إرسال كود التحقق إلى: {st.session_state.contact}")
# أمان: منع أكثر من 5 محاولات if st.session_state.otp_attempts >= 5: st.error(" تجاوزت الحد المسموح من المحاولات. يرجى إعادة الإرسال.") if st.button("إعادة إرسال كود جديد"): st.session_state.otp_sent = False st.session_state.otp_code = None st.session_state.otp_attempts = 0 st.rerun() return st.caption(f"(للاختبار، الكود هو: {st.session_state.otp_code})")
otp_input = st.text_input("أدخل كود التحقق")
if st.button("تأكيد الكود والمتابعة"): # أمان: نقارن الكود المشفّر فقط if otp_input and hash_code(otp_input.strip()) == st.session_state.otp_code: if otp_input == st.session_state.otp_code: try: db.collection("users").add({ "contact": st.session_state.contact,4 unmodified lines st.session_state.account_created = True st.rerun() else: # أمان: نزيد عداد المحاولات الخاطئة st.session_state.otp_attempts += 1 remaining = 5 - st.session_state.otp_attempts st.error(f"الكود غير صحيح. تبقى لك {remaining} محاولات.") st.error("الكود غير صحيح، يرجى المحاولة مرة أخرى")
if st.button("تغيير رقم الجوال / البريد"): st.session_state.otp_sent = False st.session_state.otp_code = None st.session_state.otp_attempts = 0 st.rerun()
3 unmodified linesdef show_questions_page(): st.markdown("<h2 style='text-align: center;'>إكمال معلومات التقديم</h2>", unsafe_allow_html=True)
# الحل: radio وselectbox خارج الفورم حتى يتغير فوراً عند الاختيار st.session_state.category_choice = st.radio( "الحالة", ["خريج", "عامل"],21 unmodified lines job_title = ""
location = st.text_input("الموقع (السكن)") st.write(" سيتم توصيلك بأقرب فرص العمل المتوفرة لموقعك.") st.write(" ..سيتم البحث عن فرصة عمل تناسبك")
if st.form_submit_button("إرسال التقديم"): if not name or not location: st.warning("رجاءً أكمل جميع الحقول المطلوبة") else: # أمان: تنظيف المدخلات قبل الحفظ profile = { "name": name.strip()[:100], "name": name, "gender": gender, "age": int(age), "job_status": st.session_state.category_choice, "location": location.strip()[:200], "location": location, "major": major, "work_type": work_type, "edu": edu, "job_title": job_title.strip()[:100], "job_title": job_title, } try: db.collection("applications").add({**profile, "date": datetime.now()})7 unmodified lines st.session_state.account_created = False st.session_state.otp_sent = False st.session_state.otp_code = None st.session_state.otp_attempts = 0 st.rerun()
31 unmodified lines st.session_state.account_created = False st.session_state.otp_sent = False st.session_state.otp_code = None st.session_state.otp_attempts = 0 st.session_state.contact = "" st.session_state.submitted = False st.session_state.user_profile = {}app.py+12-41