From 1c4bdf584d508308ce13e66a403ed214b2d05507 Mon Sep 17 00:00:00 2001 From: Sameer Wagh Date: Thu, 5 Sep 2024 11:09:54 -0400 Subject: [PATCH 01/11] Fixed linting --- .../bigquery/011-users-emails-passwords.ipynb | 89 ++++++++++++++++++- .../service/notification/email_templates.py | 14 ++- 2 files changed, 98 insertions(+), 5 deletions(-) diff --git a/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb b/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb index b3ca595d812..682d7d972f4 100644 --- a/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb +++ b/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb @@ -382,10 +382,86 @@ "save_users(users)" ] }, + { + "cell_type": "markdown", + "id": "29", + "metadata": {}, + "source": [ + "## Testing token expiry" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "29", + "id": "30", + "metadata": {}, + "outputs": [], + "source": [ + "high_client.api.services.settings.update(pwd_token_config={\"token_exp_min\": 1})\n", + "high_client.refresh()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31", + "metadata": {}, + "outputs": [], + "source": [ + "reset_password_user.client.guest().forgot_password(email=reset_password_user.email)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "32", + "metadata": {}, + "outputs": [], + "source": [ + "# Wait one minute\n", + "await asyncio.sleep(60)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "33", + "metadata": {}, + "outputs": [], + "source": [ + "reset_password_user.emails[-1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "34", + "metadata": {}, + "outputs": [], + "source": [ + "# This should throw a SyftError because we waited too long\n", + "output = reset_password_user.client.guest().reset_password(\n", + " token=reset_password_user.reset_token, new_password=reset_password_user.new_password\n", + ")\n", + "output" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35", + "metadata": {}, + "outputs": [], + "source": [ + "# Set things back to the the default settings\n", + "high_client.api.services.settings.update(pwd_token_config={\"token_exp_min\": 30})\n", + "high_client.refresh()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "36", "metadata": {}, "outputs": [], "source": [ @@ -395,7 +471,7 @@ { "cell_type": "code", "execution_count": null, - "id": "30", + "id": "37", "metadata": {}, "outputs": [], "source": [ @@ -405,13 +481,18 @@ { "cell_type": "code", "execution_count": null, - "id": "31", + "id": "38", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, "language_info": { "codemirror_mode": { "name": "ipython", @@ -422,7 +503,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.5" + "version": "3.12.3" } }, "nbformat": 4, diff --git a/packages/syft/src/syft/service/notification/email_templates.py b/packages/syft/src/syft/service/notification/email_templates.py index 2a17a662086..147b2130d54 100644 --- a/packages/syft/src/syft/service/notification/email_templates.py +++ b/packages/syft/src/syft/service/notification/email_templates.py @@ -50,6 +50,18 @@ def email_body(notification: "Notification", context: AuthedServiceContext) -> s if result.is_err(): raise Exception("Couldn't update the user password") + # Get the token expiry time from settings + # relative + from ..settings.settings_service import SettingsService + + method = context.server.get_service_method(SettingsService.get) + settings = method(context=context) + expiry_time = settings.pwd_token_config.token_exp_min + + # settings_service = context.server.get_service("settingsservice") + # settings = settings_service.get(context) + # expiry_time = settings.pwd_token_config.token_exp_min + head = """