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.
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
|
|
|
|
|
2019-02-27 12:18:16 +00:00
|
|
|
from passbook.core.models import User
|
2018-11-11 12:41:48 +00:00
|
|
|
|
2019-02-27 12:18:16 +00:00
|
|
|
|
2020-05-19 19:53:36 +00:00
|
|
|
def user_get_or_create(**kwargs: str) -> User:
|
2018-11-11 12:41:48 +00:00
|
|
|
"""Create user or return existing user"""
|
|
|
|
try:
|
2019-02-27 12:18:16 +00:00
|
|
|
new_user = User.objects.create_user(**kwargs)
|
2018-11-11 12:41:48 +00:00
|
|
|
except IntegrityError:
|
2019-02-27 12:18:16 +00:00
|
|
|
# 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"]
|
2019-02-27 12:18:16 +00:00
|
|
|
new_user = User.objects.create_user(**kwargs)
|
2018-11-11 12:41:48 +00:00
|
|
|
return new_user
|