diff --git a/A_core/__pycache__/settings.cpython-38.pyc b/A_core/__pycache__/settings.cpython-38.pyc
index fa057f3..79c2e8f 100644
Binary files a/A_core/__pycache__/settings.cpython-38.pyc and b/A_core/__pycache__/settings.cpython-38.pyc differ
diff --git a/A_core/__pycache__/telegram_utils.cpython-38.pyc b/A_core/__pycache__/telegram_utils.cpython-38.pyc
index 7adbbf6..a50912c 100644
Binary files a/A_core/__pycache__/telegram_utils.cpython-38.pyc and b/A_core/__pycache__/telegram_utils.cpython-38.pyc differ
diff --git a/A_core/telegram_utils.py b/A_core/telegram_utils.py
index 54bece8..8f8a7be 100644
--- a/A_core/telegram_utils.py
+++ b/A_core/telegram_utils.py
@@ -218,13 +218,14 @@ def send_signup_notification(name, phone, request):
send_telegram_message_async(message)
-def send_password_reset_notification(phone, request):
+def send_password_reset_notification(phone, request, user_exists=True):
"""
비밀번호 찾기 문자인증 요청 알림
Args:
phone (str): 전화번호
request: Django request 객체 (IP, User-Agent 정보)
+ user_exists (bool): 사용자가 등록되어 있는지 여부
"""
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
@@ -237,10 +238,21 @@ def send_password_reset_notification(phone, request):
# 디버그 정보 출력
print(f"[TELEGRAM_DEBUG] 비밀번호 찾기 알림 - IP: {ip}, 기기: {device_info}, 브라우저: {browser_info}")
+ # 사용자 존재 여부에 따른 메시지 구성
+ if user_exists:
+ status_icon = "✅"
+ status_text = "등록된 사용자"
+ action_text = "비밀번호 찾기 요청이 있습니다!"
+ else:
+ status_icon = "❌"
+ status_text = "미등록 사용자"
+ action_text = "등록되지 않은 전화번호로 비밀번호 찾기 시도!"
+
message = f"""
🔑 신라AMP 비밀번호 찾기 알림
📱 전화번호: {phone}
+{status_icon} 상태: {status_text}
⏰ 요청시간: {current_time}
🌐 접속 정보:
@@ -248,7 +260,7 @@ def send_password_reset_notification(phone, request):
• 기기: {device_info}
• 브라우저: {browser_info}
-💡 비밀번호 찾기 요청이 있습니다!
+💡 {action_text}
""".strip()
# 비동기로 전송 (사용자 대기시간 없음)
diff --git a/B_main/__pycache__/forms.cpython-38.pyc b/B_main/__pycache__/forms.cpython-38.pyc
index 9aa304e..0efde0a 100644
Binary files a/B_main/__pycache__/forms.cpython-38.pyc and b/B_main/__pycache__/forms.cpython-38.pyc differ
diff --git a/B_main/__pycache__/urls.cpython-38.pyc b/B_main/__pycache__/urls.cpython-38.pyc
index 35406aa..1d6b3d7 100644
Binary files a/B_main/__pycache__/urls.cpython-38.pyc and b/B_main/__pycache__/urls.cpython-38.pyc differ
diff --git a/B_main/__pycache__/views.cpython-38.pyc b/B_main/__pycache__/views.cpython-38.pyc
index dbd928a..0c89020 100644
Binary files a/B_main/__pycache__/views.cpython-38.pyc and b/B_main/__pycache__/views.cpython-38.pyc differ
diff --git a/C_accounts/__pycache__/views.cpython-38.pyc b/C_accounts/__pycache__/views.cpython-38.pyc
index 73fe511..5d65620 100644
Binary files a/C_accounts/__pycache__/views.cpython-38.pyc and b/C_accounts/__pycache__/views.cpython-38.pyc differ
diff --git a/C_accounts/views.py b/C_accounts/views.py
index 3f0c76e..019535c 100644
--- a/C_accounts/views.py
+++ b/C_accounts/views.py
@@ -197,8 +197,37 @@ def password_change(request):
# 모드1: 비밀번호 찾기 (로그인하지 않은 상태)
def password_reset(request):
"""비밀번호 찾기 뷰"""
- # 세션 초기화
- if 'password_reset_step' not in request.session:
+
+ # GET 요청 시 세션 상태에 따른 처리
+ if request.method == 'GET':
+ # 강제 리셋 파라미터 확인
+ force_reset = request.GET.get('reset', '').lower() == 'true'
+
+ current_step = request.session.get('password_reset_step', 1)
+ current_verified = request.session.get('password_reset_verified', False)
+
+ # 강제 리셋이거나, 2단계 인증된 상태가 아닌 경우 세션 초기화
+ if force_reset or not (current_step == 2 and current_verified):
+ # 기존 비밀번호 찾기 세션 모두 제거
+ for key in ['password_reset_step', 'password_reset_code', 'password_reset_phone',
+ 'password_reset_verified', 'password_reset_code_sent_at']:
+ request.session.pop(key, None)
+
+ # 새로운 세션 시작
+ request.session['password_reset_step'] = 1
+ request.session['password_reset_code'] = None
+ request.session['password_reset_phone'] = None
+ request.session['password_reset_verified'] = False
+
+ if force_reset:
+ print("[DEBUG] 비밀번호 찾기 세션 강제 초기화됨 (reset=true)")
+ else:
+ print("[DEBUG] 비밀번호 찾기 세션 초기화됨 (GET 요청)")
+ else:
+ print("[DEBUG] 비밀번호 찾기 2단계 인증된 상태 - 세션 유지")
+
+ # 세션 초기화 (POST 요청 시에도 세션이 없으면 초기화)
+ elif 'password_reset_step' not in request.session:
request.session['password_reset_step'] = 1
request.session['password_reset_code'] = None
request.session['password_reset_phone'] = None
@@ -219,7 +248,25 @@ def password_reset(request):
form1 = PasswordResetStep1Form(request.POST)
if form1.is_valid():
phone = form1.cleaned_data['phone']
- # 인증번호 생성 및 실제 SMS 발송
+
+ # 먼저 해당 전화번호로 가입된 사용자가 있는지 확인
+ try:
+ user = User.objects.get(username=phone)
+ print(f"[DEBUG] 비밀번호 찾기: 등록된 사용자 확인됨 - {phone}")
+ except User.DoesNotExist:
+ print(f"[DEBUG] 비밀번호 찾기: 등록되지 않은 전화번호 - {phone}")
+
+ # 미등록 사용자 시도에 대한 텔레그램 알림 전송
+ from A_core.telegram_utils import send_password_reset_notification
+ send_password_reset_notification(phone, request, user_exists=False)
+
+ error = '등록되지 않은 전화번호입니다. 회원가입을 먼저 진행해주세요.'
+ form1 = PasswordResetStep1Form(request.POST)
+ return render(request, 'C_accounts/password_reset.html', {
+ 'step': 1, 'form1': form1, 'code_sent': False, 'error': error, 'message': None
+ })
+
+ # 등록된 사용자인 경우에만 인증번호 생성 및 SMS 발송
verification_code = str(random.randint(100000, 999999))
# 실제 SMS 발송
@@ -234,9 +281,9 @@ def password_reset(request):
code_sent = True
print(f"[DEBUG] 비밀번호 찾기 SMS 발송 성공: {phone} - {verification_code}")
- # 텔레그램 알림 전송 (비동기)
+ # 텔레그램 알림 전송 (비동기) - 등록된 사용자
from A_core.telegram_utils import send_password_reset_notification
- send_password_reset_notification(phone, request)
+ send_password_reset_notification(phone, request, user_exists=True)
else:
error = '인증번호 발송에 실패했습니다. 잠시 후 다시 시도해주세요.'
print(f"[DEBUG] 비밀번호 찾기 SMS 발송 실패: {sms_result['error']}")
diff --git a/db.sqlite3 b/db.sqlite3
index c0ca4c7..f0798e5 100644
Binary files a/db.sqlite3 and b/db.sqlite3 differ