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

17 lines
532 B
Python
Raw Normal View History

2018-12-18 12:24:26 +00:00
"""OAuth Client User Creation Utils"""
2018-11-11 12:41:48 +00:00
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:
2018-12-18 12:24:26 +00:00
# TODO: Fix potential username change vuln
2018-11-11 12:41:48 +00:00
new_user = user_model.objects.get(username=kwargs['username'])
return new_user