2016-11-23 28 views
1

我们的团队使用django-rest-api在后端工作,并在前端做出反应。 对于身份验证,我们使用django-rest-auth,并且我们在密码重置时遇到问题。 这里网址:django-rest-auth重置密码uid和令牌

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')), 
] 

当请求password_reset张贴,用户将收到链接的电子邮件中包含uid和令牌。然后用户填写反馈形式的new_password,并且我们想要发布数据:

{ 
    "new_password1": "new_password", 
    "new_password2": "new_password", 
    "uid": "", 
    "token": "" 
} 

to/rest-auth/password/reset/confirm /。

我们如何在前端获取此uid和令牌以使页面在此URL上确认密码重置,然后发布确认密码更改的数据?

+0

难道你不能只是从页面的URL获取uid和令牌吗?这就是Django中类似的内置功能所做的。您可以使用javascript获取网址。这是密码重置令牌的实际实现,顺便说一句。 https://github.com/django/django/blob/master/django/contrib/auth/tokens.py –

回答

3

您应该配置您的反应路由器以获得params from url。对于例如,

<Route path="reset/:uid/:token" component={PasswordResetView}/> 

然后在你反应过来查看您可以得到像this.props.params.uidthis.props.params.token这些值。

相关问题