summaryrefslogtreecommitdiff
path: root/lib/gitlab/o_auth/auth_hash.rb
diff options
context:
space:
mode:
authorClement Ho <clemmakesapps@gmail.com>2018-03-01 22:33:29 +0000
committerClement Ho <clemmakesapps@gmail.com>2018-03-01 22:33:29 +0000
commitb112a33b98c657b1d2838c14d598a291a14565e0 (patch)
treea37cc22491baf419a15b81918ee07c2fd0d8f2da /lib/gitlab/o_auth/auth_hash.rb
parent4441ca4ba7bf6c4a68574d018d2bf48e45326654 (diff)
parent5c4eace67f188da436b3b380a0125d053b29422a (diff)
downloadgitlab-ce-sentiment-analysis.tar.gz
Merge branch 'master' into 'sentiment-analysis'sentiment-analysis
# Conflicts: # app/assets/javascripts/notes/components/comment_form.vue
Diffstat (limited to 'lib/gitlab/o_auth/auth_hash.rb')
-rw-r--r--lib/gitlab/o_auth/auth_hash.rb90
1 files changed, 0 insertions, 90 deletions
diff --git a/lib/gitlab/o_auth/auth_hash.rb b/lib/gitlab/o_auth/auth_hash.rb
deleted file mode 100644
index 5b5ed449f94..00000000000
--- a/lib/gitlab/o_auth/auth_hash.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-# Class to parse and transform the info provided by omniauth
-#
-module Gitlab
- module OAuth
- class AuthHash
- attr_reader :auth_hash
- def initialize(auth_hash)
- @auth_hash = auth_hash
- end
-
- def uid
- @uid ||= Gitlab::Utils.force_utf8(auth_hash.uid.to_s)
- end
-
- def provider
- @provider ||= auth_hash.provider.to_s
- end
-
- def name
- @name ||= get_info(:name) || "#{get_info(:first_name)} #{get_info(:last_name)}"
- end
-
- def username
- @username ||= username_and_email[:username].to_s
- end
-
- def email
- @email ||= username_and_email[:email].to_s
- end
-
- def password
- @password ||= Gitlab::Utils.force_utf8(Devise.friendly_token[0, 8].downcase)
- end
-
- def location
- location = get_info(:address)
- if location.is_a?(Hash)
- [location.locality.presence, location.country.presence].compact.join(', ')
- else
- location
- end
- end
-
- def has_attribute?(attribute)
- if attribute == :location
- get_info(:address).present?
- else
- get_info(attribute).present?
- end
- end
-
- private
-
- def info
- auth_hash.info
- end
-
- def get_info(key)
- value = info[key]
- Gitlab::Utils.force_utf8(value) if value
- value
- end
-
- def username_and_email
- @username_and_email ||= begin
- username = get_info(:username).presence || get_info(:nickname).presence
- email = get_info(:email).presence
-
- username ||= generate_username(email) if email
- email ||= generate_temporarily_email(username) if username
-
- {
- username: username,
- email: email
- }
- end
- end
-
- # Get the first part of the email address (before @)
- # In addtion in removes illegal characters
- def generate_username(email)
- email.match(/^[^@]*/)[0].mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/, '').to_s
- end
-
- def generate_temporarily_email(username)
- "temp-email-for-oauth-#{username}@gitlab.localhost"
- end
- end
- end
-end