create-caspian-app 0.2.0-beta.79 → 0.2.0-beta.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.py +22 -5
- package/package.json +1 -1
package/dist/main.py
CHANGED
|
@@ -194,11 +194,14 @@ class AuthMiddleware:
|
|
|
194
194
|
if oauth_response:
|
|
195
195
|
await oauth_response(scope, receive, send)
|
|
196
196
|
return
|
|
197
|
+
is_authenticated = auth_inst.is_authenticated()
|
|
198
|
+
if is_authenticated:
|
|
199
|
+
auth_inst.refresh_session()
|
|
197
200
|
if auth_inst.is_public_route(path):
|
|
198
201
|
await self.app(scope, receive, send)
|
|
199
202
|
return
|
|
200
203
|
if auth_inst.is_auth_route(path):
|
|
201
|
-
if
|
|
204
|
+
if is_authenticated:
|
|
202
205
|
await RedirectResponse(
|
|
203
206
|
url=auth_inst.settings.default_signin_redirect,
|
|
204
207
|
status_code=303
|
|
@@ -210,7 +213,7 @@ class AuthMiddleware:
|
|
|
210
213
|
if auth_inst.settings.is_role_based:
|
|
211
214
|
required_roles = auth_inst.get_required_roles(path)
|
|
212
215
|
if required_roles:
|
|
213
|
-
if not
|
|
216
|
+
if not is_authenticated:
|
|
214
217
|
await RedirectResponse(url=f'/signin?next={path}', status_code=303)(scope, receive, send)
|
|
215
218
|
return
|
|
216
219
|
if not auth_inst.check_role(auth_inst.get_payload(), required_roles):
|
|
@@ -218,7 +221,7 @@ class AuthMiddleware:
|
|
|
218
221
|
return
|
|
219
222
|
|
|
220
223
|
if auth_inst.is_private_route(path):
|
|
221
|
-
if not
|
|
224
|
+
if not is_authenticated:
|
|
222
225
|
await RedirectResponse(url=f'/signin?next={path}', status_code=303)(scope, receive, send)
|
|
223
226
|
return
|
|
224
227
|
|
|
@@ -495,8 +498,21 @@ def register_single_route(url_pattern: str, file_path: str):
|
|
|
495
498
|
|
|
496
499
|
endpoint = file_path.replace('/', '_').replace('\\', '_').replace(
|
|
497
500
|
'.', '_').replace('[', '').replace(']', '').replace('(', '').replace(')', '')
|
|
498
|
-
|
|
499
|
-
|
|
501
|
+
|
|
502
|
+
route_methods = ['GET', 'POST']
|
|
503
|
+
if file_path.endswith('.py'):
|
|
504
|
+
module = load_route_module(file_path)
|
|
505
|
+
declared_route_methods = getattr(module, 'route_methods', None)
|
|
506
|
+
if isinstance(declared_route_methods, (list, tuple)) and declared_route_methods:
|
|
507
|
+
normalized_methods = [
|
|
508
|
+
str(method).strip().upper()
|
|
509
|
+
for method in declared_route_methods
|
|
510
|
+
if str(method).strip()
|
|
511
|
+
]
|
|
512
|
+
if normalized_methods:
|
|
513
|
+
route_methods = list(dict.fromkeys(normalized_methods))
|
|
514
|
+
|
|
515
|
+
app.add_api_route(url_pattern, make_handler, methods=route_methods, name=endpoint)
|
|
500
516
|
|
|
501
517
|
|
|
502
518
|
register_routes()
|
|
@@ -538,6 +554,7 @@ async def custom_general_exception_handler(request: Request, exc: Exception):
|
|
|
538
554
|
print(traceback.format_exc())
|
|
539
555
|
error_message = str(exc)
|
|
540
556
|
error_trace = traceback.format_exc() if not IS_PRODUCTION else None
|
|
557
|
+
|
|
541
558
|
error_page_path = os.path.join('src', 'app', 'error.html')
|
|
542
559
|
if os.path.exists(error_page_path):
|
|
543
560
|
with open(error_page_path, 'r', encoding='utf-8') as f:
|