Kerikim commited on
Commit
c08f399
Β·
1 Parent(s): 55c067f

elkay frontend api and app signup

Browse files
Files changed (2) hide show
  1. app.py +13 -26
  2. utils/api.py +20 -5
app.py CHANGED
@@ -168,25 +168,18 @@ def main():
168
  st.stop()
169
 
170
  if DISABLE_DB:
171
- # Call your backend Space instead of touching the DB
172
  try:
173
- payload = {
174
- "role": "student",
175
- "name": name.strip(),
176
- "email": email.strip().lower(),
177
- "password": password,
178
- "country": country,
179
- "level": level,
180
- }
181
- r = requests.post(f"{BACKEND}/auth/register", json=payload, timeout=15)
182
- r.raise_for_status()
183
  st.success("βœ… Signup successful! Please go to the **Login** page to continue.")
184
  st.session_state.current_page = "Login"
185
  st.session_state.signup_role = None
186
  st.rerun()
187
- except requests.HTTPError as e:
188
- msg = e.response.text if hasattr(e, "response") and e.response is not None else str(e)
189
- st.error(f"❌ Signup failed: {msg}")
190
  except Exception as e:
191
  st.error(f"❌ Signup failed: {e}")
192
  else:
@@ -227,22 +220,16 @@ def main():
227
 
228
  if DISABLE_DB:
229
  try:
230
- payload = {
231
- "role": "teacher",
232
- "title": title.strip(),
233
- "name": name.strip(),
234
- "email": email.strip().lower(),
235
- "password": password,
236
- }
237
- r = requests.post(f"{BACKEND}/auth/register", json=payload, timeout=15)
238
- r.raise_for_status()
239
  st.success("βœ… Signup successful! Please go to the **Login** page to continue.")
240
  st.session_state.current_page = "Login"
241
  st.session_state.signup_role = None
242
  st.rerun()
243
- except requests.HTTPError as e:
244
- msg = e.response.text if hasattr(e, "response") and e.response is not None else str(e)
245
- st.error(f"❌ Signup failed: {msg}")
246
  except Exception as e:
247
  st.error(f"❌ Signup failed: {e}")
248
  else:
 
168
  st.stop()
169
 
170
  if DISABLE_DB:
 
171
  try:
172
+ api.signup_student(
173
+ name=name.strip(),
174
+ email=email.strip().lower(),
175
+ password=password,
176
+ level_label=level, # <-- keep these names
177
+ country_label=country,
178
+ )
 
 
 
179
  st.success("βœ… Signup successful! Please go to the **Login** page to continue.")
180
  st.session_state.current_page = "Login"
181
  st.session_state.signup_role = None
182
  st.rerun()
 
 
 
183
  except Exception as e:
184
  st.error(f"❌ Signup failed: {e}")
185
  else:
 
220
 
221
  if DISABLE_DB:
222
  try:
223
+ api.signup_teacher(
224
+ title=title.strip(),
225
+ name=name.strip(),
226
+ email=email.strip().lower(),
227
+ password=password,
228
+ )
 
 
 
229
  st.success("βœ… Signup successful! Please go to the **Login** page to continue.")
230
  st.session_state.current_page = "Login"
231
  st.session_state.signup_role = None
232
  st.rerun()
 
 
 
233
  except Exception as e:
234
  st.error(f"❌ Signup failed: {e}")
235
  else:
utils/api.py CHANGED
@@ -3,6 +3,7 @@ import os, json, requests
3
  from urllib3.util.retry import Retry
4
  from requests.adapters import HTTPAdapter
5
 
 
6
  # ---- Setup ----
7
  BACKEND = (os.getenv("BACKEND_URL") or "").strip().rstrip("/")
8
  if not BACKEND:
@@ -373,13 +374,27 @@ def login(email: str, password: str):
373
  return _json_or_raise(_req("POST", "/auth/login", json={"email": email, "password": password}))
374
 
375
  def signup_student(name: str, email: str, password: str, level_label: str, country_label: str):
376
- return _json_or_raise(_req("POST", "/auth/signup/student",
377
- json={"name": name, "email": email, "password": password,
378
- "level_label": level_label, "country_label": country_label}))
 
 
 
 
 
 
 
 
 
379
 
380
  def signup_teacher(title: str, name: str, email: str, password: str):
381
- return _json_or_raise(_req("POST", "/auth/signup/teacher",
382
- json={"title": title, "name": name, "email": email, "password": password}))
 
 
 
 
 
383
 
384
  # ---- New LangGraph-backed endpoints ----
385
  def fetch_lesson_content(lesson: str, module: str, topic: str):
 
3
  from urllib3.util.retry import Retry
4
  from requests.adapters import HTTPAdapter
5
 
6
+
7
  # ---- Setup ----
8
  BACKEND = (os.getenv("BACKEND_URL") or "").strip().rstrip("/")
9
  if not BACKEND:
 
374
  return _json_or_raise(_req("POST", "/auth/login", json={"email": email, "password": password}))
375
 
376
  def signup_student(name: str, email: str, password: str, level_label: str, country_label: str):
377
+ payload_student = {
378
+ "name": name, "email": email, "password": password,
379
+ "level_label": level_label, "country_label": country_label
380
+ }
381
+ # Prefer dedicated route; fall back to /auth/register with role
382
+ return _try_candidates("POST", [
383
+ ("/auth/signup/student", {"json": payload_student}),
384
+ ("/auth/register", {"json": {
385
+ "role": "student", "name": name, "email": email, "password": password,
386
+ "level": level_label, "country": country_label
387
+ }}),
388
+ ])
389
 
390
  def signup_teacher(title: str, name: str, email: str, password: str):
391
+ payload_teacher = {"title": title, "name": name, "email": email, "password": password}
392
+ return _try_candidates("POST", [
393
+ ("/auth/signup/teacher", {"json": payload_teacher}),
394
+ ("/auth/register", {"json": {
395
+ "role": "teacher", "title": title, "name": name, "email": email, "password": password
396
+ }}),
397
+ ])
398
 
399
  # ---- New LangGraph-backed endpoints ----
400
  def fetch_lesson_content(lesson: str, module: str, topic: str):