Skip to content

Commit

Permalink
Merge pull request teamhephy#75 from jianxiaoguo/main
Browse files Browse the repository at this point in the history
chore(oauth2): update user info pipline
  • Loading branch information
duanhongyi authored Mar 11, 2022
2 parents 17b7a70 + fec95b2 commit 4f6e169
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion rootfs/api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def _get_user(key):
user_info = OAuthManager().get_user_by_token(key)
if not user_info.get('email'):
user_info['email'] = OAuthManager().get_email_by_token(key)
return serializers.UserSerializer.update_or_create(user_info)
user, _ = serializers.UserSerializer.update_or_create(user_info)
return user
except Exception as e:
logger.info(e)
raise exceptions.AuthenticationFailed(_('Verify token fail.'))
2 changes: 1 addition & 1 deletion rootfs/api/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def authenticate(self, request, username=None, password=None, **kwargs):
user_info['password'] = password
if not user_info.get('email'):
user_info['email'] = client.get_email()
user = serializers.UserSerializer.update_or_create(user_info)
user, _ = serializers.UserSerializer.update_or_create(user_info)
return user

def get_user(self, user_id):
Expand Down
10 changes: 9 additions & 1 deletion rootfs/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@


def update_or_create(backend, user, response, *args, **kwargs):
UserSerializer.update_or_create(response)
user, created = UserSerializer.update_or_create(response)

if not created:
return {'is_new': False}

return {
'is_new': True,
'user': user
}


def load_extra_data(backend, details, response, uid, user, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion rootfs/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def update_or_create(data):
user.date_joined = now
user.set_unusable_password()
user.save()
return user
return user, created


class AdminUserSerializer(serializers.ModelSerializer):
Expand Down

0 comments on commit 4f6e169

Please sign in to comment.