Spaces:
Runtime error
Runtime error
Update app/routes.py
Browse files- app/routes.py +15 -18
app/routes.py
CHANGED
|
@@ -80,7 +80,6 @@ def rank_resumes():
|
|
| 80 |
auth = Blueprint('auth', __name__)
|
| 81 |
|
| 82 |
|
| 83 |
-
auth = Blueprint('auth', __name__)
|
| 84 |
|
| 85 |
@auth.route('/register', methods=['GET', 'POST'])
|
| 86 |
def register():
|
|
@@ -89,33 +88,31 @@ def register():
|
|
| 89 |
email = request.form.get('email')
|
| 90 |
password = request.form.get('password')
|
| 91 |
|
| 92 |
-
|
| 93 |
token = str(uuid.uuid4())
|
| 94 |
|
| 95 |
-
# Supabase REST API Insert
|
| 96 |
-
supabase_url = os.getenv("SUPABASE_URL")
|
| 97 |
-
supabase_key = os.getenv("SUPABASE_API_KEY")
|
| 98 |
-
headers = {
|
| 99 |
-
"apikey": supabase_key,
|
| 100 |
-
"Authorization": f"Bearer {supabase_key}",
|
| 101 |
-
"Content-Type": "application/json"
|
| 102 |
-
}
|
| 103 |
payload = {
|
| 104 |
"username": username,
|
| 105 |
"email": email,
|
| 106 |
-
"password":
|
| 107 |
-
"email_token": token
|
|
|
|
| 108 |
}
|
| 109 |
|
| 110 |
-
response = requests.post(f"{
|
| 111 |
|
| 112 |
if response.status_code == 201:
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
return redirect(url_for('auth.login'))
|
| 116 |
else:
|
| 117 |
-
print("
|
| 118 |
-
flash('Failed to register. Try again.',
|
| 119 |
|
| 120 |
return render_template("register.html")
|
| 121 |
|
|
@@ -167,7 +164,7 @@ def resend_verification():
|
|
| 167 |
try:
|
| 168 |
email = request.form['email']
|
| 169 |
|
| 170 |
-
#
|
| 171 |
headers = {
|
| 172 |
"apikey": SUPABASE_API_KEY,
|
| 173 |
"Authorization": f"Bearer {SUPABASE_API_KEY}"
|
|
|
|
| 80 |
auth = Blueprint('auth', __name__)
|
| 81 |
|
| 82 |
|
|
|
|
| 83 |
|
| 84 |
@auth.route('/register', methods=['GET', 'POST'])
|
| 85 |
def register():
|
|
|
|
| 88 |
email = request.form.get('email')
|
| 89 |
password = request.form.get('password')
|
| 90 |
|
| 91 |
+
hashed_password = generate_password_hash(password)
|
| 92 |
token = str(uuid.uuid4())
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
payload = {
|
| 95 |
"username": username,
|
| 96 |
"email": email,
|
| 97 |
+
"password": hashed_password,
|
| 98 |
+
"email_token": token,
|
| 99 |
+
"is_verified": False
|
| 100 |
}
|
| 101 |
|
| 102 |
+
response = requests.post(f"{SUPABASE_URL}/rest/v1/users", json=payload, headers=HEADERS)
|
| 103 |
|
| 104 |
if response.status_code == 201:
|
| 105 |
+
try:
|
| 106 |
+
send_verification_email(email, username, token)
|
| 107 |
+
flash('Account created. Check your email to verify.', 'success')
|
| 108 |
+
except Exception as e:
|
| 109 |
+
print("Email sending failed:", e)
|
| 110 |
+
flash('Registered, but email failed to send.', 'warning')
|
| 111 |
+
|
| 112 |
return redirect(url_for('auth.login'))
|
| 113 |
else:
|
| 114 |
+
print("Supabase error:", response.text)
|
| 115 |
+
flash('Failed to register. Try again.', 'error')
|
| 116 |
|
| 117 |
return render_template("register.html")
|
| 118 |
|
|
|
|
| 164 |
try:
|
| 165 |
email = request.form['email']
|
| 166 |
|
| 167 |
+
# Fetch user by email
|
| 168 |
headers = {
|
| 169 |
"apikey": SUPABASE_API_KEY,
|
| 170 |
"Authorization": f"Bearer {SUPABASE_API_KEY}"
|