hoshikrana commited on
Commit
83c9156
·
verified ·
1 Parent(s): f8654a4

Deploy backend from GitHub Actions

Browse files
.env.example CHANGED
@@ -9,6 +9,7 @@ ALLOWED_ORIGIN_REGEX=https://.*\.vercel\.app
9
  TRUSTED_HOSTS=localhost,127.0.0.1,*.vercel.app,*.hf.space
10
  FRONTEND_URL=http://localhost:3000
11
  BACKEND_URL=http://localhost:8000
 
12
  VERSION=1.0.0
13
 
14
  # === DATABASE ===
 
9
  TRUSTED_HOSTS=localhost,127.0.0.1,*.vercel.app,*.hf.space
10
  FRONTEND_URL=http://localhost:3000
11
  BACKEND_URL=http://localhost:8000
12
+ REQUIRE_EMAIL_VERIFICATION=false
13
  VERSION=1.0.0
14
 
15
  # === DATABASE ===
backend/api/v1/routers/auth.py CHANGED
@@ -129,18 +129,23 @@ async def register(
129
  email=body.email,
130
  full_name=body.full_name,
131
  hashed_password=hash_password(body.password),
132
- is_active=not settings.is_production, # Auto-active in dev, requires verification in prod
133
- is_verified=not settings.is_production
134
  )
135
  db.add(user)
136
  await db.commit()
137
  await db.refresh(user)
138
 
139
- plain_token, _token_hash = generate_verification_token()
140
- background_tasks.add_task(send_verification_email, user.email, plain_token)
 
141
 
142
  logger.info("User registered", extra={"user_id": str(user.id), "email": user.email})
143
- message = "Account created. You can sign in now." if not settings.is_production else "Account created. Check your email to verify."
 
 
 
 
144
  return MessageResponse(message=message)
145
 
146
  @router.post("/login", response_model=AuthResponse)
@@ -159,7 +164,10 @@ async def login(
159
  await brute_force_protector.check_and_record_failure(client_ip)
160
  raise AuthenticationError("Invalid email or password")
161
 
162
- if not user.is_active:
 
 
 
163
  raise AccountInactiveError("Please verify your email before logging in")
164
 
165
  brute_force_protector.record_success(client_ip)
 
129
  email=body.email,
130
  full_name=body.full_name,
131
  hashed_password=hash_password(body.password),
132
+ is_active=not settings.REQUIRE_EMAIL_VERIFICATION,
133
+ is_verified=not settings.REQUIRE_EMAIL_VERIFICATION,
134
  )
135
  db.add(user)
136
  await db.commit()
137
  await db.refresh(user)
138
 
139
+ if settings.REQUIRE_EMAIL_VERIFICATION:
140
+ plain_token, _token_hash = generate_verification_token()
141
+ background_tasks.add_task(send_verification_email, user.email, plain_token)
142
 
143
  logger.info("User registered", extra={"user_id": str(user.id), "email": user.email})
144
+ message = (
145
+ "Account created. Check your email to verify."
146
+ if settings.REQUIRE_EMAIL_VERIFICATION
147
+ else "Account created. You can sign in now."
148
+ )
149
  return MessageResponse(message=message)
150
 
151
  @router.post("/login", response_model=AuthResponse)
 
164
  await brute_force_protector.check_and_record_failure(client_ip)
165
  raise AuthenticationError("Invalid email or password")
166
 
167
+ if not user.is_active and not settings.REQUIRE_EMAIL_VERIFICATION:
168
+ user.is_active = True
169
+ user.is_verified = True
170
+ elif not user.is_active:
171
  raise AccountInactiveError("Please verify your email before logging in")
172
 
173
  brute_force_protector.record_success(client_ip)
backend/core/config.py CHANGED
@@ -23,6 +23,7 @@ class Settings(BaseSettings):
23
  TRUSTED_HOSTS: Any = ["localhost", "127.0.0.1", "*.vercel.app", "*.hf.space"]
24
  FRONTEND_URL: str = "http://localhost:3000"
25
  BACKEND_URL: str = "http://localhost:8000"
 
26
 
27
  # === Database ===
28
  DATABASE_URL: str = "sqlite+aiosqlite:///./medsight.db"
 
23
  TRUSTED_HOSTS: Any = ["localhost", "127.0.0.1", "*.vercel.app", "*.hf.space"]
24
  FRONTEND_URL: str = "http://localhost:3000"
25
  BACKEND_URL: str = "http://localhost:8000"
26
+ REQUIRE_EMAIL_VERIFICATION: bool = False
27
 
28
  # === Database ===
29
  DATABASE_URL: str = "sqlite+aiosqlite:///./medsight.db"