diff --git a/backend/app.py b/backend/app.py index f9b5c27..7838416 100644 --- a/backend/app.py +++ b/backend/app.py @@ -535,6 +535,45 @@ def index(): ) +@app.route('/signup') +def signup(): + """회원가입 페이지""" + if 'logged_in_user_id' in session: + return redirect(f"/my-page?phone={session.get('logged_in_phone', '')}") + return render_template('signup.html') + + +@app.route('/api/signup', methods=['POST']) +def api_signup(): + """회원가입 API""" + try: + data = request.get_json() + name = data.get('name', '').strip() + phone = data.get('phone', '').strip().replace('-', '').replace(' ', '') + + if not name or not phone: + return jsonify({'success': False, 'message': '이름과 전화번호를 모두 입력해주세요.'}), 400 + + if len(phone) < 10: + return jsonify({'success': False, 'message': '올바른 전화번호를 입력해주세요.'}), 400 + + user_id, is_new = get_or_create_user(phone, name) + + # 세션에 유저 정보 저장 + session.permanent = True + session['logged_in_user_id'] = user_id + session['logged_in_phone'] = phone + session['logged_in_name'] = name + + return jsonify({ + 'success': True, + 'message': '가입이 완료되었습니다.' if is_new else '이미 가입된 회원입니다. 로그인되었습니다.', + 'is_new': is_new + }) + except Exception as e: + return jsonify({'success': False, 'message': f'오류가 발생했습니다: {str(e)}'}), 500 + + @app.route('/claim') def claim(): """ diff --git a/backend/templates/index.html b/backend/templates/index.html index 0e3e9c0..94e9d00 100644 --- a/backend/templates/index.html +++ b/backend/templates/index.html @@ -340,6 +340,14 @@ + + + + +