This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/oauth_client/utils.py
2018-12-18 13:24:26 +01:00

17 lines
532 B
Python

"""OAuth Client User Creation Utils"""
from django.contrib.auth import get_user_model
from django.db.utils import IntegrityError
def user_get_or_create(user_model=None, **kwargs):
"""Create user or return existing user"""
if user_model is None:
user_model = get_user_model()
try:
new_user = user_model.objects.create_user(**kwargs)
except IntegrityError:
# TODO: Fix potential username change vuln
new_user = user_model.objects.get(username=kwargs['username'])
return new_user