CAT-SOOP is a flexible, programmable learning management system based on the Python programming language. https://catsoop.mit.edu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

44 lines
1.5 KiB

  1. # This file is part of CAT-SOOP
  2. # Copyright (c) 2011-2020 by The CAT-SOOP Developers <catsoop-dev@mit.edu>
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU Affero General Public License as published by the Free
  6. # Software Foundation, either version 3 of the License, or (at your option) any
  7. # later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  12. # details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. def get_logged_in_user(context):
  17. # certificates-based login
  18. env = context["cs_env"]
  19. if "SSL_CLIENT_S_DN_Email" in env:
  20. email = env["SSL_CLIENT_S_DN_Email"]
  21. return {
  22. "username": email.split("@")[0],
  23. "email": email,
  24. "name": env["SSL_CLIENT_S_DN_CN"],
  25. }
  26. elif "SSL_CLIENT_S_DN" in env:
  27. cert_data = {}
  28. for i in env["SSL_CLIENT_S_DN"].split("/"):
  29. try:
  30. k, v = i.split("=")
  31. cert_data[k] = v
  32. except:
  33. pass
  34. email = cert_data.get("emailAddress", "None")
  35. return {
  36. "username": email.split("@")[0],
  37. "email": email,
  38. "name": cert_data.get("CN", email),
  39. }
  40. else:
  41. return {"username": "None"}