defremind_credentials(request):ifrequest.user.is_authenticated():returnredirect("videos")ifrequest.method=="POST":form=RemindCredentialsForm(request.POST)ifform.is_valid():email=form.cleaned_data.get("email")# validation already checked that user existsu=User.objects.get(email=email)id=uuid.uuid1()redis_key="reset_{}".format(id)settings.REDIS.set(redis_key,u.username)send_remind_credentials_email.delay(u.username,"http://{}/reset_password/{}/".format(settings.BASE_DOMAIN,id),email)messages.add_message(request,messages.SUCCESS,"Se ha enviado un correo electrónico a la dirección ""proporcionada. ""Revisa tu bandeja de entrada para resetear la contraseña.")returnrender(request,"app/message.html")else:form=RemindCredentialsForm()returnrender(request,"app/remind_credentials.html",{"form":form})defreset_password(request,reset_id):ifrequest.user.is_authenticated():returnredirect("videos")redis_key="reset_{}".format(reset_id)ifnotsettings.REDIS.exists(redis_key):messages.add_message(request,messages.ERROR,"Identificador de reseteo de contraseña no encontrado.")url_next=reverse("login")returnrender(request,"app/message.html",{"url_next":url_next})ifrequest.method=="POST":form=ResetPasswordForm(request.POST)ifform.is_valid():password=form.cleaned_data.get("password")username=settings.REDIS.get(redis_key)u=User.objects.get(username=username)u.set_password(password)u.save()messages.add_message(request,messages.SUCCESS,"La contraseña ha sido reestablecida con éxito.")settings.REDIS.delete(redis_key)returnrender(request,"app/message.html",{"url_next":reverse("login")})else:form=ResetPasswordForm()returnrender(request,"app/reset_password.html",{"form":form})
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.