webcodelab commited on
Commit
c3149c5
·
verified ·
1 Parent(s): 8055220

Update app/routes.py

Browse files
Files changed (1) hide show
  1. app/routes.py +40 -19
app/routes.py CHANGED
@@ -10,6 +10,8 @@ from .ranker import rank_resumes_by_semantic_similarity
10
  import traceback
11
  from werkzeug.security import generate_password_hash, check_password_hash
12
  from .supabase_client import get_user_by_email, create_user
 
 
13
 
14
 
15
  auth = Blueprint('auth', __name__)
@@ -53,29 +55,48 @@ def rank_resumes():
53
 
54
 
55
 
 
 
 
56
  auth = Blueprint('auth', __name__)
57
 
58
  @auth.route('/register', methods=['GET', 'POST'])
59
  def register():
60
  if request.method == 'POST':
61
- email = request.form['email']
62
- password = request.form['password']
63
-
64
- existing_user = get_user_by_email(email)
65
- if existing_user:
66
- flash('Email already registered.', category='error')
67
- return redirect(url_for('auth.register'))
68
-
69
- password_hash = generate_password_hash(password, method='sha256')
70
- response = create_user(email, password_hash)
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  if response.status_code == 201:
73
- send_verification_email(email)
74
- flash('Account created successfully. Please check your email.', category='success')
75
  return redirect(url_for('auth.login'))
76
  else:
77
- flash('Failed to register user.', category='error')
78
- return render_template('register.html')
 
 
 
79
 
80
 
81
  @auth.route('/login', methods=['GET', 'POST'])
@@ -119,7 +140,7 @@ def resend_verification():
119
  if result is True:
120
  flash('Verification email resent. Please check your inbox.')
121
  else:
122
- print("📧 Email error from resend:", result)
123
  return jsonify(result), 500 # Shows JSON error in browser
124
  else:
125
  flash('No account found with that email.')
@@ -127,7 +148,7 @@ def resend_verification():
127
  return redirect(url_for('auth.login'))
128
 
129
  except Exception as e:
130
- print("🔥 Resend error:", e)
131
  traceback.print_exc()
132
  return jsonify({"error": str(e)}), 500
133
 
@@ -210,7 +231,7 @@ def try_api():
210
  return render_template('docs.html', response=" Invalid API key.")
211
 
212
  try:
213
- # ✅ Use the actual ranking logic
214
  results = rank_resumes_by_semantic_similarity(resumes, job_description)
215
 
216
  return render_template(
@@ -229,7 +250,7 @@ def ping_db():
229
  try:
230
  # Try to count users in the database
231
  count = User.query.count()
232
- return f"✅ Connected to DB. Users count: {count}"
233
  except Exception as e:
234
- return f"❌ DB Error: {e}"
235
 
 
10
  import traceback
11
  from werkzeug.security import generate_password_hash, check_password_hash
12
  from .supabase_client import get_user_by_email, create_user
13
+ import os
14
+ import uuid
15
 
16
 
17
  auth = Blueprint('auth', __name__)
 
55
 
56
 
57
 
58
+ auth = Blueprint('auth', __name__)
59
+
60
+
61
  auth = Blueprint('auth', __name__)
62
 
63
  @auth.route('/register', methods=['GET', 'POST'])
64
  def register():
65
  if request.method == 'POST':
66
+ username = request.form.get('username')
67
+ email = request.form.get('email')
68
+ password = request.form.get('password')
69
+
70
+ # Generate a simple UUID token (you can use JWT instead if needed)
71
+ token = str(uuid.uuid4())
72
+
73
+ # Supabase REST API Insert
74
+ supabase_url = os.getenv("SUPABASE_URL")
75
+ supabase_key = os.getenv("SUPABASE_API_KEY")
76
+ headers = {
77
+ "apikey": supabase_key,
78
+ "Authorization": f"Bearer {supabase_key}",
79
+ "Content-Type": "application/json"
80
+ }
81
+ payload = {
82
+ "username": username,
83
+ "email": email,
84
+ "password": password,
85
+ "email_token": token
86
+ }
87
+
88
+ response = requests.post(f"{supabase_url}/rest/v1/users", json=payload, headers=headers)
89
 
90
  if response.status_code == 201:
91
+ send_verification_email(email, username, token)
92
+ flash('Account created. Check your email to verify.', category='success')
93
  return redirect(url_for('auth.login'))
94
  else:
95
+ print(" Supabase error:", response.text)
96
+ flash('Failed to register. Try again.', category='error')
97
+
98
+ return render_template("register.html")
99
+
100
 
101
 
102
  @auth.route('/login', methods=['GET', 'POST'])
 
140
  if result is True:
141
  flash('Verification email resent. Please check your inbox.')
142
  else:
143
+ print(" Email error from resend:", result)
144
  return jsonify(result), 500 # Shows JSON error in browser
145
  else:
146
  flash('No account found with that email.')
 
148
  return redirect(url_for('auth.login'))
149
 
150
  except Exception as e:
151
+ print(" Resend error:", e)
152
  traceback.print_exc()
153
  return jsonify({"error": str(e)}), 500
154
 
 
231
  return render_template('docs.html', response=" Invalid API key.")
232
 
233
  try:
234
+ # Use the actual ranking logic
235
  results = rank_resumes_by_semantic_similarity(resumes, job_description)
236
 
237
  return render_template(
 
250
  try:
251
  # Try to count users in the database
252
  count = User.query.count()
253
+ return f" Connected to DB. Users count: {count}"
254
  except Exception as e:
255
+ return f" DB Error: {e}"
256