PasswordResetConfirmView
This class provides the logic for users to set a new password using a secure, one-time use link. It validates the user identity and token provided in the URL, manages session-based security to prevent token leakage, and optionally logs the user in after a successful password reset.
Attributes
| Attribute | Type | Description |
|---|---|---|
| form_class | [Form](../../../forms/forms/form.md?sid=django_forms_forms_form) = SetPasswordForm | The form class used to set the new password for the user. |
| post_reset_login | boolean = False | A boolean flag indicating whether the user should be automatically logged in after a successful password reset. |
| post_reset_login_backend | string = null | The dotted path to the authentication backend to use when logging the user in after a reset. |
| reset_url_token | string = "set-password" | A placeholder string used in the URL to represent the password reset session after the initial token validation. |
| success_url | string = reverse_lazy("password_reset_complete") | The URL to redirect to after the password has been successfully reset. |
| template_name | string = "registration/password_reset_confirm.html" | The path to the template used to render the password reset confirmation page. |
| title | string = _("Enter new password") | The title displayed on the password reset confirmation page. |
| token_generator | object = default_token_generator | The generator instance used to verify the validity of the password reset token. |
Methods
dispatch()
@classmethod
def dispatch(
*args: tuple,
**kwargs: dict
) - > [HttpResponse](../../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Validates the reset token and user ID from the URL, managing session security to prevent token leakage before rendering the view.
Parameters
| Name | Type | Description |
|---|---|---|
| *args | tuple | Variable positional arguments passed to the view. |
| **kwargs | dict | Keyword arguments containing 'uidb64' and 'token' required for user identification and validation. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | An HTTP response that either displays the password reset form, redirects to a secure URL, or shows a failure message. |
get_user()
@classmethod
def get_user(
uidb64: string
) - > User|None
Retrieves the user object corresponding to the provided base64-encoded primary key.
Parameters
| Name | Type | Description |
|---|---|---|
| uidb64 | string | The base64-encoded string representing the user's primary key. |
Returns
| Type | Description |
|---|---|
| `User | None` |
get_form_kwargs()
@classmethod
def get_form_kwargs() - > dict
Injects the retrieved user instance into the keyword arguments used to instantiate the password reset form.
Returns
| Type | Description |
|---|---|
dict | A dictionary of arguments including the 'user' object required by SetPasswordForm. |
form_valid()
@classmethod
def form_valid(
form: [Form](../../../forms/forms/form.md?sid=django_forms_forms_form)
) - > [HttpResponse](../../../http/response/httpresponse.md?sid=django_http_response_httpresponse)
Saves the new password, clears the temporary reset token from the session, and optionally logs the user in.
Parameters
| Name | Type | Description |
|---|---|---|
| form | [Form](../../../forms/forms/form.md?sid=django_forms_forms_form) | The validated form instance containing the new password data. |
Returns
| Type | Description |
|---|---|
[HttpResponse](../../../http/response/httpresponse.md?sid=django_http_response_httpresponse) | A redirect to the success URL after the password has been successfully updated. |
get_context_data()
@classmethod
def get_context_data(
**kwargs: dict
) - > dict
Builds the template context, including the 'validlink' status and appropriate page titles based on token validity.
Parameters
| Name | Type | Description |
|---|---|---|
| **kwargs | dict | Additional keyword arguments to be included in the template context. |
Returns
| Type | Description |
|---|---|
dict | The context dictionary used to render the password reset confirmation or failure template. |