Exemple #1
0
 def post(self, request):
     form_data = request.data.dict()
     user = None
     if 'type' not in form_data:
         return Response(data=json.dumps(
             {'error': 'Login type not specified'}),
                         status=status.HTTP_400_BAD_REQUEST)
     elif form_data.get('type') not in ['admin', 'biller', 'customer']:
         return Response(data=json.dumps(
             {'error': 'Login type inappropriate'}),
                         status=status.HTTP_400_BAD_REQUEST)
     try:
         user = Mywallet.objects.filter(
             (Q(user__email=form_data.get('email', ''))
              | Q(user__username=form_data.get('username', ''))
              | Q(contact_number=form_data.get('contact_number', ''))),
             user__is_active=True,
             user__is_staff=True
             if form_data.get('type') is 'admin' else False,
         ).first()
     except Exception as e:
         Response(data=json.dumps({'error': 'DB error'}),
                  status=status.HTTP_404_NOT_FOUND)
     if user is None:
         user = User.objects.create_user(
             form_data.get('username', ''),
             email=form_data.get('email', ''),
             password=form_data.get('password', ''),
             **{
                 'first_name': form_data.get('first-name', ''),
                 'last_name': form_data.get('last-name', ''),
             })
         if form_data.get('type') == 'biller':
             user.is_active = False
             user.save()
         mywallet_user = Mywallet.objects.create(
             user=user, contact_number=form_data.get('contact_number'))
         if form_data.get('type') == 'admin':
             serializer = MywalletSerializer(mywallet_user)
         elif form_data.get('type') == 'biller':
             serializer = BillerSerializer(
                 Biller.objects.create(biller=mywallet_user))
         elif form_data.get('type') == 'customer':
             serializer = CustomerSerializer(
                 Customer.objects.create(customer=mywallet_user))
         return Response(serializer.data)
     Response(data=json.dumps(
         {'error': 'Username / EmailID already in use'}),
              status=status.HTTP_400_BAD_REQUEST)
Exemple #2
0
 def post(self, request, user_id):
     current_user = request.user
     if current_user.is_staff:
         try:
             biller = self.get_object(user_id)
             biller.biller.user.is_active = True
             biller.commission = float(request.data.get('commission',
                                                        0.0)) / 100.0
             biller.save()
             serializer = BillerSerializer(biller)
             return Response(serializer.data)
         except Exception as e:
             Response(data=json.dumps({'error': 'DB error'}),
                      status=status.HTTP_404_NOT_FOUND)
     return Response(data=json.dumps({'error': 'Unauthorized'}),
                     status=status.HTTP_404_UNAUTHORIZED)
Exemple #3
0
 def post(self, request, user_id):
     try:
         print ">>>>>>>>>>>"
         form_data = request.data.dict()
         print "form_data", form_data
         user = User.objects.get(id=user_id)
         user.is_active = True
         user.save()
         biller = self.get_object(user_id)
         biller.commission = float(form_data.get('commission', 0.0)) / 100.0
         biller.save()
         serializer = BillerSerializer(biller)
         return Response(serializer.data)
     except Exception as e:
         Response(data=json.dumps({'error': 'DB error'}),
                  status=status.HTTP_404_NOT_FOUND)
Exemple #4
0
 def get(self, request, user_id=None):
     biller = None
     print "+++++++++++"
     try:
         if user_id is None:
             biller = self.get_object()
         else:
             biller = self.get_object(user_id)
         if biller is not None:
             print "MMMMMMMMMMMMM", biller
             serializer = BillerSerializer(
                 biller,
                 many=True if isinstance(biller, QuerySet) else False)
             return Response(serializer.data)
         return Response(data=json.dumps(
             {'error': 'Please contact MyWallet to activate your account'}),
                         status=status.HTTP_400_BAD_REQUEST)
     except Exception as e:
         return Response(data=json.dumps({'error': 'Unauthorized'}),
                         status=status.HTTP_404_UNAUTHORIZED)
Exemple #5
0
 def post(self, request):
     form_data = request.data.dict()
     mywallet_user = None
     if 'type' not in form_data:
         return Response(data=json.dumps(
             {'error': 'Login type not specified'}),
                         status=status.HTTP_400_BAD_REQUEST)
     elif form_data.get('type') not in ['admin', 'biller', 'customer']:
         return Response(data=json.dumps(
             {'error': 'Login type inappropriate'}),
                         status=status.HTTP_400_BAD_REQUEST)
     try:
         mywallet_user = Mywallet.objects.filter(
             (Q(user__email=form_data.get('username', ''))
              | Q(user__username=form_data.get('username', ''))
              | Q(contact_number=form_data.get('username', ''))),
             user__is_active=True,
             user__is_staff=True
             if form_data.get('type') == u'admin' else False,
         ).first()
     except Exception as e:
         Response(data=json.dumps({'error': 'DB error'}),
                  status=status.HTTP_404_NOT_FOUND)
     if mywallet_user is not None:
         if form_data.get('type') == 'admin':
             serializer = MywalletSerializer(mywallet_user)
         elif form_data.get('type') == 'biller':
             serializer = BillerSerializer(
                 Biller.objects.get(biller__user__id=mywallet_user.user.id))
         elif form_data.get('type') == 'customer':
             serializer = CustomerSerializer(
                 Customer.objects.get(
                     customer__user__id=mywallet_user.user.id))
         return Response(serializer.data)
     return Response(data=json.dumps({'error': 'Unauthorized'}),
                     status=status.HTTP_404_UNAUTHORIZED)