Example #1
0
def change_email_endpoint(request, pk=None):
    serializer = ChangeEmailSerializer(
        data=request.data,
        context={'user': request.user},
    )

    if serializer.is_valid():
        token = store_new_credential(request, 'email',
                                     serializer.validated_data['new_email'])

        mail_subject = _("Confirm e-mail change on %(forum_name)s forums")
        mail_subject = mail_subject % {'forum_name': settings.forum_name}

        # swap address with new one so email is sent to new address
        request.user.email = serializer.validated_data['new_email']

        mail_user(request.user,
                  mail_subject,
                  'misago/emails/change_email',
                  context={'token': token})

        message = _("E-mail change confirmation link was sent to new address.")
        return Response({'detail': message})
    else:
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    def test_invalid_token_is_handled(self):
        """there are no explosions in invalid tokens handling"""
        request = MockRequest(self.user)
        token = credentialchange.store_new_credential(request, 'email', '*****@*****.**')

        email = credentialchange.read_new_credential(request, 'em4il', token)
        self.assertIsNone(email)
    def test_valid_token_generation(self):
        """credentialchange module allows for store and read of change token"""
        request = MockRequest(self.user)
        token = credentialchange.store_new_credential(request, 'email', '*****@*****.**')

        email = credentialchange.read_new_credential(request, 'email', token)
        self.assertEqual(email, '*****@*****.**')
    def test_invalid_token_is_handled(self):
        """there are no explosions in invalid tokens handling"""
        request = MockRequest(self.user)
        token = credentialchange.store_new_credential(request, 'email',
                                                      '*****@*****.**')

        email = credentialchange.read_new_credential(request, 'em4il', token)
        self.assertIsNone(email)
    def test_valid_token_generation(self):
        """credentialchange module allows for store and read of change token"""
        request = MockRequest(self.user)
        token = credentialchange.store_new_credential(request, 'email',
                                                      '*****@*****.**')

        email = credentialchange.read_new_credential(request, 'email', token)
        self.assertEqual(email, '*****@*****.**')
    def test_password_change_invalidated_token(self):
        """token is invalidated by password change"""
        request = MockRequest(self.user)
        token = credentialchange.store_new_credential(request, 'email', '*****@*****.**')

        self.user.set_password('Egebeg!123')
        self.user.save()

        email = credentialchange.read_new_credential(request, 'email', token)
        self.assertIsNone(email)
    def test_password_change_invalidated_token(self):
        """token is invalidated by password change"""
        request = MockRequest(self.user)
        token = credentialchange.store_new_credential(request, 'email',
                                                      '*****@*****.**')

        self.user.set_password('Egebeg!123')
        self.user.save()

        email = credentialchange.read_new_credential(request, 'email', token)
        self.assertIsNone(email)
Example #8
0
def change_password_endpoint(request, pk=None):
    form = ChangePasswordForm(request.data, user=request.user)
    if form.is_valid():
        token = store_new_credential(
            request, 'password', form.cleaned_data['new_password'])

        mail_subject = _("Confirm password change on %(forum_title)s forums")
        mail_subject = mail_subject % {'forum_title': settings.forum_name}

        mail_user(request, request.user, mail_subject,
                  'misago/emails/change_password',
                  {'token': token})

        return Response({'detail': _("Password change confirmation link "
                                     "was sent to your address.")})
    else:
        return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
Example #9
0
def change_password_endpoint(request, pk=None):
    form = ChangePasswordForm(request.data, user=request.user)
    if form.is_valid():
        token = store_new_credential(
            request, 'password', form.cleaned_data['new_password'])

        mail_subject = _("Confirm password change on %(forum_name)s forums")
        mail_subject = mail_subject % {'forum_name': settings.forum_name}

        mail_user(request, request.user, mail_subject,
                  'misago/emails/change_password',
                  {'token': token})

        return Response({'detail': _("Password change confirmation link "
                                     "was sent to your address.")})
    else:
        return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
Example #10
0
def change_password_endpoint(request, pk=None):
    serializer = ChangePasswordSerializer(
        data=request.data,
        context={'user': request.user},
    )

    serializer.is_valid(raise_exception=True)

    token = store_new_credential(request, 'password',
                                 serializer.validated_data['new_password'])

    mail_subject = _("Confirm password change on %(forum_name)s forums")
    mail_subject = mail_subject % {'forum_name': settings.forum_name}

    mail_user(request, request.user, mail_subject,
              'misago/emails/change_password', {'token': token})

    return Response(status=204)
Example #11
0
def handle_form_submission(request):
    form = ChangeEmailForm(request.data, user=request.user)
    if form.is_valid():
        token = store_new_credential(request, 'email',
                                     form.cleaned_data['new_email'])

        mail_subject = _("Confirm e-mail change on %(forum_title)s forums")
        mail_subject = mail_subject % {'forum_title': settings.forum_name}

        # swap address with new one so email is sent to new address
        request.user.email = form.cleaned_data['new_email']

        mail_user(request, request.user, mail_subject,
                  'misago/emails/change_email', {'token': token})

        message = _("E-mail change confirmation link was sent to new address.")
        return Response({'detail': message})
    else:
        return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
Example #12
0
def change_email_endpoint(request, pk=None):
    form = ChangeEmailForm(request.data, user=request.user)
    if form.is_valid():
        token = store_new_credential(
            request, 'email', form.cleaned_data['new_email'])

        mail_subject = _("Confirm e-mail change on %(forum_title)s forums")
        mail_subject = mail_subject % {'forum_title': settings.forum_name}

        # swap address with new one so email is sent to new address
        request.user.email = form.cleaned_data['new_email']

        mail_user(request, request.user, mail_subject,
                  'misago/emails/change_email',
                  {'token': token})

        message = _("E-mail change confirmation link was sent to new address.")
        return Response({'detail': message})
    else:
        return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
Example #13
0
def change_password_endpoint(request, pk=None):
    serializer = ChangePasswordSerializer(data=request.data,
                                          context={'user': request.user})

    if serializer.is_valid():
        token = store_new_credential(request, 'password',
                                     serializer.validated_data['new_password'])

        mail_subject = _("Confirm password change on %(forum_name)s forums")
        mail_subject = mail_subject % {'forum_name': settings.forum_name}

        mail_user(request, request.user, mail_subject,
                  'misago/emails/change_password', {'token': token})

        return Response({
            'detail':
            _("Password change confirmation link was sent to your address.")
        })
    else:
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Example #14
0
def change_email_endpoint(request, pk=None):
    serializer = ChangeEmailSerializer(
        data=request.data,
        context={'user': request.user},
    )

    serializer.is_valid(raise_exception=True)

    token = store_new_credential(request, 'email',
                                 serializer.validated_data['new_email'])

    mail_subject = _("Confirm e-mail change on %(forum_name)s forums")
    mail_subject = mail_subject % {'forum_name': settings.forum_name}

    # swap address with new one so email is sent to new address
    request.user.email = serializer.validated_data['new_email']

    mail_user(request, request.user, mail_subject,
              'misago/emails/change_email', {'token': token})

    return Response(status=204)