Exemplo n.º 1
0
    def create(self, request, *args, **kwargs):

        try:
            request.data['username'] = request.data.get('email')
            user_serializer = UserSerializer(data=request.data, partial=False)
            if user_serializer.is_valid():
                user_serializer.save()
                email = request.data['email']
                last_user = User.objects.get(email=email)
                activation_code = random_string()
                code_data = {
                    'requester_id': last_user.id,
                    'type': 'registration',
                    'code': activation_code,
                    'expiry': datetime.now(tz=timezone.utc) + timedelta(days=1)
                }
                code_serializer = CodeSerializer(data=code_data)
                if code_serializer.is_valid():
                    code_serializer.save()
                    send_luna_emails(last_user, 'activation', activation_code)
                    return Response(None, status=status.HTTP_204_NO_CONTENT)
                else:
                    return Response(code_serializer.errors,
                                    status=status.HTTP_400_BAD_REQUEST)
            return Response(user_serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
        except AttributeError as e:
            return Response(str(e), status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
	def put(self,request,user_id):
		try:
			get_data = UserProfile.objects.get(pk=user_id)
			update_data = UserSerializer(get_data,data=request.data)
			if update_data.is_valid():
				update_data.save()
				return Response(update_data.data)
		except:
			return Response("Error" ,status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 3
0
    def put(self, request, *args, **kwargs):
        serializer_data = request.data.get('user', {})

        serializer = UserSerializer(request.user,
                                    data=serializer_data,
                                    partial=True)
        serializer.is_valid(raise_exception=True)
        serializer.save()

        return Response(serializer.data, status=status.HTTP_200_OK)
Exemplo n.º 4
0
 def patch(self, request, *args, **kwargs):
     request.data['username'] = request.data.get('email')
     serializer = UserSerializer(request.user,
                                 data=request.data,
                                 partial=True)
     if serializer.is_valid():
         serializer.save()
         return Response(None, status=status.HTTP_204_NO_CONTENT)
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 5
0
	def post(self,request):
		try:
			
			user = self.create_user(request)
			if not(user):
				return Response("Error while create user",status=status.HTTP_404_NOT_FOUND)

			self.overWrite(request, {'user':user.id})
			print(request.data)	
			user_data = UserSerializer(data=request.data)
			if not(user_data.is_valid()):
				return Response(user_data.errors,status=status.HTTP_404_NOT_FOUND)
			user_data.save()
			return Response(user_data.data,status=status.HTTP_201_CREATED)
		except Exception as err:
			print(err)
			return Response("Error",status=status.HTTP_404_NOT_FOUND)
Exemplo n.º 6
0
    def post(self, request, *args, **kwargs):

        try:
            code_entry = ActivationCodes.objects.get(
                code=self.kwargs.get('code'))
            user = User.objects.get(id=code_entry.requester_id_id)

            if code_entry.expiry > datetime.now(tz=timezone.utc):
                user_serializer = UserSerializer(user,
                                                 data={'is_active': True},
                                                 partial=True)
                if user_serializer.is_valid():
                    user_serializer.save()
                    return Response(None, status=status.HTTP_204_NO_CONTENT)
                return Response('Input validation error',
                                status=status.HTTP_400_BAD_REQUEST)
            else:
                return Response('Activation code has expired',
                                status=status.HTTP_422_UNPROCESSABLE_ENTITY)
        except User.DoesNotExist as e:
            return Response(str(e), status=status.HTTP_404_NOT_FOUND)
        except ActivationCodes.DoesNotExist as e:
            return Response(str(e), status=status.HTTP_404_NOT_FOUND)
Exemplo n.º 7
0
 def post(self, request):
     user = request.data
     serializer = UserSerializer(data=user)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return Response(serializer.data, status=status.HTTP_201_CREATED)