accountservlet.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from __future__ import absolute_import
  16. from twisted.web.resource import Resource
  17. from sydent.http.servlets import jsonwrap, send_cors
  18. from sydent.http.auth import authIfV2
  19. class AccountServlet(Resource):
  20. isLeaf = False
  21. def __init__(self, syd):
  22. Resource.__init__(self)
  23. self.sydent = syd
  24. @jsonwrap
  25. def render_GET(self, request):
  26. """
  27. Return information about the user's account
  28. (essentially just a 'who am i')
  29. """
  30. send_cors(request)
  31. account = authIfV2(self.sydent, request)
  32. return {
  33. "user_id": account.userId,
  34. }
  35. def render_OPTIONS(self, request):
  36. send_cors(request)
  37. return b''