Ejemplo n.º 1
0
 def post(self, request, *args, **kwargs):
     resp = super().post(request, *args, **kwargs)
     if resp.status_code == 200 and resp.data['user'].get('table',
                                                          '') == 'staffs':
         if resp.data['user']['is_lock'] is True:
             return err_res('Account locked')
         return resp
     return err_res('Wrong username or password.')
Ejemplo n.º 2
0
 def post(self, request, *args, **kwargs):
     response = super().post(request, *args, **kwargs)
     if response.status_code == 200 and response.data['user'].get(
             'table', '') == 'customers':
         if response.data['user']['is_lock'] is True:
             return err_res('Account locked')
         return response
     return err_res({'detail': 'Wrong username or password.'})
Ejemplo n.º 3
0
 def post(self, request, format=None):
     params = self.request.data
     administrator = self.get_object().administrator
     serializer = AdministratorUpdateSerializer(administrator,
                                                data=params,
                                                partial=True)
     if serializer.is_valid() is True:
         serializer.save()
         return res(serializer.data)
     else:
         return err_res(serializer.errors)
Ejemplo n.º 4
0
    def post(self, request, format=None):
        params = self.request.data

        user = self.get_object()

        # Check correct old password
        if check_password(params["oldPassword"], user.password) is False:
            return err_res({"detail": "Incorrect old password"})

        user.password = make_password(params["password"])
        user.save()

        return res({})
Ejemplo n.º 5
0
    def post(self, request, format=None):
        user = self.get_object()
        obj = user.staff

        data = Tools.parse_user_related_data(request.data)

        userSr = UserSr(user, data=data['user'])
        if userSr.is_valid(raise_exception=True):
            userSr.save()

        remain = data['remain']
        remain.update({'user': user.pk})
        serializer = StaffBaseSr(obj, data=remain)
        if serializer.is_valid(raise_exception=True):
            serializer.save()
            return res(serializer.data)
        else:
            return err_res(serializer.errors)
Ejemplo n.º 6
0
    def post(self, request, format=None):
        user = self.get_object()
        obj = user.customer
        data = request.data
        if (type(request.data) is QueryDict):
            data = request.data.dict()

        data = Tools.parse_user_related_data(data)

        userSr = UserSr(user, data=data['user'])
        if userSr.is_valid(raise_exception=True):
            userSr.save()

        remain = data['remain']
        remain.update({'user': user.pk})
        if type(remain.get('avatar')) is not InMemoryUploadedFile:
            remain.pop('avatar', None)
        serializer = CustomerBaseSr(obj, data=remain)
        if serializer.is_valid(raise_exception=True):
            serializer.save()
            return res(serializer.data)
        else:
            return err_res(serializer.errors)
Ejemplo n.º 7
0
 def post(self, request, *args, **kwargs):
     response = super().post(request, *args, **kwargs)
     if response.status_code == 200 and response.data['user'][
             'table'] == 'administrators':
         return response
     return err_res('Wrong username or password.')