Mark-Lasfar commited on
Commit
b249bd4
·
1 Parent(s): 87b09dd

Update authorize for google & github

Browse files
Files changed (2) hide show
  1. main.py +28 -6
  2. static/css/sidebar.css +18 -90
main.py CHANGED
@@ -25,7 +25,7 @@ from pathlib import Path
25
  from hashlib import md5
26
  from datetime import datetime
27
  import re
28
-
29
  # Setup logging for debugging and monitoring
30
  logging.basicConfig(level=logging.INFO)
31
  logger = logging.getLogger(__name__)
@@ -89,12 +89,15 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
89
  # CORS setup to allow requests from specific origins
90
  app.add_middleware(
91
  CORSMiddleware,
92
- allow_origins=[
93
- "https://mgzon-mgzon-app.hf.space", # Production domain
94
- "http://localhost:7860", # Local development
95
- "https://mgzon-mgzon-app.hf.space/users/me", # For user settings endpoint
96
  # Add staging domain here if needed, e.g., "https://staging.mgzon-mgzon-app.hf.space"
97
- ],
 
 
 
98
  allow_credentials=True,
99
  allow_methods=["*"],
100
  allow_headers=["*"],
@@ -144,6 +147,25 @@ class NotFoundMiddleware(BaseHTTPMiddleware):
144
  return templates.TemplateResponse("500.html", {"request": request, "error": str(e)}, status_code=500)
145
 
146
  app.add_middleware(NotFoundMiddleware)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  # Root endpoint for homepage
149
  @app.get("/", response_class=HTMLResponse)
 
25
  from hashlib import md5
26
  from datetime import datetime
27
  import re
28
+ from httpx_oauth.clients.google import GoogleOAuth2
29
  # Setup logging for debugging and monitoring
30
  logging.basicConfig(level=logging.INFO)
31
  logger = logging.getLogger(__name__)
 
89
  # CORS setup to allow requests from specific origins
90
  app.add_middleware(
91
  CORSMiddleware,
92
+ #allow_origins=[
93
+ #"https://mgzon-mgzon-app.hf.space", # Production domain
94
+ # "http://localhost:7860", # Local development
95
+ # "https://mgzon-mgzon-app.hf.space/users/me", # For user settings endpoint
96
  # Add staging domain here if needed, e.g., "https://staging.mgzon-mgzon-app.hf.space"
97
+ # "http://localhost:3000",
98
+ # "https://mgchat.vercel.app",
99
+ # ],
100
+ allow_origins=["*"],
101
  allow_credentials=True,
102
  allow_methods=["*"],
103
  allow_headers=["*"],
 
147
  return templates.TemplateResponse("500.html", {"request": request, "error": str(e)}, status_code=500)
148
 
149
  app.add_middleware(NotFoundMiddleware)
150
+ # Manual OAuth authorize endpoints (to ensure they work even if router fails)
151
+ @app.get("/auth/google/authorize")
152
+ async def google_authorize():
153
+ redirect_uri = "https://mgzon-mgzon-app.hf.space/auth/google/callback"
154
+ authorization_url = await google_oauth_client.get_authorization_url(
155
+ redirect_uri=redirect_uri,
156
+ scope=["openid", "email", "profile"],
157
+ )
158
+ return RedirectResponse(authorization_url)
159
+
160
+ @app.get("/auth/github/authorize")
161
+ async def github_authorize():
162
+ redirect_uri = "https://mgzon-mgzon-app.hf.space/auth/github/callback"
163
+ authorization_url = await github_oauth_client.get_authorization_url(
164
+ redirect_uri=redirect_uri,
165
+ scope=["user", "user:email"],
166
+ )
167
+ return RedirectResponse(authorization_url)
168
+
169
 
170
  # Root endpoint for homepage
171
  @app.get("/", response_class=HTMLResponse)
static/css/sidebar.css CHANGED
@@ -1,23 +1,17 @@
1
- /* sidebar.css */
2
-
3
- /* تنسيق السايدبار الأساسي */
4
  #sidebar {
5
- width: 256px; /* عرض ثابت للسايدبار */
6
- background: linear-gradient(to bottom, rgba(31, 41, 55, 0.9), rgba(20, 78, 85, 0.9)); /* تدرج لوني */
7
- backdrop-filter: blur(10px); /* تأثير البلور */
8
- -webkit-backdrop-filter: blur(10px); /* دعم WebKit */
9
- box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3); /* ظل خفيف */
10
- transition: transform 0.3s ease-in-out; /* حركة سلسة */
11
- z-index: 50; /* التأكد إن السايدبار فوق العناصر الأخرى */
12
  }
13
 
14
- /* تنسيق روابط التنقل */
15
  #sidebar nav ul li a {
16
  display: flex;
17
  align-items: center;
18
  padding: 0.5rem 1rem;
19
  border-radius: 0.375rem;
20
- color: white;
21
  transition: background-color 0.2s ease, transform 0.2s ease;
22
  }
23
 
@@ -26,19 +20,12 @@
26
  transform: translateX(4px);
27
  }
28
 
29
- /* تنسيق قائمة المحادثات */
30
- #conversationList {
31
- max-height: calc(100vh - 300px); /* تحديد الارتفاع */
32
- overflow-y: auto; /* شريط تمرير إذا لزم الأمر */
33
- }
34
-
35
  #conversationList li {
36
  display: flex;
37
  align-items: center;
38
  justify-content: space-between;
39
  padding: 0.5rem 1rem;
40
  border-radius: 0.375rem;
41
- color: white;
42
  transition: background-color 0.2s ease, transform 0.2s ease;
43
  }
44
 
@@ -54,7 +41,6 @@
54
  white-space: nowrap;
55
  }
56
 
57
- /* تنسيق زر الحذف */
58
  .delete-conversation-btn {
59
  opacity: 0;
60
  transition: opacity 0.2s ease;
@@ -64,88 +50,30 @@
64
  opacity: 1;
65
  }
66
 
67
- /* تنسيق زر التبديل */
68
- #sidebarToggle {
69
- background: none;
70
- border: none;
71
- cursor: pointer;
72
- color: white;
73
- }
74
-
75
- /* تنسيق زر History Toggle */
76
- #historyToggle {
77
- display: flex;
78
- align-items: center;
79
- width: 100%;
80
- padding: 0.5rem 1rem;
81
- color: white;
82
- background: none;
83
- border: none;
84
- border-radius: 0.375rem;
85
- text-align: left;
86
- transition: background-color 0.2s ease;
87
- }
88
-
89
- #historyToggle:hover {
90
- background-color: rgba(55, 65, 81, 0.8);
91
- }
92
-
93
- /* تنسيق تلميح السحب */
94
  #swipeHint {
95
- position: fixed;
96
- top: 50%;
97
- left: 1rem;
98
- z-index: 50;
99
- animation: swipe 2s infinite; /* استخدام swipe بدل pulse */
100
  }
101
 
102
- #swipeHint img {
103
- width: 32px;
104
- height: 32px;
 
105
  }
106
 
107
- /* الرسوم المتحركة */
108
- @keyframes swipe {
109
- 0% { transform: translateX(0); opacity: 0.7; }
110
- 50% { transform: translateX(10px); opacity: 1; }
111
- 100% { transform: translateX(0); opacity: 0.7; }
112
- }
113
 
114
- /* التصميم المتجاوب */
115
- @media (min-width: 768px) {
116
- #sidebar {
117
- transform: translateX(0); /* السايدبار مرئي دايمًا */
118
- }
119
- #sidebarToggle {
120
- display: none; /* إخفاء زر التبديل على الشاشات الكبيرة */
121
- }
122
- #swipeHint {
123
- display: none; /* إخفاء تلميح السحب على الشاشات الكبيرة */
124
- }
125
- #conversationList {
126
- display: block; /* قائمة المحادثات مرئية دايمًا */
127
- }
128
- #historyToggle {
129
- display: none; /* إخفاء زر History Toggle على الشاشات الكبيرة */
130
- }
131
- }
132
 
133
- @media (max-width: 767px) {
 
134
  #sidebar {
135
  width: 80%;
136
  max-width: 280px;
137
- transform: translateX(-100%); /* السايدبار مخفي افتراضيًا */
138
- }
139
- #sidebar.open {
140
- transform: translateX(0); /* إظهار السايدبار عند الفتح */
141
  }
142
  .md\:ml-64 {
143
- margin-left: 0 !important; /* إزالة الهامش على الموبايل */
144
  }
145
- #conversationList {
146
- display: none; /* إخفاء قائمة المحادثات افتراضيًا */
147
- }
148
- #conversationList:not(.hidden) {
149
- display: block; /* إظهار القائمة عند الضغط على History Toggle */
150
  }
151
  }
 
 
 
1
+ /* Sidebar styles */
 
 
2
  #sidebar {
3
+ background: linear-gradient(to bottom, rgba(31, 41, 55, 0.9), rgba(20, 78, 85, 0.9));
4
+ backdrop-filter: blur(10px);
5
+ -webkit-backdrop-filter: blur(10px);
6
+ box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
7
+ transition: transform 0.3s ease-in-out;
 
 
8
  }
9
 
 
10
  #sidebar nav ul li a {
11
  display: flex;
12
  align-items: center;
13
  padding: 0.5rem 1rem;
14
  border-radius: 0.375rem;
 
15
  transition: background-color 0.2s ease, transform 0.2s ease;
16
  }
17
 
 
20
  transform: translateX(4px);
21
  }
22
 
 
 
 
 
 
 
23
  #conversationList li {
24
  display: flex;
25
  align-items: center;
26
  justify-content: space-between;
27
  padding: 0.5rem 1rem;
28
  border-radius: 0.375rem;
 
29
  transition: background-color 0.2s ease, transform 0.2s ease;
30
  }
31
 
 
41
  white-space: nowrap;
42
  }
43
 
 
44
  .delete-conversation-btn {
45
  opacity: 0;
46
  transition: opacity 0.2s ease;
 
50
  opacity: 1;
51
  }
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  #swipeHint {
54
+ animation: pulse 2s infinite;
 
 
 
 
55
  }
56
 
57
+ @keyframes pulse {
58
+ 0% { transform: scale(1); opacity: 0.7; }
59
+ 50% { transform: scale(1.2); opacity: 1; }
60
+ 100% { transform: scale(1); opacity: 0.7; }
61
  }
62
 
 
 
 
 
 
 
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
+ /* Responsive adjustments */
66
+ @media (max-width: 768px) {
67
  #sidebar {
68
  width: 80%;
69
  max-width: 280px;
 
 
 
 
70
  }
71
  .md\:ml-64 {
72
+ margin-left: 0 !important;
73
  }
74
+ #sidebarToggleMobile {
75
+ display: none !important;
 
 
 
76
  }
77
  }
78
+
79
+