Spaces:
Runtime error
Runtime error
Update app/routes.py
Browse files- app/routes.py +51 -35
app/routes.py
CHANGED
|
@@ -7,6 +7,7 @@ from .utils import rank_resumes_by_similarity
|
|
| 7 |
import requests
|
| 8 |
from werkzeug.utils import secure_filename
|
| 9 |
from .ranker import rank_resumes_by_semantic_similarity
|
|
|
|
| 10 |
|
| 11 |
auth = Blueprint('auth', __name__)
|
| 12 |
|
|
@@ -49,31 +50,39 @@ def rank_resumes():
|
|
| 49 |
@auth.route('/register', methods=['GET', 'POST'])
|
| 50 |
def register():
|
| 51 |
if request.method == 'POST':
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
|
| 66 |
-
# Send verification email
|
| 67 |
-
if send_verification_email(email, username, new_user.verification_token):
|
| 68 |
-
flash('Registration successful! Please check your email to verify your account.')
|
| 69 |
-
else:
|
| 70 |
-
flash('Registration succeeded, but failed to send verification email.')
|
| 71 |
new_user.generate_api_key()
|
| 72 |
db.session.commit()
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
return render_template('register.html')
|
| 76 |
|
|
|
|
| 77 |
@auth.route('/login', methods=['GET', 'POST'])
|
| 78 |
def login():
|
| 79 |
if request.method == 'POST':
|
|
@@ -96,30 +105,37 @@ def login():
|
|
| 96 |
|
| 97 |
return render_template('login.html')
|
| 98 |
|
|
|
|
| 99 |
@auth.route('/resend-verification', methods=['GET', 'POST'])
|
| 100 |
def resend_verification():
|
| 101 |
if request.method == 'POST':
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
if user
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
else:
|
| 115 |
-
flash('
|
| 116 |
-
else:
|
| 117 |
-
flash('No account found with that email.')
|
| 118 |
|
| 119 |
-
|
| 120 |
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
| 122 |
|
|
|
|
| 123 |
|
| 124 |
@auth.route('/dashboard')
|
| 125 |
def dashboard():
|
|
|
|
| 7 |
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 |
|
|
|
|
| 50 |
@auth.route('/register', methods=['GET', 'POST'])
|
| 51 |
def register():
|
| 52 |
if request.method == 'POST':
|
| 53 |
+
try:
|
| 54 |
+
username = request.form['username']
|
| 55 |
+
email = request.form['email']
|
| 56 |
+
password = request.form['password']
|
| 57 |
+
|
| 58 |
+
if User.query.filter_by(email=email).first():
|
| 59 |
+
flash('Email already registered.')
|
| 60 |
+
return redirect(url_for('auth.register'))
|
| 61 |
+
|
| 62 |
+
new_user = User(username=username, email=email)
|
| 63 |
+
new_user.set_password(password)
|
| 64 |
+
new_user.generate_verification_token()
|
| 65 |
+
db.session.add(new_user)
|
| 66 |
+
db.session.commit()
|
| 67 |
|
| 68 |
+
# Send verification email
|
| 69 |
+
if send_verification_email(email, username, new_user.verification_token):
|
| 70 |
+
flash('Registration successful! Please check your email to verify your account.')
|
| 71 |
+
else:
|
| 72 |
+
flash('Registration succeeded, but failed to send verification email.')
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
new_user.generate_api_key()
|
| 75 |
db.session.commit()
|
| 76 |
+
return redirect(url_for('auth.login'))
|
| 77 |
+
|
| 78 |
+
except Exception as e:
|
| 79 |
+
print("🔥 Registration error:", e)
|
| 80 |
+
traceback.print_exc() # This prints full error to Hugging Face logs
|
| 81 |
+
return "Internal Server Error", 500
|
| 82 |
|
| 83 |
return render_template('register.html')
|
| 84 |
|
| 85 |
+
|
| 86 |
@auth.route('/login', methods=['GET', 'POST'])
|
| 87 |
def login():
|
| 88 |
if request.method == 'POST':
|
|
|
|
| 105 |
|
| 106 |
return render_template('login.html')
|
| 107 |
|
| 108 |
+
|
| 109 |
@auth.route('/resend-verification', methods=['GET', 'POST'])
|
| 110 |
def resend_verification():
|
| 111 |
if request.method == 'POST':
|
| 112 |
+
try:
|
| 113 |
+
email = request.form['email']
|
| 114 |
+
user = User.query.filter_by(email=email).first()
|
| 115 |
+
|
| 116 |
+
if user:
|
| 117 |
+
if user.is_verified:
|
| 118 |
+
flash('Your email is already verified. You can log in.')
|
| 119 |
+
return redirect(url_for('auth.login'))
|
| 120 |
+
|
| 121 |
+
user.generate_verification_token()
|
| 122 |
+
db.session.commit()
|
| 123 |
+
|
| 124 |
+
if send_verification_email(user.email, user.username, user.verification_token):
|
| 125 |
+
flash('Verification email resent. Please check your inbox.')
|
| 126 |
+
else:
|
| 127 |
+
flash('Failed to send verification email. Try again later.')
|
| 128 |
else:
|
| 129 |
+
flash('No account found with that email.')
|
|
|
|
|
|
|
| 130 |
|
| 131 |
+
return redirect(url_for('auth.login'))
|
| 132 |
|
| 133 |
+
except Exception as e:
|
| 134 |
+
print("🔥 Resend error:", e)
|
| 135 |
+
traceback.print_exc()
|
| 136 |
+
return "Internal Server Error", 500
|
| 137 |
|
| 138 |
+
return render_template('resend_verification.html')
|
| 139 |
|
| 140 |
@auth.route('/dashboard')
|
| 141 |
def dashboard():
|