Spaces:
Runtime error
Runtime error
Update app/routes.py
Browse files- app/routes.py +21 -30
app/routes.py
CHANGED
|
@@ -8,6 +8,9 @@ import requests
|
|
| 8 |
from werkzeug.utils import secure_filename
|
| 9 |
from .ranker import rank_resumes_by_semantic_similarity
|
| 10 |
import traceback
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
auth = Blueprint('auth', __name__)
|
| 13 |
|
|
@@ -21,6 +24,8 @@ def embed():
|
|
| 21 |
text = data.get("text", "")
|
| 22 |
return jsonify({"embedding": [0.1, 0.2, 0.3]}) # Dummy
|
| 23 |
|
|
|
|
|
|
|
| 24 |
@auth.route('/rank-resumes', methods=['POST'])
|
| 25 |
def rank_resumes():
|
| 26 |
auth_header = request.headers.get('Authorization')
|
|
@@ -47,43 +52,29 @@ def rank_resumes():
|
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
@auth.route('/register', methods=['GET', 'POST'])
|
| 53 |
def register():
|
| 54 |
if request.method == 'POST':
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
email = request.form['email']
|
| 58 |
-
password = request.form['password']
|
| 59 |
-
|
| 60 |
-
if User.query.filter_by(email=email).first():
|
| 61 |
-
flash('Email already registered.')
|
| 62 |
-
return redirect(url_for('auth.register'))
|
| 63 |
-
|
| 64 |
-
new_user = User(username=username, email=email)
|
| 65 |
-
new_user.set_password(password)
|
| 66 |
-
new_user.generate_verification_token()
|
| 67 |
-
db.session.add(new_user)
|
| 68 |
-
db.session.commit()
|
| 69 |
-
|
| 70 |
-
# Send verification email
|
| 71 |
-
result = send_verification_email(email, username, new_user.verification_token)
|
| 72 |
-
if result is True:
|
| 73 |
-
flash('Registration successful! Please check your email to verify your account.')
|
| 74 |
-
else:
|
| 75 |
-
print("📧 Email error from send_verification_email:", result)
|
| 76 |
-
return jsonify(result), 500 # Shows JSON error in browser
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
traceback.print_exc()
|
| 85 |
-
return jsonify({"error": str(e)}), 500
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
return render_template('register.html')
|
| 88 |
|
| 89 |
|
|
|
|
| 8 |
from werkzeug.utils import secure_filename
|
| 9 |
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__)
|
| 16 |
|
|
|
|
| 24 |
text = data.get("text", "")
|
| 25 |
return jsonify({"embedding": [0.1, 0.2, 0.3]}) # Dummy
|
| 26 |
|
| 27 |
+
|
| 28 |
+
|
| 29 |
@auth.route('/rank-resumes', methods=['POST'])
|
| 30 |
def rank_resumes():
|
| 31 |
auth_header = request.headers.get('Authorization')
|
|
|
|
| 52 |
|
| 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 |
|