6
votes

Our team works on project with django-rest-api on backend and react on frontend. For authentication we use django-rest-auth, and we have problem with password reset. Here urls:

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

When request to password_reset is posted, user receives email with link contains uid and token. Then user fills new_password in react form, and we want post data:

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

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

How we may to obtain this uid and token on frontend for make page with confirm password reset on this url, and then post data for confirm password change?

1
Can't you just take the uid and token from the page url? That is how the similar built-in functionality in Django does it. You can grab the url with javascript. Here's the actual implementation of password reset tokens, btw. github.com/django/django/blob/master/django/contrib/auth/…Håken Lid

1 Answers

9
votes

You should configure your react router to get the params from url. For eg,

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

And then in your react view you can get these values like this.props.params.uid and this.props.params.token.