def authenticate_credentials(self, userid, password): """ Authenticate the userid and password against username and password. """ user = User.objects.authenticate_user(userid, password) if user is not None: return (user, None) raise exceptions.AuthenticationFailed(error_messages.get("invalid_user_or_pass"))
def authenticate_credentials(self, userid, password): """ Authenticate the userid and password against username and password. """ user = User.objects.authenticate_user(userid, password) if user is not None: return (user, None) raise exceptions.AuthenticationFailed( error_messages.get("invalid_user_or_pass"))
def get_by_id(request, id_supply): try: supply = Supply.objects.get_by_id_and_user(id_supply, request.user) return response_commit(model_to_dict(supply)) except ObjectDoesNotExist, e: logger.error(e) return ServiceExceptionSerializer.response_exception(error_messages.get("invalid") % u"Abastecimento")
def get_by_id(request, id_supply): try: supply = Supply.objects.get_by_id_and_user(id_supply, request.user) return response_commit(model_to_dict(supply)) except ObjectDoesNotExist, e: logger.error(e) return ServiceExceptionSerializer.response_exception( error_messages.get("invalid") % u"Abastecimento")
def get_by_id(request, id_car): try: vehicle = Vehicle.objects.get_vehicle_by_id_and_user(id_car, request.user) return response_commit({"id": vehicle.pk, "model": vehicle.model.name, "motor": vehicle.motor, "manufactured": vehicle.manufactured}) except ObjectDoesNotExist, e: logger.error(e) return ServiceExceptionSerializer.response_exception(error_messages.get("invalid") % u"Veículo")
def delete(request, id_user): try: # Valid ID try: is_valid_int_greater_zero_param(id_user) except ValidationError, e: return ValidationExceptionSerializer.response_exception({"id_user": e.messages}) # Find User by ID to check if it exist try: user = User.objects.get_by_pk(id_user) except ObjectDoesNotExist, e: return ServiceExceptionSerializer.response_exception(error_messages.get("invalid") % "Usuário")
def get_by_id(request, id_car): try: vehicle = Vehicle.objects.get_vehicle_by_id_and_user( id_car, request.user) return response_commit({ "id": vehicle.pk, "model": vehicle.model.name, "motor": vehicle.motor, "manufactured": vehicle.manufactured }) except ObjectDoesNotExist, e: logger.error(e) return ServiceExceptionSerializer.response_exception( error_messages.get("invalid") % u"Veículo")
def update(request): try: vehicle = Vehicle.objects.get_by_pk(request.DATA.get('car_id')) serializer = SaveSerializer(clone(vehicle), data=request.DATA) if serializer.is_valid(): vehicle = serializer.object vehicle.save() return response_commit(model_to_dict(vehicle)) else: return ValidationExceptionSerializer.response_exception(serializer.errors) except ObjectDoesNotExist, e: logger.error(e) return ServiceExceptionSerializer.response_exception(error_messages.get("invalid") % u"Veículo")
def update(request): try: user = User.objects.get_by_pk(request.user.id) serializer = UpdateSerializer(clone(user), data=request.DATA) if serializer.is_valid(): user = serializer.object user.save() return response_commit({"user": model_to_dict(user, exclude=["password", "token"])}) else: return ValidationExceptionSerializer.response_exception(serializer.errors) except ObjectDoesNotExist, e: logger.error(e) return ServiceExceptionSerializer.response_exception(error_messages.get("invalid") % "Usuário")
def update(request): try: vehicle = Vehicle.objects.get_by_pk(request.DATA.get('car_id')) serializer = SaveSerializer(clone(vehicle), data=request.DATA) if serializer.is_valid(): vehicle = serializer.object vehicle.save() return response_commit(model_to_dict(vehicle)) else: return ValidationExceptionSerializer.response_exception( serializer.errors) except ObjectDoesNotExist, e: logger.error(e) return ServiceExceptionSerializer.response_exception( error_messages.get("invalid") % u"Veículo")
@renderer_classes(Renderer) def get_by_username(request, username): try: # Valid Username validate_required(username) # Find User by username to check if it exist user = User.objects.get_by_username(username) return response_commit({"user": model_to_dict(user, exclude=["password", "token"])}) except ValidationError, e: return ValidationExceptionSerializer.response_exception({"username": e.messages}) except ObjectDoesNotExist, e: return ObjectDoesNotExistExceptionSerializer.response_exception(error_messages.get("invalid") % "Usuário") except Exception, e: logger.error(e) return ServiceExceptionSerializer.response_exception(error_messages.get("default_error"))