Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines56789101126 unmodified lines38394041424344453 unmodified lines495051525354555657585950 unmodified lines1101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461474 unmodified lines1521531541551561571581591601611621631641651663 unmodified lines17017117217317417521 unmodified lines1971981992002012022032042052062072082092102112122132142152162172182197 unmodified lines22722822923023123223331 unmodified lines2652662672682692702714 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, # ✅ أمان: عداد المحاولات"contact": "","submitted": False,"user_profile": {},3 unmodified linesst.session_state[key] = default# ✅ دالة تشفير الكود — لا يُخزّن الكود كنص عادي أبداًdef hash_code(code):return hashlib.sha256(code.encode()).hexdigest()# ==========================================# دالة جلب ومطابقة الوظائف من Firestore# ==========================================50 unmodified linesif not st.session_state.otp_sent:if st.button("إرسال كود التحقق"):if contact:# أمان: تنظيف المدخلاتcontact_clean = contact.strip()[:100]st.session_state.contact = contact_cleancode = str(random.randint(1000, 9999))# أمان: نخزّن الكود مشفراً فقط، لا يظهر للمستخدمst.session_state.otp_code = hash_code(code)st.session_state.otp_attempts = 0st.session_state.otp_sent = True# في الإنتاج: أرسل الكود عبر SMS/Email# للاختبار فقط: احذف السطر التالي قبل النشر الحقيقيst.info(f" تم إرسال كود التحقق إلى: {contact_clean} (للاختبار: **{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 = Falsest.session_state.otp_code = Nonest.session_state.otp_attempts = 0st.rerun()returnotp_input = st.text_input("أدخل كود التحقق")if st.button("تأكيد الكود والمتابعة"):# أمان: نقارن الكود المشفّر فقطif otp_input and hash_code(otp_input.strip()) == st.session_state.otp_code:try:db.collection("users").add({"contact": st.session_state.contact,4 unmodified linesst.session_state.account_created = Truest.rerun()else:# أمان: نزيد عداد المحاولات الخاطئةst.session_state.otp_attempts += 1remaining = 5 - st.session_state.otp_attemptsst.error(f"الكود غير صحيح. تبقى لك {remaining} محاولات.")if st.button("تغيير رقم الجوال / البريد"):st.session_state.otp_sent = Falsest.session_state.otp_code = Nonest.session_state.otp_attempts = 0st.rerun()3 unmodified linesdef show_questions_page():st.markdown("<h2 style='text-align: center;'>إكمال معلومات التقديم</h2>", unsafe_allow_html=True)st.session_state.category_choice = st.radio("الحالة",["خريج", "عامل"],21 unmodified linesjob_title = ""location = st.text_input("الموقع (السكن)")st.write(" سيتم توصيلك بأقرب فرص العمل المتوفرة لموقعك.")if st.form_submit_button("إرسال التقديم"):if not name or not location:st.warning("رجاءً أكمل جميع الحقول المطلوبة")else:# أمان: تنظيف المدخلات قبل الحفظprofile = {"name": name.strip()[:100],"gender": gender,"age": int(age),"job_status": st.session_state.category_choice,"location": location.strip()[:200],"major": major,"work_type": work_type,"edu": edu,"job_title": job_title.strip()[:100],}try:db.collection("applications").add({**profile, "date": datetime.now()})7 unmodified linesst.session_state.account_created = Falsest.session_state.otp_sent = Falsest.session_state.otp_code = Nonest.session_state.otp_attempts = 0st.rerun()31 unmodified linesst.session_state.account_created = Falsest.session_state.otp_sent = Falsest.session_state.otp_code = Nonest.session_state.otp_attempts = 0st.session_state.contact = ""st.session_state.submitted = Falsest.session_state.user_profile = {}4 unmodified lines567891026 unmodified lines373839404142433 unmodified lines47484950515250 unmodified lines1031041051061071081091101111121131141151161171181191201211221231244 unmodified lines1291301311321331341351361371381393 unmodified lines14314414514614714814921 unmodified lines1711721731741751761771781791801811821831841851861871881891901911927 unmodified lines20020120220320420531 unmodified lines2372382392402412424 unmodified linesimport osimport jsonimport random# 1. إعداد الواجهةst.set_page_config(page_title="تطبيق فرصة عمل", layout="centered")26 unmodified linesfor key, default in {"account_created": False,"otp_sent": False,"otp_code": None,"contact": "","submitted": False,"user_profile": {},3 unmodified linesst.session_state[key] = default# ==========================================# دالة جلب ومطابقة الوظائف من Firestore# ==========================================50 unmodified linesif not st.session_state.otp_sent:if st.button("إرسال كود التحقق"):if contact:st.session_state.contact = contactcode = str(random.randint(1000, 9999))st.session_state.otp_code = codest.session_state.otp_sent = Truest.info(f" تم إرسال كود التحقق (للاختبار: **{code}**)")st.rerun()else:st.warning("رجاءً أدخل البريد الإلكتروني أو رقم الجوال")else:st.info(f" تم إرسال كود التحقق إلى: {st.session_state.contact}")st.caption(f"(للاختبار، الكود هو: {st.session_state.otp_code})")otp_input = st.text_input("أدخل كود التحقق")if st.button("تأكيد الكود والمتابعة"):if otp_input == st.session_state.otp_code:try:db.collection("users").add({"contact": st.session_state.contact,4 unmodified linesst.session_state.account_created = Truest.rerun()else:st.error("الكود غير صحيح، يرجى المحاولة مرة أخرى")if st.button("تغيير رقم الجوال / البريد"):st.session_state.otp_sent = Falsest.session_state.otp_code = Nonest.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 linesjob_title = ""location = st.text_input("الموقع (السكن)")st.write(" ..سيتم البحث عن فرصة عمل تناسبك")if st.form_submit_button("إرسال التقديم"):if not name or not location:st.warning("رجاءً أكمل جميع الحقول المطلوبة")else:profile = {"name": name,"gender": gender,"age": int(age),"job_status": st.session_state.category_choice,"location": location,"major": major,"work_type": work_type,"edu": edu,"job_title": job_title,}try:db.collection("applications").add({**profile, "date": datetime.now()})7 unmodified linesst.session_state.account_created = Falsest.session_state.otp_sent = Falsest.session_state.otp_code = Nonest.rerun()31 unmodified linesst.session_state.account_created = Falsest.session_state.otp_sent = Falsest.session_state.otp_code = Nonest.session_state.contact = ""st.session_state.submitted = Falsest.session_state.user_profile = {}
app.py+12-41