Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
Django Rest Framework + Serializers + Vue.js, Reset Password Functionality

I am trying to create a reset password functionality, but I can't find a good tutorial that explains how to do that with DRF and Vue.js. I am using serializers to pass the data, so there are no html views involved. What is the most efficient way of creating that Reset Password Functionality?

I am creating new users via /api/v1/users/.

The idea is to send a link via email that leads to ResetPassword.vue (Don't really understand how to do that, can't find good tutorial on that neither) where the user inputs the new password and after pressing submit is redirected to Login.vue.

Any ideas are very appretiated. Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

After trying out and inventing different options, I managed to find one that works the best. Basically, if you are using Django Rest Framework Auth token, in your database you will have a table that will hold Key: (here is user's token) and Name: (here is user's name). So, you create a view that will only have a form with email input and send button. You get the email, post it with Axios to backend and here is the View you will be managing:

@api_view(['POST', 'GET'])
def your_method_name_that_will_be_in_urls_py(request):
    if request.method == "POST":
        serializer = ResetPasswordEmail(data=request.data)
        if serializer.is_valid():

            //Here you get the email from Front-End
            email = serializer.validated_data['email']

            //Here you fin the user that has that email
            user = User.objects.get(email=email)

            //Here you get the token of that user
            token = Token.objects.get(user=user)

            if user:

                //Here you pass the context of things above to send them in an email
                context = {
                    'email': email,
                    'username': user,
                    'token': token
                }

                send_mail(
                    'SUBJECT',
                    render_to_string('emails/reset_password.txt', context),
                    'COMPANY NAME and No Reply',
                    [email],
                    fail_silently=False,
                    auth_user=None, auth_password=None, connection=None, html_message=None
                )
                serializer.save(token=token, slug=token)

            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

And the Serializer like this one:

class ResetPasswordEmail(serializers.ModelSerializer):
    class Meta:
        model = ResetPassword
        fields = (
            'email',
        )

Also, I created a model for that Password Reset:

class ResetPassword(models.Model):
    email = models.CharField(max_length=200, null=True)
    token = models.CharField(max_length=255, null=True)
    slug = models.SlugField(max_length=255)

    def __str__(self):
        return self.token
    //This thing creates users personalized link, that they visit and have a enter new password view in Front-End.
    def get_absolute_url(self):
        return f'/{self.token}/'

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda