Beispiel #1
0
 def put(self, request, id, format=None):
     try:
         obj = self.get_object(id)
         role = request.data['role']
         first_name = request.data['first_name']
         last_name = request.data['last_name']
         mobile_no = request.data['mobile_no']
         address = request.data['address']
         emailId = request.data['emailId']
         password = crypt.crypt(request.data['password'])
         status = request.data['status']
         users = {
             "role": role,
             "first_name": first_name,
             "last_name": last_name,
             "mobile_no": mobile_no,
             "address": address,
             "emailId": emailId,
             "password": password,
             "status": status
         }
         serializer = UserSerializers(obj, data=users)
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data)
         return Response(serializer.error,
                         status=status.HTTP_400_BAD_REQUEST)
     except Http404:
         return JsonResponse({"message": "data not updated"})
Beispiel #2
0
 def get(self, request, id, format=None):
     try:
         get = self.get_object(id)
         serializer = UserSerializers(get)
         return Response(serializer.data)
     except Http404:
         return JsonResponse({"message:": "listings not found"})
Beispiel #3
0
 def put(self, request, id, format=None):
     try:
         obj = self.get_object(id)
         password = crypt.crypt(request.data['password'])
         user = {'password': password}
         serializer = UserSerializers(obj, data=user, partial=True)
         if serializer.is_valid():
             if (serializer.validated_data['password']):
                 serializer.save()
                 return Response({"success": True, "data": serializer.data})
     except:
         obj = self.get_object(id)
         serializer = UserSerializers(obj, data=request.data, partial=True)
         if serializer.is_valid():
             serializer.save()
             return Response({"success": True, "data": serializer.data})
 def get(self, request, *args, **kwargs):
     try:
         get = Users.objects.all()
         serializer = UserSerializers(get, many=True)
         return Response(serializer.data)
     except Users.DoesNotExist:
         raise Http404
 def post(self, request, format=None):
     try:
         serializer = UserSerializers(data=request.data)
         role = request.data['role']
         first_name = request.data['first_name']
         last_name = request.data['last_name']
         mobile_no = request.data['mobile_no']
         address = request.data['address']
         emailId = request.data['emailId']
         password = crypt.crypt(request.data['password'])
         status = request.data['status']
         users = {
             "role": role,
             "first_name": first_name,
             "last_name": last_name,
             "mobile_no": mobile_no,
             "address": address,
             "emailId": emailId,
             "password": password,
             "status": status
         }
         serializer = UserSerializers(data=users)
         if serializer.is_valid():
             serializer.save()
             mail_id = request.data['emailId']
             mail = SendMail.send(mail_id)
             if (mail == 'success'):
                 return JsonResponse({"message": "successfully sent"})
             return Response(serializer.data, status=301)
     except Http404:
         return JsonResponse({"message": "data not added"})
Beispiel #6
0
 def put(self, request, id, format=None):
     try:
         obj = self.get_object(id)
         password = make_password(request.data['password'])
         user = {'password': password}
         serializer = UserSerializers(obj, data=user, partial=True)
         if serializer.is_valid():
             if (serializer.validated_data['password']):
                 serializer.save()
                 mail_id = obj.emailId
                 mail = password_mail.send(mail_id)
                 if (mail == 'success'):
                     return Response(serializer.data)
         return JsonResponse({
             "success": True,
             "data": serializer.errors,
             "message": "password not changed"
         })
     except Http404:
         return JsonResponse({
             "success": False,
             "message": "User password not updated"
         })