I doing custom reset password with email confirm.
path('password_reset', views.reset_password_view, name='password-reset'),
path('password_reset/done', views.reset_password_done_view, name='password_reset_done'),
path('reset/<uidb64>/<token>/', views.password_confirm_view, name='password_reset_confirm') #this url
def password_confirm_view(request, uidb64, token):
context = {}
if request.method == 'POST':
form = SetPasswordForm(data=request.POST, user=request.user)
if form.is_valid():
form.save() #I have error
update_session_auth_hash(request, form.user)
return redirect('password_reset_done')
else:
form = SetPasswordForm(user=request.user)
context['form'] = form
return render(request, 'mdm/registration/password_confirm.html', context)
Exception Type:NotImplementedError
Exception Value:Django doesn't provide a DB representation for AnonymousUser.
template:
form enctype="multipart/form-data" method="post">
{% csrf_token %}
<div class="input-group register">
{{ form.new_password1.errors }}
<label for="id_new_password1">Пароль: </label>
{{ form.new_password1 }}
</div>
<div class="input-group register">
{{ form.new_password2.errors }}
<label for="id_new_password2">Подтвердите пароль: </label>
{{ form.new_password2 }}
</div>
<div class="justify-content-center">
<button class="btn btn-block btn-sm btn-info mt-5" type="submit">Сменить пароль</button>
</div>
</form>
I send email for change password for not authorisation user(forgot password). He followed link from email. He must input password and confirm and save form. How i can autherisation user? I think, I must used (uidb64, token).
request.user
. Why are you doing that? The point is that the user is identified by the UID and the token. – Daniel Roseman