Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-04-07 18:15:31 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-04-07 18:15:31 +0400
commit650d0bc695eb0f874561b8d4ed3fc86510573fba (patch)
tree70da3eb09b3d8f0e34997158272cf36c8e7fe0fa
parent5d6e9ea8efa07d5342857de0772b59a4c5092f60 (diff)
parente6f58cb87da914f2a424df66b680e19e49dcd2e6 (diff)
Merge branch 'improve-oauth'
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Conflicts: CHANGELOG
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/application_controller.rb7
-rw-r--r--app/controllers/profiles/emails_controller.rb2
-rw-r--r--app/controllers/profiles_controller.rb1
-rw-r--r--app/models/user.rb8
-rw-r--r--app/views/devise/sessions/_oauth_providers.html.haml2
-rw-r--r--app/views/profiles/show.html.haml5
-rw-r--r--lib/gitlab/oauth/user.rb13
-rw-r--r--spec/lib/oauth_spec.rb1
9 files changed, 35 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index a6f2b36d31c..f0a72710a92 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,7 @@ v 6.8.0
- Protected branch does not allow force push
- Fix popen bug in `rake gitlab:satellites:create`
- Disable connection reaping for MySQL
+ - Allow oauth signup without email for twitter and github
v 6.7.3
- Fix the merge notification email not being sent (Pierre de La Morinerie)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 5f8b2da06f8..a3f39c23e08 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base
before_filter :default_headers
before_filter :add_gon_variables
before_filter :configure_permitted_parameters, if: :devise_controller?
+ before_filter :require_email, unless: :devise_controller?
protect_from_forgery
@@ -234,4 +235,10 @@ class ApplicationController < ActionController::Base
def hexdigest(string)
Digest::SHA1.hexdigest string
end
+
+ def require_email
+ if current_user && current_user.temp_oauth_email?
+ redirect_to profile_path, notice: 'Please complete your profile with email address' and return
+ end
+ end
end
diff --git a/app/controllers/profiles/emails_controller.rb b/app/controllers/profiles/emails_controller.rb
index 9996b67a8a4..40c352dab0c 100644
--- a/app/controllers/profiles/emails_controller.rb
+++ b/app/controllers/profiles/emails_controller.rb
@@ -8,7 +8,7 @@ class Profiles::EmailsController < ApplicationController
def create
@email = current_user.emails.new(params[:email])
-
+
flash[:alert] = @email.errors.full_messages.first unless @email.save
redirect_to profile_emails_url
diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb
index 9234cd1708f..9c9a129b26b 100644
--- a/app/controllers/profiles_controller.rb
+++ b/app/controllers/profiles_controller.rb
@@ -3,6 +3,7 @@ class ProfilesController < ApplicationController
before_filter :user
before_filter :authorize_change_username!, only: :update_username
+ skip_before_filter :require_email, only: [:show, :update]
layout 'profile'
diff --git a/app/models/user.rb b/app/models/user.rb
index 25c10a6faa0..58d90f03b34 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -462,4 +462,12 @@ class User < ActiveRecord::Base
def all_ssh_keys
keys.map(&:key)
end
+
+ def temp_oauth_email?
+ email =~ /\Atemp-email-for-oauth/
+ end
+
+ def generate_tmp_oauth_email
+ self.email = "temp-email-for-oauth-#{username}@gitlab.localhost"
+ end
end
diff --git a/app/views/devise/sessions/_oauth_providers.html.haml b/app/views/devise/sessions/_oauth_providers.html.haml
index 2b1cb9c694f..f4556eea4a2 100644
--- a/app/views/devise/sessions/_oauth_providers.html.haml
+++ b/app/views/devise/sessions/_oauth_providers.html.haml
@@ -9,5 +9,3 @@
= link_to authbutton(provider, 32), omniauth_authorize_path(resource_name, provider)
- else
= link_to provider.to_s.titleize, omniauth_authorize_path(resource_name, provider), class: "btn"
- %br
- %small * Make sure your email address is public
diff --git a/app/views/profiles/show.html.haml b/app/views/profiles/show.html.haml
index 26e9f22c3cc..69598e799e5 100644
--- a/app/views/profiles/show.html.haml
+++ b/app/views/profiles/show.html.haml
@@ -30,7 +30,10 @@
%span.help-block.light
Email is read-only for LDAP user
- else
- = f.text_field :email, class: "form-control", required: true
+ - if @user.temp_oauth_email?
+ = f.text_field :email, class: "form-control", required: true, value: nil
+ - else
+ = f.text_field :email, class: "form-control", required: true
- if @user.unconfirmed_email.present?
%span.help-block
Please click the link in the confirmation email before continuing, it was send to
diff --git a/lib/gitlab/oauth/user.rb b/lib/gitlab/oauth/user.rb
index 529753c4019..1bac93378ef 100644
--- a/lib/gitlab/oauth/user.rb
+++ b/lib/gitlab/oauth/user.rb
@@ -29,6 +29,17 @@ module Gitlab
user = model.build_user(opts, as: :admin)
user.skip_confirmation!
+
+ # Services like twitter and github does not return email via oauth
+ # In this case we generate temporary email and force user to fill it later
+ if user.email.blank?
+ user.generate_tmp_oauth_email
+ else
+ # Google oauth returns email but dont return nickname
+ # So we use part of email as username for new user
+ user.username = email.match(/^[^@]*/)[0]
+ end
+
user.save!
log.info "(OAuth) Creating user #{email} from login with extern_uid => #{uid}"
@@ -58,7 +69,7 @@ module Gitlab
end
def username
- email.match(/^[^@]*/)[0]
+ auth.info.nickname.to_s.force_encoding("utf-8")
end
def provider
diff --git a/spec/lib/oauth_spec.rb b/spec/lib/oauth_spec.rb
index 3dfe95a8e38..2f15b5e0349 100644
--- a/spec/lib/oauth_spec.rb
+++ b/spec/lib/oauth_spec.rb
@@ -8,6 +8,7 @@ describe Gitlab::OAuth::User do
@info = double(
uid: '12djsak321',
+ nickname: 'john',
name: 'John',
email: 'john@mail.com'
)