<commit_before>from django.conf import settings
from django.contrib.auth.models import User

import requests

OPENJUB_BASE = "https://api.jacobs-cs.club/"

class OjubBackend(object):
	"""
	Authenticates credentials against the OpenJUB database.

	The URL for the server is configured by OPENJUB_BASE in the settings.

	This class does not fill in user profiles, this has to be handled
	in other places
	"""
	def authenticate(self, username=None, password=None):
		r = requests.post(OPENJUB_BASE + "auth/signin",
			data = {'username':username, 'password': password})

		if r.status_code != requests.codes.ok:
			return None

		resp = r.json()

		uname = resp['user']
		token = resp['token']

		try:
			user = User.objects.get(username=uname)
		except User.DoesNotExist:
			user = User(username=uname, password="stored in LDAP")

			# TODO Don't hardcode this
			if user.username in ["lkuboschek", "twiesing"]:
				user.is_staff = True
				user.is_superuser = True

			details = requests.get(OPENJUB_BASE + "user/me",
				params = {'token':token})

			if details.status_code != requests.codes.ok:
				print("Could not get user details")
				return None

			data = details.json()<commit_msg>Set unusable passwords for LDAP users<commit_after>from django.conf import settings
from django.contrib.auth.models import User

import requests

OPENJUB_BASE = "https://api.jacobs-cs.club/"

class OjubBackend(object):
	"""
	Authenticates credentials against the OpenJUB database.

	The URL for the server is configured by OPENJUB_BASE in the settings.

	This class does not fill in user profiles, this has to be handled
	in other places
	"""
	def authenticate(self, username=None, password=None):
		r = requests.post(OPENJUB_BASE + "auth/signin",
			data = {'username':username, 'password': password})

		if r.status_code != requests.codes.ok:
			return None

		resp = r.json()

		uname = resp['user']
		token = resp['token']

		try:
			user = User.objects.get(username=uname)
		except User.DoesNotExist:
			user = User(username=uname)

			user.set_unusable_password()

			# TODO Don't hardcode this
			if user.username in ["lkuboschek", "twiesing"]:
				user.is_staff = True
				user.is_superuser = True

			details = requests.get(OPENJUB_BASE + "user/me",
				params = {'token':token})

			if details.status_code != requests.codes.ok:
				print("Could not get user details")
				return None

			data = details.json()
{'fraction_non_alphanumeric': 0.11254152823920266, 'fraction_numerical': 0.0, 'mean_word_length': 3.9263803680981595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2837350', 'n_tokens_mistral': 872, 'n_tokens_neox': 758, 'n_words': 222}