Beispiel #1
0
 def post(self, request, **kwargs):
     """ Log in """
     serializer = AuthLoginSerializer(data=request.data,
                                      context={'request': request})
     if serializer.is_valid():
         return Response(data=AuthUserSerializer(request.user).data,
                         status=status.HTTP_201_CREATED)
     else:
         return Response(data=serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Beispiel #2
0
 def post(self, request):
     """
     Change your password
     """
     self.check_object_permissions(request, request.user)
     serializer = self.get_serializer(request.user, request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(status=status.HTTP_200_OK,
                     data=AuthUserSerializer(instance=request.user).data)
Beispiel #3
0
def send_auth_user_updates(sender, instance, **kwargs):
    """Send full details to the user"""
    user = instance
    payload = AuthUserSerializer(user,
                                 context={
                                     'request': AbsoluteURIBuildingRequest()
                                 }).data
    for subscription in ChannelSubscription.objects.recent().filter(user=user):
        send_in_channel(subscription.reply_channel,
                        topic='auth:user',
                        payload=payload)
 def test_fails_if_user_language_is_not_updated(self):
     serializer = AuthUserSerializer(self.user)
     current_language = serializer.data['language']
     serializer.update(self.user, validated_data={'language': 'fr'})
     updated_language = getattr(self.user, 'language')
     self.assertNotEqual(current_language, updated_language)
 def test_instantiation(self):
     serializer = AuthUserSerializer(self.user)
     for k in ['id', 'display_name', 'email']:
         self.assertEqual(serializer.data[k], getattr(self.user, k))