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/channels/in_oauth/utils.py

18 lines
566 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.db.utils import IntegrityError
from passbook.core.models import User
2018-11-11 12:41:48 +00:00
def user_get_or_create(**kwargs):
2018-11-11 12:41:48 +00:00
"""Create user or return existing user"""
try:
new_user = User.objects.create_user(**kwargs)
2018-11-11 12:41:48 +00:00
except IntegrityError:
# At this point we've already checked that there is no existing connection
# to any user. Hence if we can't create the user,
2019-12-31 11:51:16 +00:00
kwargs["username"] = "%s_1" % kwargs["username"]
new_user = User.objects.create_user(**kwargs)
2018-11-11 12:41:48 +00:00
return new_user