diff options
Diffstat (limited to 'lib/gitlab/auth/omniauth_identity_linker_base.rb')
-rw-r--r-- | lib/gitlab/auth/omniauth_identity_linker_base.rb | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/lib/gitlab/auth/omniauth_identity_linker_base.rb b/lib/gitlab/auth/omniauth_identity_linker_base.rb index 4ed28d6a8be..ae365fcdfaa 100644 --- a/lib/gitlab/auth/omniauth_identity_linker_base.rb +++ b/lib/gitlab/auth/omniauth_identity_linker_base.rb @@ -6,19 +6,41 @@ module Gitlab def initialize(current_user, oauth) @current_user = current_user @oauth = oauth - @created = false + @changed = false end - def created? - @created + def link + save if identity.new_record? + end + + def changed? + @changed end def error_message - '' + identity.validate + + identity.errors.full_messages.join(', ') + end + + private + + def save + @changed = identity.save + end + + def identity + @identity ||= current_user.identities + .with_extern_uid(provider, uid) + .first_or_initialize(extern_uid: uid) + end + + def provider + oauth['provider'] end - def create_or_update - raise NotImplementedError + def uid + oauth['uid'] end end end |