mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2026-03-13 07:49:55 +08:00
Bump fastapi from 0.46.0 to 0.47.1 (#92)
* Bump fastapi from 0.46.0 to 0.47.1 Bumps [fastapi](https://github.com/tiangolo/fastapi) from 0.46.0 to 0.47.1. - [Release notes](https://github.com/tiangolo/fastapi/releases) - [Changelog](https://github.com/tiangolo/fastapi/blob/master/docs/history-design-future.md) - [Commits](https://github.com/tiangolo/fastapi/compare/0.46.0...0.47.1) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * Add Request in event_handlers arguments * Bump fastapi Co-authored-by: François Voron <fvoron@gmail.com>
This commit is contained in:
committed by
François Voron
parent
2a537fbb2d
commit
4a7f9e750f
2
Pipfile
2
Pipfile
@@ -27,7 +27,7 @@ bumpversion = "*"
|
||||
httpx-oauth = "*"
|
||||
|
||||
[packages]
|
||||
fastapi = "==0.46.0"
|
||||
fastapi = "==0.47.1"
|
||||
passlib = {extras = ["bcrypt"],version = "==1.7.2"}
|
||||
email-validator = "==1.0.5"
|
||||
sqlalchemy = "==1.3.12"
|
||||
|
||||
8
Pipfile.lock
generated
8
Pipfile.lock
generated
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "ffcf9dc56bced08a8b89ea62bded5e1d716d803bf9497c312dcdf8d89853c9b4"
|
||||
"sha256": "14b374c141f9239db7e5a844426561c1c72dbe48c71479c06da09cb9eac71842"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
@@ -112,11 +112,11 @@
|
||||
},
|
||||
"fastapi": {
|
||||
"hashes": [
|
||||
"sha256:6c9b919f2ed742d2ad78e6dce5ad1be761e67292b838ba114cb525ec784d10a1",
|
||||
"sha256:7f8d795be11e21675b6843424b378fe2ec95a14cecba1c53c68471412cca28c7"
|
||||
"sha256:3130313f23935d99150953422dfe5f6b43f043b6fe3aac22cc4c8d537a4464d9",
|
||||
"sha256:be62491f536dc50041913a37bdcd6b5e05c84e756ff331506b5afeddec859013"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==0.46.0"
|
||||
"version": "==0.47.1"
|
||||
},
|
||||
"idna": {
|
||||
"hashes": [
|
||||
|
||||
@@ -42,7 +42,7 @@ In order to be as unopinionated as possible, we expose decorators that allow you
|
||||
|
||||
### After register
|
||||
|
||||
This event handler is called after a successful registration. It is called with **one argument**: the **user** that has just registered.
|
||||
This event handler is called after a successful registration. It is called with **two argument**: the **user** that has just registered, and the original **`Request` object**.
|
||||
|
||||
Typically, you'll want to **send a welcome e-mail** or add it to your marketing analytics pipeline.
|
||||
|
||||
@@ -52,13 +52,17 @@ Example:
|
||||
|
||||
```py
|
||||
@fastapi_users.on_after_register()
|
||||
def on_after_register(user: User):
|
||||
def on_after_register(user: User, request: Request):
|
||||
print(f"User {user.id} has registered.")
|
||||
```
|
||||
|
||||
### After forgot password
|
||||
|
||||
This event handler is called after a successful forgot password request. It is called with **two arguments**: the **user** which has requested to reset their password and a ready-to-use **JWT token** that will be accepted by the reset password route.
|
||||
This event handler is called after a successful forgot password request. It is called with **three arguments**:
|
||||
|
||||
* The **user** which has requested to reset their password.
|
||||
* A ready-to-use **JWT token** that will be accepted by the reset password route.
|
||||
* The original **`Request` object**.
|
||||
|
||||
Typically, you'll want to **send an e-mail** with the link (and the token) that allows the user to reset their password.
|
||||
|
||||
@@ -68,7 +72,7 @@ Example:
|
||||
|
||||
```py
|
||||
@fastapi_users.on_after_forgot_password()
|
||||
def on_after_forgot_password(user: User, token: str):
|
||||
def on_after_forgot_password(user: User, token: str, request: Request):
|
||||
print(f"User {user.id} has forgot their password. Reset token: {token}")
|
||||
```
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi import Body, Depends, HTTPException
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
from pydantic import EmailStr
|
||||
from starlette import status
|
||||
from starlette.requests import Request
|
||||
from starlette.responses import Response
|
||||
|
||||
from fastapi_users import models
|
||||
@@ -74,7 +75,7 @@ def get_user_router(
|
||||
@router.post(
|
||||
"/register", response_model=user_model, status_code=status.HTTP_201_CREATED
|
||||
)
|
||||
async def register(user: user_create_model): # type: ignore
|
||||
async def register(request: Request, user: user_create_model): # type: ignore
|
||||
user = cast(models.BaseUserCreate, user) # Prevent mypy complain
|
||||
existing_user = await user_db.get_by_email(user.email)
|
||||
|
||||
@@ -90,12 +91,14 @@ def get_user_router(
|
||||
)
|
||||
created_user = await user_db.create(db_user)
|
||||
|
||||
await router.run_handlers(Event.ON_AFTER_REGISTER, created_user)
|
||||
await router.run_handlers(Event.ON_AFTER_REGISTER, created_user, request)
|
||||
|
||||
return created_user
|
||||
|
||||
@router.post("/forgot-password", status_code=status.HTTP_202_ACCEPTED)
|
||||
async def forgot_password(email: EmailStr = Body(..., embed=True)):
|
||||
async def forgot_password(
|
||||
request: Request, email: EmailStr = Body(..., embed=True)
|
||||
):
|
||||
user = await user_db.get_by_email(email)
|
||||
|
||||
if user is not None and user.is_active:
|
||||
@@ -105,7 +108,9 @@ def get_user_router(
|
||||
reset_password_token_lifetime_seconds,
|
||||
reset_password_token_secret,
|
||||
)
|
||||
await router.run_handlers(Event.ON_AFTER_FORGOT_PASSWORD, user, token)
|
||||
await router.run_handlers(
|
||||
Event.ON_AFTER_FORGOT_PASSWORD, user, token, request
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ classifiers = [
|
||||
description-file = "README.md"
|
||||
requires-python = ">=3.7"
|
||||
requires = [
|
||||
"fastapi ==0.46.0",
|
||||
"fastapi ==0.47.1",
|
||||
"passlib[bcrypt] ==1.7.1",
|
||||
"email-validator ==1.0.5",
|
||||
"pyjwt ==1.7.1",
|
||||
|
||||
@@ -5,6 +5,7 @@ import jwt
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from starlette import status
|
||||
from starlette.requests import Request
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
from fastapi_users.authentication import Authenticator
|
||||
@@ -106,6 +107,8 @@ class TestRegister:
|
||||
|
||||
actual_user = event_handler.call_args[0][0]
|
||||
assert actual_user.id == response_json["id"]
|
||||
request = event_handler.call_args[0][1]
|
||||
assert isinstance(request, Request)
|
||||
|
||||
def test_valid_body_is_superuser(self, test_app_client: TestClient, event_handler):
|
||||
json = {
|
||||
@@ -211,6 +214,8 @@ class TestForgotPassword:
|
||||
algorithms=[JWT_ALGORITHM],
|
||||
)
|
||||
assert decoded_token["user_id"] == user.id
|
||||
request = event_handler.call_args[0][2]
|
||||
assert isinstance(request, Request)
|
||||
|
||||
|
||||
@pytest.mark.router
|
||||
|
||||
Reference in New Issue
Block a user