Fix bug where the login service ID doesn't exist
This commit is contained in:
parent
6736e69ebd
commit
421c5d6012
1 changed files with 11 additions and 9 deletions
|
@ -370,6 +370,13 @@ def update_user_metadata(user, given_name=None, family_name=None, company=None):
|
|||
remove_user_prompt(user, UserPromptTypes.ENTER_COMPANY)
|
||||
|
||||
|
||||
def _get_login_service(service_id):
|
||||
try:
|
||||
return LoginService.get(LoginService.name == service_id)
|
||||
except LoginService.DoesNotExist:
|
||||
return LoginService.create(name=service_id)
|
||||
|
||||
|
||||
def create_federated_user(username, email, service_id, service_ident,
|
||||
set_password_notification, metadata={},
|
||||
email_required=True, prompts=tuple()):
|
||||
|
@ -380,12 +387,7 @@ def create_federated_user(username, email, service_id, service_ident,
|
|||
new_user.verified = True
|
||||
new_user.save()
|
||||
|
||||
try:
|
||||
service = LoginService.get(LoginService.name == service_id)
|
||||
except LoginService.DoesNotExist:
|
||||
service = LoginService.create(name=service_id)
|
||||
|
||||
FederatedLogin.create(user=new_user, service=service,
|
||||
FederatedLogin.create(user=new_user, service=_get_login_service(service_id),
|
||||
service_ident=service_ident,
|
||||
metadata_json=json.dumps(metadata))
|
||||
|
||||
|
@ -395,10 +397,10 @@ def create_federated_user(username, email, service_id, service_ident,
|
|||
return new_user
|
||||
|
||||
|
||||
def attach_federated_login(user, service_id, service_ident, metadata={}):
|
||||
service = LoginService.get(LoginService.name == service_id)
|
||||
def attach_federated_login(user, service_id, service_ident, metadata=None):
|
||||
service = _get_login_service(service_id)
|
||||
FederatedLogin.create(user=user, service=service, service_ident=service_ident,
|
||||
metadata_json=json.dumps(metadata))
|
||||
metadata_json=json.dumps(metadata or {}))
|
||||
return user
|
||||
|
||||
|
||||
|
|
Reference in a new issue