Spaces:
Sleeping
Sleeping
Update auth.py
Browse files
auth.py
CHANGED
@@ -68,8 +68,8 @@ SUBSCRIPTION_TIERS = {
|
|
68 |
"documents_per_month": 3,
|
69 |
"video_size_mb": 0,
|
70 |
"audio_size_mb": 0,
|
71 |
-
"daily_api_calls": 10,
|
72 |
-
"max_document_size_mb": 5
|
73 |
}
|
74 |
},
|
75 |
"standard_tier": {
|
@@ -81,21 +81,24 @@ SUBSCRIPTION_TIERS = {
|
|
81 |
"documents_per_month": 20,
|
82 |
"video_size_mb": 100,
|
83 |
"audio_size_mb": 50,
|
84 |
-
"daily_api_calls": 100,
|
85 |
-
"max_document_size_mb": 20
|
86 |
}
|
87 |
},
|
88 |
"premium_tier": {
|
89 |
"price": 1499,
|
90 |
"currency": "INR",
|
91 |
-
"features": [
|
|
|
|
|
|
|
92 |
"limits": {
|
93 |
"document_size_mb": 50,
|
94 |
"documents_per_month": 999999,
|
95 |
"video_size_mb": 500,
|
96 |
"audio_size_mb": 200,
|
97 |
-
"daily_api_calls": 1000,
|
98 |
-
"max_document_size_mb": 50
|
99 |
}
|
100 |
}
|
101 |
}
|
@@ -530,7 +533,7 @@ def check_subscription_access(user: User, feature: str, file_size_mb: Optional[f
|
|
530 |
if user.subscription_tier != "free_tier" and user.subscription_expiry and user.subscription_expiry < datetime.now():
|
531 |
# Downgrade to free tier if subscription expired
|
532 |
user.subscription_tier = "free_tier"
|
533 |
-
user.api_calls_remaining = SUBSCRIPTION_TIERS["free_tier"]["daily_api_calls"]
|
534 |
with get_db_connection() as conn:
|
535 |
c = conn.cursor()
|
536 |
c.execute("""
|
@@ -539,7 +542,7 @@ def check_subscription_access(user: User, feature: str, file_size_mb: Optional[f
|
|
539 |
WHERE id = ?
|
540 |
""", (user.subscription_tier, user.api_calls_remaining, user.id))
|
541 |
conn.commit()
|
542 |
-
|
543 |
# Reset API calls if needed
|
544 |
user = reset_api_calls_if_needed(user)
|
545 |
|
@@ -560,7 +563,7 @@ def check_subscription_access(user: User, feature: str, file_size_mb: Optional[f
|
|
560 |
|
561 |
# Check file size limit if applicable
|
562 |
if file_size_mb:
|
563 |
-
max_size = SUBSCRIPTION_TIERS[user.subscription_tier]["max_document_size_mb"]
|
564 |
if file_size_mb > max_size:
|
565 |
raise HTTPException(
|
566 |
status_code=413,
|
@@ -579,12 +582,12 @@ def check_subscription_access(user: User, feature: str, file_size_mb: Optional[f
|
|
579 |
conn.commit()
|
580 |
|
581 |
return True
|
582 |
-
|
583 |
def reset_api_calls_if_needed(user: User):
|
584 |
"""Reset API call counter if it's a new day"""
|
585 |
today = datetime.now().date()
|
586 |
if user.last_reset_date is None or user.last_reset_date.date() < today:
|
587 |
-
tier_limits = SUBSCRIPTION_TIERS[user.subscription_tier]
|
588 |
user.api_calls_remaining = tier_limits["daily_api_calls"]
|
589 |
user.last_reset_date = datetime.now()
|
590 |
# Update the user in the database
|
@@ -596,7 +599,6 @@ def reset_api_calls_if_needed(user: User):
|
|
596 |
WHERE id = ?
|
597 |
""", (user.api_calls_remaining, user.last_reset_date, user.id))
|
598 |
conn.commit()
|
599 |
-
|
600 |
return user
|
601 |
|
602 |
def login_user(email, password):
|
|
|
68 |
"documents_per_month": 3,
|
69 |
"video_size_mb": 0,
|
70 |
"audio_size_mb": 0,
|
71 |
+
"daily_api_calls": 10,
|
72 |
+
"max_document_size_mb": 5
|
73 |
}
|
74 |
},
|
75 |
"standard_tier": {
|
|
|
81 |
"documents_per_month": 20,
|
82 |
"video_size_mb": 100,
|
83 |
"audio_size_mb": 50,
|
84 |
+
"daily_api_calls": 100,
|
85 |
+
"max_document_size_mb": 20
|
86 |
}
|
87 |
},
|
88 |
"premium_tier": {
|
89 |
"price": 1499,
|
90 |
"currency": "INR",
|
91 |
+
"features": [
|
92 |
+
"basic_document_analysis", "basic_risk_assessment", "video_analysis",
|
93 |
+
"audio_analysis", "chatbot", "detailed_risk_assessment", "contract_clause_analysis"
|
94 |
+
],
|
95 |
"limits": {
|
96 |
"document_size_mb": 50,
|
97 |
"documents_per_month": 999999,
|
98 |
"video_size_mb": 500,
|
99 |
"audio_size_mb": 200,
|
100 |
+
"daily_api_calls": 1000,
|
101 |
+
"max_document_size_mb": 50
|
102 |
}
|
103 |
}
|
104 |
}
|
|
|
533 |
if user.subscription_tier != "free_tier" and user.subscription_expiry and user.subscription_expiry < datetime.now():
|
534 |
# Downgrade to free tier if subscription expired
|
535 |
user.subscription_tier = "free_tier"
|
536 |
+
user.api_calls_remaining = SUBSCRIPTION_TIERS["free_tier"]["limits"]["daily_api_calls"]
|
537 |
with get_db_connection() as conn:
|
538 |
c = conn.cursor()
|
539 |
c.execute("""
|
|
|
542 |
WHERE id = ?
|
543 |
""", (user.subscription_tier, user.api_calls_remaining, user.id))
|
544 |
conn.commit()
|
545 |
+
|
546 |
# Reset API calls if needed
|
547 |
user = reset_api_calls_if_needed(user)
|
548 |
|
|
|
563 |
|
564 |
# Check file size limit if applicable
|
565 |
if file_size_mb:
|
566 |
+
max_size = SUBSCRIPTION_TIERS[user.subscription_tier]["limits"]["max_document_size_mb"]
|
567 |
if file_size_mb > max_size:
|
568 |
raise HTTPException(
|
569 |
status_code=413,
|
|
|
582 |
conn.commit()
|
583 |
|
584 |
return True
|
585 |
+
|
586 |
def reset_api_calls_if_needed(user: User):
|
587 |
"""Reset API call counter if it's a new day"""
|
588 |
today = datetime.now().date()
|
589 |
if user.last_reset_date is None or user.last_reset_date.date() < today:
|
590 |
+
tier_limits = SUBSCRIPTION_TIERS[user.subscription_tier]["limits"]
|
591 |
user.api_calls_remaining = tier_limits["daily_api_calls"]
|
592 |
user.last_reset_date = datetime.now()
|
593 |
# Update the user in the database
|
|
|
599 |
WHERE id = ?
|
600 |
""", (user.api_calls_remaining, user.last_reset_date, user.id))
|
601 |
conn.commit()
|
|
|
602 |
return user
|
603 |
|
604 |
def login_user(email, password):
|