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.')
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.'})
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)
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({})
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)
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)
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.')