-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9052 from OpenMined/feature/reset_password_feature
ADD reset password api
- Loading branch information
Showing
13 changed files
with
902 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0", | ||
"metadata": {}, | ||
"source": [ | ||
"# Forgot User Password" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "1", | ||
"metadata": {}, | ||
"source": [ | ||
"## Initialize the server" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# stdlib\n", | ||
"\n", | ||
"# syft absolute\n", | ||
"import syft as sy\n", | ||
"from syft import SyftError\n", | ||
"from syft import SyftSuccess\n", | ||
"\n", | ||
"server = sy.orchestra.launch(\n", | ||
" name=\"test-datasite-1\",\n", | ||
" dev_mode=True,\n", | ||
" create_producer=True,\n", | ||
" n_consumers=3,\n", | ||
" reset=True,\n", | ||
" port=8081,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "3", | ||
"metadata": {}, | ||
"source": [ | ||
"## Register a new user" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"datasite_client = server.login(email=\"[email protected]\", password=\"changethis\")\n", | ||
"res = datasite_client.register(\n", | ||
" email=\"[email protected]\",\n", | ||
" password=\"verysecurepassword\",\n", | ||
" password_verify=\"verysecurepassword\",\n", | ||
" name=\"New User\",\n", | ||
")\n", | ||
"\n", | ||
"if not isinstance(res, SyftSuccess):\n", | ||
" raise Exception(f\"Res isn't SyftSuccess, its {res}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "5", | ||
"metadata": {}, | ||
"source": [ | ||
"### Ask for a password reset - Notifier disabled Workflow" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6", | ||
"metadata": {}, | ||
"source": [ | ||
"### Call for users.forgot_password" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"guest_client = server.login_as_guest()\n", | ||
"res = guest_client.users.forgot_password(email=\"[email protected]\")\n", | ||
"\n", | ||
"if not isinstance(res, SyftSuccess):\n", | ||
" raise Exception(f\"Res isn't SyftSuccess, its {res}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8", | ||
"metadata": {}, | ||
"source": [ | ||
"### Admin generates a temp token" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"temp_token = datasite_client.users.request_password_reset(\n", | ||
" datasite_client.notifications[-1].linked_obj.resolve.id\n", | ||
")\n", | ||
"\n", | ||
"if not isinstance(temp_token, str):\n", | ||
" raise Exception(f\"temp_token isn't a string, its {temp_token}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "10", | ||
"metadata": {}, | ||
"source": [ | ||
"### User use this token to reset password" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "11", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"res = guest_client.users.reset_password(token=temp_token, new_password=\"Password123\")\n", | ||
"\n", | ||
"if not isinstance(res, SyftSuccess):\n", | ||
" raise Exception(f\"Res isn't SyftSuccess, its {res}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "12", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"new_user_session = server.login(\n", | ||
" email=\"[email protected]\", password=\"Password123\"\n", | ||
")\n", | ||
"\n", | ||
"if isinstance(new_user_session, SyftError):\n", | ||
" raise Exception(f\"Res isn't SyftSuccess, its {new_user_session}\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.