From f80c51045e74ce1ffc96a3441bcc564fdfd99269 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 7 May 2024 01:38:44 +0200 Subject: [PATCH] Added session support and themes --- parameciofast/modules/fastadmin/__init__.py | 22 +- .../fastadmin/templates/admin/dashboard.phtml | 211 ++++++++++++++++++ .../fastadmin/templates/admin/home.phtml | 9 + .../fastadmin/templates/admin/login2.phtml | 116 ---------- 4 files changed, 241 insertions(+), 117 deletions(-) create mode 100644 parameciofast/modules/fastadmin/templates/admin/dashboard.phtml create mode 100644 parameciofast/modules/fastadmin/templates/admin/home.phtml delete mode 100644 parameciofast/modules/fastadmin/templates/admin/login2.phtml diff --git a/parameciofast/modules/fastadmin/__init__.py b/parameciofast/modules/fastadmin/__init__.py index bcbca72..ecaa5d6 100644 --- a/parameciofast/modules/fastadmin/__init__.py +++ b/parameciofast/modules/fastadmin/__init__.py @@ -74,7 +74,7 @@ def admin(paramecio_session: Annotated[str | None, Cookie()] = None): if 'admin' in arr_user: - return "Hello world" + return t.load_template('home.phtml', title=_('Admin'), user=arr_user) else: raise HTTPException(status_code=404, detail="User incorrect") @@ -352,6 +352,26 @@ def admin_recovery_passsword(): return "" +@admin_app.get('/change_theme') +def change_theme(theme: int, paramecio_session: Annotated[str | None, Cookie()] = None): + + resp={'error': 0} + + response=JSONResponse(resp) + + s=URLSafeSerializer(config.secret_key) + + arr_user=get_user(paramecio_session) + + arr_user['theme']=theme + + value_cookie=s.dumps(arr_user) + + response.set_cookie(key=cookie_name, value=value_cookie) + + return response + + """Function for get the number of login tries """ diff --git a/parameciofast/modules/fastadmin/templates/admin/dashboard.phtml b/parameciofast/modules/fastadmin/templates/admin/dashboard.phtml new file mode 100644 index 0000000..b0711b5 --- /dev/null +++ b/parameciofast/modules/fastadmin/templates/admin/dashboard.phtml @@ -0,0 +1,211 @@ +<% + + +dark_checked='' +dark_css='' + +if user.get('theme', 0)==1: + dark_checked='checked' + dark_css='dark' + + +%> + + + + + +${title} + + + + + +<%block name="extra_css"> + + + + +${load_js()|n} +<%block name="extra_js"> + +<%block name="extra_header"> + + + +
+
+
+
+<%block name="logout"> Logout +
+ +
+ +
+ + +
+

${title}

+
+
+ ${_('Dark theme')} +
+
+ +
+
+
+ + <%block name="content"> + +
+
+
+
+
+ +<%block name="jscript_block"> + + + diff --git a/parameciofast/modules/fastadmin/templates/admin/home.phtml b/parameciofast/modules/fastadmin/templates/admin/home.phtml new file mode 100644 index 0000000..f3883a5 --- /dev/null +++ b/parameciofast/modules/fastadmin/templates/admin/home.phtml @@ -0,0 +1,9 @@ +<%inherit file="dashboard.phtml"/> +<%block name="content"> +
+ ${_('Welcome to Paramecio Admin')} +
+
+ ${_('From here you can admin your site')} +
+ diff --git a/parameciofast/modules/fastadmin/templates/admin/login2.phtml b/parameciofast/modules/fastadmin/templates/admin/login2.phtml deleted file mode 100644 index 8de9e95..0000000 --- a/parameciofast/modules/fastadmin/templates/admin/login2.phtml +++ /dev/null @@ -1,116 +0,0 @@ - - - - <%block name="title">${_('Paramecio Login')}</%block> - - - - - <%block name="extra_css"> - - - <%block name="extra_js"> - - <%block name="ajax"> - - - - - <%block name="content"> -
-
- ${_('Paramecio Login')} -
- ${forms|n} -
- ${_('Remember login?')} -
-
- -   -
- % if yes_recovery_login: - - % endif - -
- - -