Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Form, HTTPException, Depends, Header
|
| 2 |
+
from fastapi.security import OAuth2PasswordBearer
|
| 3 |
+
from pydantic import BaseModel, EmailStr
|
| 4 |
+
import os, requests, random, string, jwt
|
| 5 |
+
from datetime import datetime, timedelta, timezone
|
| 6 |
+
from passlib.context import CryptContext
|
| 7 |
+
|
| 8 |
+
# ====== Config ======
|
| 9 |
+
SUPA_URL = os.getenv("SUPABASE_URL", "https://hirmgvjpdifudkiugtyr.supabase.co").rstrip("/")
|
| 10 |
+
SUPA_KEY = os.getenv("SUPABASE_ANON_KEY", "")
|
| 11 |
+
GAS_URL = os.getenv("GAS_MAIL_URL","https://script.google.com/macros/s/AKfycbxzj7vfMpkzAissmvXjazWZMRTvhB2tBG3xodYeq8wYQzraBekA5NupIbeJLaGUh3l85g/exec")
|
| 12 |
+
|
| 13 |
+
JWT_SECRET = os.getenv("JWT_SECRET", "change_me")
|
| 14 |
+
JWT_ALG = os.getenv("JWT_ALG", "HS256")
|
| 15 |
+
|
| 16 |
+
HEADERS = {
|
| 17 |
+
"apikey": SUPA_KEY,
|
| 18 |
+
"Authorization": f"Bearer {SUPA_KEY}",
|
| 19 |
+
"Content-Type": "application/json",
|
| 20 |
+
"Accept": "application/json",
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
pwd = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
| 24 |
+
oauth2 = OAuth2PasswordBearer(tokenUrl="/api/auth/login")
|
| 25 |
+
|
| 26 |
+
app = FastAPI(title="BinRushd Auth (Supabase REST)")
|
| 27 |
+
|
| 28 |
+
# ====== Helpers ======
|
| 29 |
+
def now_utc() -> datetime:
|
| 30 |
+
return datetime.now(timezone.utc)
|
| 31 |
+
|
| 32 |
+
def iso(dt: datetime) -> str:
|
| 33 |
+
return dt.astimezone(timezone.utc).isoformat()
|
| 34 |
+
|
| 35 |
+
def create_access_token(sub: str, scopes=None, minutes=60) -> str:
|
| 36 |
+
now = now_utc()
|
| 37 |
+
payload = {"sub": sub, "scopes": scopes or [], "iat": int(now.timestamp()), "exp": int((now + timedelta(minutes=minutes)).timestamp())}
|
| 38 |
+
return jwt.encode(payload, JWT_SECRET, algorithm=JWT_ALG)
|
| 39 |
+
|
| 40 |
+
def decode_token(tok: str):
|
| 41 |
+
return jwt.decode(tok, JWT_SECRET, algorithms=[JWT_ALG])
|
| 42 |
+
|
| 43 |
+
def eq(col, val): return {col: f"eq.{val}"}
|
| 44 |
+
|
| 45 |
+
def supa_select(table: str, params: dict):
|
| 46 |
+
r = requests.get(f"{SUPA_URL}/rest/v1/{table}", headers=HEADERS, params=params, timeout=30)
|
| 47 |
+
r.raise_for_status(); return r.json()
|
| 48 |
+
|
| 49 |
+
def supa_insert(table: str, obj: dict):
|
| 50 |
+
r = requests.post(f"{SUPA_URL}/rest/v1/{table}", headers={**HEADERS,"Prefer":"return=representation"}, json=obj, timeout=30)
|
| 51 |
+
r.raise_for_status(); return r.json()[0]
|
| 52 |
+
|
| 53 |
+
def supa_update(table: str, filters: dict, obj: dict):
|
| 54 |
+
r = requests.patch(f"{SUPA_URL}/rest/v1/{table}", headers={**HEADERS,"Prefer":"return=representation"}, params=filters, json=obj, timeout=30)
|
| 55 |
+
r.raise_for_status(); return r.json()
|
| 56 |
+
|
| 57 |
+
def supa_delete(table: str, filters: dict):
|
| 58 |
+
r = requests.delete(f"{SUPA_URL}/rest/v1/{table}", headers=HEADERS, params=filters, timeout=30)
|
| 59 |
+
r.raise_for_status(); return True
|
| 60 |
+
|
| 61 |
+
def send_otp_email(email: str, otp: str, purpose: str, name: str|None=None):
|
| 62 |
+
# GAS Web App: يرسل HTML جاهز
|
| 63 |
+
payload = {"email": email, "otp": otp, "purpose": purpose, "name": name or "عميلنا الكريم"}
|
| 64 |
+
try:
|
| 65 |
+
r = requests.post(GAS_URL, json=payload, timeout=30)
|
| 66 |
+
r.raise_for_status()
|
| 67 |
+
# لو حابب تسجّل لوج:
|
| 68 |
+
supa_insert("email_logs", {
|
| 69 |
+
"user_id": None, "to": email, "template": f"{purpose}_otp",
|
| 70 |
+
"status": "sent", "payload": payload, "created_at": iso(now_utc())
|
| 71 |
+
})
|
| 72 |
+
except Exception as e:
|
| 73 |
+
supa_insert("email_logs", {
|
| 74 |
+
"user_id": None, "to": email, "template": f"{purpose}_otp",
|
| 75 |
+
"status": "failed", "payload": payload, "error": str(e), "created_at": iso(now_utc())
|
| 76 |
+
})
|
| 77 |
+
|
| 78 |
+
def require_scopes(scopes_required=None):
|
| 79 |
+
scopes_required = scopes_required or []
|
| 80 |
+
def _dep(token: str = Depends(oauth2)):
|
| 81 |
+
try:
|
| 82 |
+
payload = decode_token(token)
|
| 83 |
+
except Exception:
|
| 84 |
+
raise HTTPException(401, "Invalid token")
|
| 85 |
+
token_scopes = payload.get("scopes", [])
|
| 86 |
+
if any(s not in token_scopes for s in scopes_required):
|
| 87 |
+
raise HTTPException(403, "Insufficient scope")
|
| 88 |
+
return payload
|
| 89 |
+
return _dep
|
| 90 |
+
|
| 91 |
+
def latest_valid_otp(user_id: int, purpose: str):
|
| 92 |
+
rows = supa_select("user_otps", {**eq("user_id", user_id), **eq("purpose", purpose), "order":"created_at.desc", "limit":"1"})
|
| 93 |
+
return rows[0] if rows else None
|
| 94 |
+
|
| 95 |
+
def rotate_refresh(user_id: int, device: str|None, ua: str|None):
|
| 96 |
+
raw = ''.join(random.choices(string.ascii_letters + string.digits, k=64))
|
| 97 |
+
hashed = pwd.hash(raw)
|
| 98 |
+
rec = supa_insert("user_sessions", {
|
| 99 |
+
"user_id": user_id,
|
| 100 |
+
"refresh_token_hash": hashed,
|
| 101 |
+
"device_name": device,
|
| 102 |
+
"user_agent": ua,
|
| 103 |
+
"expires_at": iso(now_utc() + timedelta(days=14)),
|
| 104 |
+
"created_at": iso(now_utc())
|
| 105 |
+
})
|
| 106 |
+
return raw, rec
|
| 107 |
+
|
| 108 |
+
# ====== Schemas ======
|
| 109 |
+
class LoginIn(BaseModel):
|
| 110 |
+
email: EmailStr
|
| 111 |
+
password: str
|
| 112 |
+
|
| 113 |
+
class EmailOTP(BaseModel):
|
| 114 |
+
email: EmailStr
|
| 115 |
+
otp: str
|
| 116 |
+
|
| 117 |
+
class ResetPasswordIn(BaseModel):
|
| 118 |
+
password: str
|
| 119 |
+
password_confirmation: str
|
| 120 |
+
|
| 121 |
+
# ====== Endpoints ======
|
| 122 |
+
@app.post("/api/auth/register")
|
| 123 |
+
def register(
|
| 124 |
+
email: EmailStr = Form(...),
|
| 125 |
+
password: str = Form(...),
|
| 126 |
+
password_confirmation: str = Form(...),
|
| 127 |
+
fname: str | None = Form(None),
|
| 128 |
+
lname: str | None = Form(None),
|
| 129 |
+
mobile: str | None = Form(None),
|
| 130 |
+
):
|
| 131 |
+
if password != password_confirmation:
|
| 132 |
+
raise HTTPException(422, "Passwords do not match")
|
| 133 |
+
|
| 134 |
+
existed = supa_select("users", {**eq("email", email), "select":"id", "limit":"1"})
|
| 135 |
+
if existed:
|
| 136 |
+
raise HTTPException(422, "Email already exists")
|
| 137 |
+
|
| 138 |
+
user = supa_insert("users", {
|
| 139 |
+
"email": email, "password": pwd.hash(password),
|
| 140 |
+
"fname": fname, "lname": lname, "mobile": mobile,
|
| 141 |
+
"role": "client", "is_active": True, "created_at": iso(now_utc())
|
| 142 |
+
})
|
| 143 |
+
|
| 144 |
+
otp = f"{random.randint(100000, 999999)}"
|
| 145 |
+
supa_insert("user_otps", {
|
| 146 |
+
"user_id": user["id"],
|
| 147 |
+
"purpose": "verify",
|
| 148 |
+
"code_hash": pwd.hash(otp),
|
| 149 |
+
"expires_at": iso(now_utc() + timedelta(minutes=3)),
|
| 150 |
+
"attempts": 0, "created_at": iso(now_utc())
|
| 151 |
+
})
|
| 152 |
+
send_otp_email(email, otp, "verify", user.get("fname"))
|
| 153 |
+
|
| 154 |
+
# توكن مؤقت لتأكيد الحساب
|
| 155 |
+
token = create_access_token(sub=str(email), scopes=["verifyAccount"], minutes=7)
|
| 156 |
+
return {"access_token": token, "token_type": "bearer"}
|
| 157 |
+
|
| 158 |
+
@app.post("/api/auth/resend_otp")
|
| 159 |
+
def resend_otp(payload=Depends(require_scopes(["verifyAccount"]))):
|
| 160 |
+
email = payload["sub"]
|
| 161 |
+
u = supa_select("users", {**eq("email", email), "select":"id,fname", "limit":"1"})
|
| 162 |
+
if not u: raise HTTPException(404, "User not found")
|
| 163 |
+
user = u[0]
|
| 164 |
+
otp = f"{random.randint(100000, 999999)}"
|
| 165 |
+
supa_insert("user_otps", {
|
| 166 |
+
"user_id": user["id"], "purpose":"verify", "code_hash": pwd.hash(otp),
|
| 167 |
+
"expires_at": iso(now_utc() + timedelta(minutes=3)),
|
| 168 |
+
"attempts": 0, "created_at": iso(now_utc())
|
| 169 |
+
})
|
| 170 |
+
send_otp_email(email, otp, "verify", user.get("fname"))
|
| 171 |
+
return {"message":"OTP sent"}
|
| 172 |
+
|
| 173 |
+
@app.post("/api/auth/check_otp")
|
| 174 |
+
def check_otp(body: EmailOTP, payload=Depends(require_scopes(["verifyAccount"]))):
|
| 175 |
+
if body.email.lower() != payload["sub"].lower():
|
| 176 |
+
raise HTTPException(400, "Email mismatch")
|
| 177 |
+
|
| 178 |
+
u = supa_select("users", {**eq("email", body.email), "select":"id,email,fname,lname,mobile,role,email_verified_at", "limit": "1"})
|
| 179 |
+
if not u: raise HTTPException(404, "User not found")
|
| 180 |
+
user = u[0]
|
| 181 |
+
|
| 182 |
+
rec = latest_valid_otp(user["id"], "verify")
|
| 183 |
+
if not rec: raise HTTPException(400, "OTP not found")
|
| 184 |
+
if rec.get("consumed_at"): raise HTTPException(400, "OTP already used")
|
| 185 |
+
if datetime.fromisoformat(rec["expires_at"].replace("Z","+00:00")) < now_utc():
|
| 186 |
+
raise HTTPException(400, "OTP expired")
|
| 187 |
+
if not pwd.verify(body.otp, rec["code_hash"]):
|
| 188 |
+
supa_update("user_otps", eq("id", rec["id"]), {"attempts": (rec.get("attempts") or 0) + 1})
|
| 189 |
+
raise HTTPException(400, "Wrong OTP")
|
| 190 |
+
|
| 191 |
+
supa_update("user_otps", eq("id", rec["id"]), {"consumed_at": iso(now_utc())})
|
| 192 |
+
supa_update("users", eq("id", user["id"]), {"email_verified_at": iso(now_utc())})
|
| 193 |
+
|
| 194 |
+
access = create_access_token(sub=user["email"], scopes=["user"], minutes=60*24)
|
| 195 |
+
refresh, _ = rotate_refresh(user["id"], device="mobile", ua=None)
|
| 196 |
+
return {"access_token": access, "refresh_token": refresh, "user": user}
|
| 197 |
+
|
| 198 |
+
@app.post("/api/auth/login")
|
| 199 |
+
def login(body: LoginIn):
|
| 200 |
+
rows = supa_select("users", {**eq("email", body.email), "select":"id,email,password,email_verified_at,fname,lname,mobile,role", "limit":"1"})
|
| 201 |
+
if not rows: raise HTTPException(400, "Bad credentials")
|
| 202 |
+
user = rows[0]
|
| 203 |
+
if not pwd.verify(body.password, user["password"]): raise HTTPException(400, "Bad credentials")
|
| 204 |
+
if not user.get("email_verified_at"): raise HTTPException(400, "Please verify your email first")
|
| 205 |
+
|
| 206 |
+
access = create_access_token(sub=user["email"], scopes=["user"], minutes=60*24)
|
| 207 |
+
refresh, _ = rotate_refresh(user["id"], device="mobile", ua=None)
|
| 208 |
+
return {"access_token": access, "refresh_token": refresh, "user": user}
|
| 209 |
+
|
| 210 |
+
@app.post("/api/auth/token/refresh")
|
| 211 |
+
def token_refresh(refresh_token: str = Form(...)):
|
| 212 |
+
# نبحث عن جلسة تطابق الهاش
|
| 213 |
+
sessions = supa_select("user_sessions", {"select":"id,user_id,refresh_token_hash,expires_at,revoked_at", "order":"created_at.desc"})
|
| 214 |
+
matched = None
|
| 215 |
+
for s in sessions:
|
| 216 |
+
try:
|
| 217 |
+
if s.get("revoked_at"): continue
|
| 218 |
+
if datetime.fromisoformat(s["expires_at"].replace("Z","+00:00")) < now_utc(): continue
|
| 219 |
+
if pwd.verify(refresh_token, s["refresh_token_hash"]):
|
| 220 |
+
matched = s; break
|
| 221 |
+
except Exception:
|
| 222 |
+
continue
|
| 223 |
+
if not matched: raise HTTPException(401, "Invalid refresh token")
|
| 224 |
+
|
| 225 |
+
# اجلب ايميل المستخدم
|
| 226 |
+
u = supa_select("users", {**eq("id", matched["user_id"]), "select":"email", "limit":"1"})[0]
|
| 227 |
+
access = create_access_token(sub=u["email"], scopes=["user"], minutes=60*24)
|
| 228 |
+
|
| 229 |
+
# تدوير الريفريش
|
| 230 |
+
supa_update("user_sessions", eq("id", matched["id"]), {"revoked_at": iso(now_utc())})
|
| 231 |
+
new_refresh, _ = rotate_refresh(matched["user_id"], device="mobile", ua=None)
|
| 232 |
+
return {"access_token": access, "refresh_token": new_refresh}
|
| 233 |
+
|
| 234 |
+
@app.post("/api/auth/profile")
|
| 235 |
+
def profile(payload=Depends(require_scopes(["user"]))):
|
| 236 |
+
u = supa_select("users", {**eq("email", payload["sub"]), "select":"id,email,fname,lname,mobile,role,email_verified_at", "limit":"1"})
|
| 237 |
+
if not u: raise HTTPException(404, "User not found")
|
| 238 |
+
return {"user": u[0]}
|
| 239 |
+
|
| 240 |
+
@app.post("/api/auth/logout")
|
| 241 |
+
def logout(payload=Depends(require_scopes(["user"]))):
|
| 242 |
+
# اختياري: تقدر ترسل refresh_token في Body ونقفله. هنا بنرجّع OK فقط.
|
| 243 |
+
return {"message": "Logout Successfully"}
|
| 244 |
+
|
| 245 |
+
@app.post("/api/auth/logout-all")
|
| 246 |
+
def logout_all(payload=Depends(require_scopes(["user"]))):
|
| 247 |
+
u = supa_select("users", {**eq("email", payload["sub"]), "select":"id", "limit":"1"})[0]
|
| 248 |
+
supa_delete("user_sessions", eq("user_id", u["id"]))
|
| 249 |
+
return {"message":"All sessions revoked"}
|
| 250 |
+
|
| 251 |
+
@app.post("/api/auth/forget_password")
|
| 252 |
+
def forget_password(email: EmailStr = Form(...)):
|
| 253 |
+
u = supa_select("users", {**eq("email", email), "select":"id,fname", "limit":"1"})
|
| 254 |
+
if not u: raise HTTPException(404, "User not found")
|
| 255 |
+
user = u[0]
|
| 256 |
+
otp = f"{random.randint(100000, 999999)}"
|
| 257 |
+
supa_insert("user_otps", {
|
| 258 |
+
"user_id": user["id"], "purpose":"reset", "code_hash": pwd.hash(otp),
|
| 259 |
+
"expires_at": iso(now_utc() + timedelta(minutes=3)),
|
| 260 |
+
"attempts": 0, "created_at": iso(now_utc())
|
| 261 |
+
})
|
| 262 |
+
send_otp_email(email, otp, "reset", user.get("fname"))
|
| 263 |
+
return {"message":"Please check your email"}
|
| 264 |
+
|
| 265 |
+
@app.post("/api/auth/check_forget_password")
|
| 266 |
+
def check_forget_password(body: EmailOTP):
|
| 267 |
+
u = supa_select("users", {**eq("email", body.email), "select":"id", "limit":"1"})
|
| 268 |
+
if not u: raise HTTPException(404, "User not found")
|
| 269 |
+
user = u[0]
|
| 270 |
+
rec = latest_valid_otp(user["id"], "reset")
|
| 271 |
+
if not rec: raise HTTPException(400, "OTP not found")
|
| 272 |
+
if rec.get("consumed_at"): raise HTTPException(400, "OTP already used")
|
| 273 |
+
if datetime.fromisoformat(rec["expires_at"].replace("Z","+00:00")) < now_utc():
|
| 274 |
+
raise HTTPException(400, "OTP expired")
|
| 275 |
+
if not pwd.verify(body.otp, rec["code_hash"]):
|
| 276 |
+
supa_update("user_otps", eq("id", rec["id"]), {"attempts": (rec.get("attempts") or 0) + 1})
|
| 277 |
+
raise HTTPException(400, "Wrong OTP")
|
| 278 |
+
supa_update("user_otps", eq("id", rec["id"]), {"consumed_at": iso(now_utc())})
|
| 279 |
+
|
| 280 |
+
token = create_access_token(sub=body.email, scopes=["reset_password"], minutes=30)
|
| 281 |
+
return {"token": token, "message": "Use this token to reset your password"}
|
| 282 |
+
|
| 283 |
+
@app.post("/api/auth/reset_password")
|
| 284 |
+
def reset_password(body: ResetPasswordIn, authorization: str = Header(None)):
|
| 285 |
+
if not authorization or not authorization.lower().startswith("bearer "):
|
| 286 |
+
raise HTTPException(401, "Missing token")
|
| 287 |
+
payload = decode_token(authorization.split(" ",1)[1])
|
| 288 |
+
if "reset_password" not in payload.get("scopes", []):
|
| 289 |
+
raise HTTPException(403, "Insufficient scope")
|
| 290 |
+
if body.password != body.password_confirmation:
|
| 291 |
+
raise HTTPException(422, "Passwords do not match")
|
| 292 |
+
|
| 293 |
+
u = supa_select("users", {**eq("email", payload["sub"]), "select":"id", "limit":"1"})[0]
|
| 294 |
+
supa_update("users", eq("id", u["id"]), {"password": pwd.hash(body.password)})
|
| 295 |
+
|
| 296 |
+
# ألغِ كل الجلسات بعد تغيير كلمة السر
|
| 297 |
+
supa_delete("user_sessions", eq("user_id", u["id"]))
|
| 298 |
+
return {"message":"password changed successfully!"}
|