diff --git a/examples/providers.py b/examples/providers.py index 4da4837..1743a84 100644 --- a/examples/providers.py +++ b/examples/providers.py @@ -1,7 +1,19 @@ +from fastapi import Depends, Form +from starlette.requests import Request + +from fastapi_admin.depends import get_current_admin, get_resources from fastapi_admin.models import AbstractAdmin from fastapi_admin.providers.login import UsernamePasswordProvider class LoginProvider(UsernamePasswordProvider): - async def update_password(self, admin: AbstractAdmin, password: str): - pass + async def password( + self, + request: Request, + old_password: str = Form(...), + new_password: str = Form(...), + re_new_password: str = Form(...), + admin: AbstractAdmin = Depends(get_current_admin), + resources=Depends(get_resources), + ): + return await self.logout(request) diff --git a/examples/templates/providers/login/password.html b/examples/templates/providers/login/password.html new file mode 100644 index 0000000..06e2057 --- /dev/null +++ b/examples/templates/providers/login/password.html @@ -0,0 +1,38 @@ +{% extends "layout.html" %} +{% block page_body %} + {% include "components/alert_error.html" %} +
+
+

{{ _('update_password') }} (This will not take effect because is overwrite in + examples)

+
+
+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+{% endblock %} diff --git a/fastapi_admin/locales/en_US/LC_MESSAGES/messages.po b/fastapi_admin/locales/en_US/LC_MESSAGES/messages.po index 1db6c83..c62de86 100644 --- a/fastapi_admin/locales/en_US/LC_MESSAGES/messages.po +++ b/fastapi_admin/locales/en_US/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-05-31 20:49+0800\n" +"POT-Creation-Date: 2021-08-06 23:07+0800\n" "PO-Revision-Date: 2021-04-16 22:46+0800\n" "Last-Translator: FULL NAME \n" "Language: en_US\n" @@ -18,19 +18,19 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.9.1\n" -#: fastapi_admin/resources.py:99 +#: fastapi_admin/resources.py:91 msgid "create" msgstr "Create" -#: fastapi_admin/resources.py:120 +#: fastapi_admin/resources.py:112 msgid "update" msgstr "Update" -#: fastapi_admin/resources.py:122 +#: fastapi_admin/resources.py:114 msgid "delete" msgstr "Delete" -#: fastapi_admin/resources.py:128 +#: fastapi_admin/resources.py:120 msgid "delete_selected" msgstr "Delete Selected" @@ -69,7 +69,7 @@ msgid "Create first admin" msgstr "" #: fastapi_admin/templates/init.html:12 -#: fastapi_admin/templates/providers/login/login.html:42 +#: fastapi_admin/templates/providers/login/login.html:44 msgid "username" msgstr "Username" @@ -78,7 +78,7 @@ msgid "username_placeholder" msgstr "Enter username" #: fastapi_admin/templates/init.html:18 -#: fastapi_admin/templates/providers/login/login.html:52 +#: fastapi_admin/templates/providers/login/login.html:54 msgid "password" msgstr "Password" @@ -115,20 +115,20 @@ msgstr "Search" msgid "bulk_actions" msgstr "Bulk Actions" -#: fastapi_admin/templates/list.html:128 +#: fastapi_admin/templates/list.html:125 msgid "actions" msgstr "Actions" -#: fastapi_admin/templates/list.html:159 +#: fastapi_admin/templates/list.html:156 #, python-format msgid "Showing %(from)s to %(to)s of %(total)s entries" msgstr "" -#: fastapi_admin/templates/list.html:170 +#: fastapi_admin/templates/list.html:167 msgid "prev_page" msgstr "Prev" -#: fastapi_admin/templates/list.html:191 +#: fastapi_admin/templates/list.html:188 msgid "next_page" msgstr "Next" @@ -151,19 +151,19 @@ msgstr "Update password" msgid "logout" msgstr "Logout" -#: fastapi_admin/templates/providers/login/login.html:47 +#: fastapi_admin/templates/providers/login/login.html:49 msgid "login_username_placeholder" msgstr "Enter username" -#: fastapi_admin/templates/providers/login/login.html:57 +#: fastapi_admin/templates/providers/login/login.html:59 msgid "login_password_placeholder" msgstr "Enter password" -#: fastapi_admin/templates/providers/login/login.html:73 +#: fastapi_admin/templates/providers/login/login.html:75 msgid "remember_me" msgstr "Remember me" -#: fastapi_admin/templates/providers/login/login.html:78 +#: fastapi_admin/templates/providers/login/login.html:80 msgid "sign_in" msgstr "Sign in" @@ -190,3 +190,4 @@ msgstr "Confirm new password" #: fastapi_admin/templates/providers/login/password.html:29 msgid "re_new_password_placeholder" msgstr "Enter new password again" + diff --git a/fastapi_admin/locales/zh_CN/LC_MESSAGES/messages.po b/fastapi_admin/locales/zh_CN/LC_MESSAGES/messages.po index 4a88e93..b36eb69 100644 --- a/fastapi_admin/locales/zh_CN/LC_MESSAGES/messages.po +++ b/fastapi_admin/locales/zh_CN/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-05-31 20:49+0800\n" +"POT-Creation-Date: 2021-08-06 23:07+0800\n" "PO-Revision-Date: 2021-04-16 22:46+0800\n" "Last-Translator: FULL NAME \n" "Language: zh_Hans_CN\n" @@ -18,25 +18,25 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.9.1\n" -#: fastapi_admin/resources.py:99 +#: fastapi_admin/resources.py:91 msgid "create" msgstr "创建" -#: fastapi_admin/resources.py:120 +#: fastapi_admin/resources.py:112 msgid "update" msgstr "编辑" -#: fastapi_admin/resources.py:122 +#: fastapi_admin/resources.py:114 msgid "delete" msgstr "删除" -#: fastapi_admin/resources.py:128 +#: fastapi_admin/resources.py:120 msgid "delete_selected" msgstr "删除选中" #: fastapi_admin/providers/login.py:90 msgid "login_failed" -msgstr "登录管理台" +msgstr "登录失败" #: fastapi_admin/providers/login.py:161 msgid "confirm_password_different" @@ -69,7 +69,7 @@ msgid "Create first admin" msgstr "" #: fastapi_admin/templates/init.html:12 -#: fastapi_admin/templates/providers/login/login.html:42 +#: fastapi_admin/templates/providers/login/login.html:44 msgid "username" msgstr "用户名" @@ -78,7 +78,7 @@ msgid "username_placeholder" msgstr "请输入用户名" #: fastapi_admin/templates/init.html:18 -#: fastapi_admin/templates/providers/login/login.html:52 +#: fastapi_admin/templates/providers/login/login.html:54 msgid "password" msgstr "密码" @@ -115,20 +115,20 @@ msgstr "查询" msgid "bulk_actions" msgstr "批量操作" -#: fastapi_admin/templates/list.html:128 +#: fastapi_admin/templates/list.html:125 msgid "actions" msgstr "动作" -#: fastapi_admin/templates/list.html:159 +#: fastapi_admin/templates/list.html:156 #, python-format msgid "Showing %(from)s to %(to)s of %(total)s entries" msgstr "显示 %(from)s 到 %(to)s 共 %(total)s 项" -#: fastapi_admin/templates/list.html:170 +#: fastapi_admin/templates/list.html:167 msgid "prev_page" msgstr "上一页" -#: fastapi_admin/templates/list.html:191 +#: fastapi_admin/templates/list.html:188 msgid "next_page" msgstr "下一页" @@ -151,19 +151,19 @@ msgstr "修改密码" msgid "logout" msgstr "退出登录" -#: fastapi_admin/templates/providers/login/login.html:47 +#: fastapi_admin/templates/providers/login/login.html:49 msgid "login_username_placeholder" msgstr "请输入用户名" -#: fastapi_admin/templates/providers/login/login.html:57 +#: fastapi_admin/templates/providers/login/login.html:59 msgid "login_password_placeholder" msgstr "请输入密码" -#: fastapi_admin/templates/providers/login/login.html:73 +#: fastapi_admin/templates/providers/login/login.html:75 msgid "remember_me" msgstr "记住我" -#: fastapi_admin/templates/providers/login/login.html:78 +#: fastapi_admin/templates/providers/login/login.html:80 msgid "sign_in" msgstr "登录" @@ -190,3 +190,4 @@ msgstr "确认新密码" #: fastapi_admin/templates/providers/login/password.html:29 msgid "re_new_password_placeholder" msgstr "请再次输入新密码" + diff --git a/poetry.lock b/poetry.lock index 4dc72b2..e6337d5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -657,7 +657,7 @@ python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" [[package]] name = "tomli" -version = "1.2.0" +version = "1.2.1" description = "A lil' TOML parser" category = "dev" optional = false @@ -1164,18 +1164,26 @@ pyyaml = [ {file = "PyYAML-5.4.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:bb4191dfc9306777bc594117aee052446b3fa88737cd13b7188d0e7aa8162185"}, {file = "PyYAML-5.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:6c78645d400265a062508ae399b60b8c167bf003db364ecb26dcab2bda048253"}, {file = "PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:4e0583d24c881e14342eaf4ec5fbc97f934b999a6828693a99157fde912540cc"}, + {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:72a01f726a9c7851ca9bfad6fd09ca4e090a023c00945ea05ba1638c09dc3347"}, + {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_s390x.whl", hash = "sha256:895f61ef02e8fed38159bb70f7e100e00f471eae2bc838cd0f4ebb21e28f8541"}, {file = "PyYAML-5.4.1-cp36-cp36m-win32.whl", hash = "sha256:3bd0e463264cf257d1ffd2e40223b197271046d09dadf73a0fe82b9c1fc385a5"}, {file = "PyYAML-5.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:e4fac90784481d221a8e4b1162afa7c47ed953be40d31ab4629ae917510051df"}, {file = "PyYAML-5.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:5accb17103e43963b80e6f837831f38d314a0495500067cb25afab2e8d7a4018"}, {file = "PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e1d4970ea66be07ae37a3c2e48b5ec63f7ba6804bdddfdbd3cfd954d25a82e63"}, + {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:cb333c16912324fd5f769fff6bc5de372e9e7a202247b48870bc251ed40239aa"}, + {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_s390x.whl", hash = "sha256:fe69978f3f768926cfa37b867e3843918e012cf83f680806599ddce33c2c68b0"}, {file = "PyYAML-5.4.1-cp37-cp37m-win32.whl", hash = "sha256:dd5de0646207f053eb0d6c74ae45ba98c3395a571a2891858e87df7c9b9bd51b"}, {file = "PyYAML-5.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf"}, {file = "PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d2d9808ea7b4af864f35ea216be506ecec180628aced0704e34aca0b040ffe46"}, {file = "PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8c1be557ee92a20f184922c7b6424e8ab6691788e6d86137c5d93c1a6ec1b8fb"}, + {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:fd7f6999a8070df521b6384004ef42833b9bd62cfee11a09bda1079b4b704247"}, + {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_s390x.whl", hash = "sha256:bfb51918d4ff3d77c1c856a9699f8492c612cde32fd3bcd344af9be34999bfdc"}, {file = "PyYAML-5.4.1-cp38-cp38-win32.whl", hash = "sha256:fa5ae20527d8e831e8230cbffd9f8fe952815b2b7dae6ffec25318803a7528fc"}, {file = "PyYAML-5.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696"}, {file = "PyYAML-5.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:294db365efa064d00b8d1ef65d8ea2c3426ac366c0c4368d930bf1c5fb497f77"}, {file = "PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:74c1485f7707cf707a7aef42ef6322b8f97921bd89be2ab6317fd782c2d53183"}, + {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:d483ad4e639292c90170eb6f7783ad19490e7a8defb3e46f97dfe4bacae89122"}, + {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_s390x.whl", hash = "sha256:fdc842473cd33f45ff6bce46aea678a54e3d21f1b61a7750ce3c498eedfe25d6"}, {file = "PyYAML-5.4.1-cp39-cp39-win32.whl", hash = "sha256:49d4cdd9065b9b6e206d0595fee27a96b5dd22618e7520c33204a4a3239d5b10"}, {file = "PyYAML-5.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db"}, {file = "PyYAML-5.4.1.tar.gz", hash = "sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"}, @@ -1228,8 +1236,8 @@ toml = [ {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, ] tomli = [ - {file = "tomli-1.2.0-py3-none-any.whl", hash = "sha256:056f0376bf5a6b182c513f9582c1e5b0487265eb6c48842b69aa9ca1cd5f640a"}, - {file = "tomli-1.2.0.tar.gz", hash = "sha256:d60e681734099207a6add7a10326bc2ddd1fdc36c1b0f547d00ef73ac63739c2"}, + {file = "tomli-1.2.1-py3-none-any.whl", hash = "sha256:8dd0e9524d6f386271a36b41dbf6c57d8e32fd96fd22b6584679dc569d20899f"}, + {file = "tomli-1.2.1.tar.gz", hash = "sha256:a5b75cb6f3968abb47af1b40c1819dc519ea82bcc065776a866e8d74c5ca9442"}, ] tortoise-orm = [ {file = "tortoise-orm-0.17.6.tar.gz", hash = "sha256:f4187cd94b838cdf16aaa4e1ec54852d773c1a37a2a510d05f648d7350ab3c6e"},