我们的团队在后端使用django-rest-api,在前端使用react开发项目。我们使用django-rest-auth进行身份验证,但是我们在密码重置方面遇到了问题。以下是相关链接:
urlpatterns += [
url(r'^accounts/', include('allauth.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include('api.urls')),
url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
url(
r'^rest-auth/password/reset/$',
PasswordResetView.as_view(),
name='password_reset',
),
url(r'^rest-auth/password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
PasswordResetConfirmView.as_view(),
name='password_reset_confirm'),
url(
r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$',
confirm,
name="account_confirm_email"
),
url(r'^', include('core.urls', namespace='core')),
]
当用户提交密码重置请求时,系统会发送包含uid和token的链接到用户邮箱。然后用户填写新密码并提交react表单,我们需要提交以下数据:
```python { "new_password": "新密码", "uid": "用户id", "token": "令牌" } ```{
"new_password1": "new_password",
"new_password2": "new_password",
"uid": "",
"token": ""
}
访问 /rest-auth/password/reset/confirm/ 页面时,我们需要在前端获取uid和token信息,以便制作确认密码重置页面并提交数据进行密码更改的确认。