コード例 #1
0
 def login(self, request):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = user_services.get_and_authenticate_user(
         **serializer.validated_data)
     data = serializers.AuthUserSerializer(user).data
     return response.Ok(data)
コード例 #2
0
 def list(self, request, *args, **kwargs):
     if tenant_from_request(self.request) and team_from_request(self.request):
         team = self.get_queryset().first()
         serializer_class = self.get_serializer_class()
         serializer = serializer_class(team)
         return response.Ok(serializer.data)
     return response.NotFound()
コード例 #3
0
 def password_reset(self, request):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = user_services.get_user_by_email(serializer.data['email'])
     if user:
         services.send_password_reset_mail(user)
     return response.Ok({
         'message':
         'Further instructions will be sent to the email if it exists'
     })
コード例 #4
0
    def remove_employee(self, request):
        company = tenant_from_request(self.request)
        team = team_from_request(self.request)
        if not team or not company:
            return response.NotFound()

        employee = EmployeeModel.objects.filter(company=company).filter(id=request.data['employee']).first()
        if employee:
            queryset = self.get_queryset().first()
            queryset.employees.remove(employee)
            serializer_class = self.get_serializer_class()
            serializer = serializer_class(queryset)
            return response.Ok(serializer.data)

        return response.BadRequest({'error_message': 'Employee not found'})
コード例 #5
0
 def logout(self, request):
     """
     Calls Django logout method; Does not work for UserTokenAuth.
     """
     logout(request)
     return response.Ok({"success": "Successfully logged out."})