Strategies¶
Pydantic-forms uses the strategy pattern to provide for someof the custom logic you may need when dealing with various web frameworks.
All strategies inherit from the BaseStrategy class listed below.
The default strategy that is used is a compatible FastAPI/Starlette strategy.
- class BaseStrategy¶
Determines the logic for using request objects and performing csrf operations
- abstract async attach_csrf(request, csrf)¶
Responsible for attaching the csrf to a medium that the user can later retrieve it from. The DefaultStrategy attaches this to the request session.
- Parameters
request (Any) – The webserver ‘request’ object that is returned from the user.
csrf (str) – The generated csrf token
- Returns
- Return type
The modified request object
- abstract async csrf_check(request, csrf_form_data)¶
Performs the CSRF check logic. An invalid CSRF check will raise CsrfError
- Parameters
request –
csrf_form_data (Optional[str]) –
- Raises
CsrfError – The csrf check was invalid
- Return type
None
- abstract property csrf_key: str¶
The csrf key name that will be embedded into HTML forms
- abstract async get_request_data(request)¶
Extracts form data from the request object provided. The method transforms the results into a Dictionary where the key is the field name and the value is the form data.
- Parameters
request (pydantic_forms.interfaces.Request) – The webserver ‘request’ object that is returned from the user.
- Return type
Dict[str, Any]
- abstract async make_csrf()¶
Responsible for generating the csrf tokens using a specific algorithm.
- Return type
str