Commit a73df4f72d9d5fbc118b80cea6f6bda4f877f5df
1 parent
4e002a71
Exists in
spb-stable
and in
3 other branches
Allow oauth signup without email
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
6 changed files
with
29 additions
and
4 deletions
Show diff stats
app/controllers/application_controller.rb
@@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base | @@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base | ||
11 | before_filter :default_headers | 11 | before_filter :default_headers |
12 | before_filter :add_gon_variables | 12 | before_filter :add_gon_variables |
13 | before_filter :configure_permitted_parameters, if: :devise_controller? | 13 | before_filter :configure_permitted_parameters, if: :devise_controller? |
14 | + before_filter :require_email | ||
14 | 15 | ||
15 | protect_from_forgery | 16 | protect_from_forgery |
16 | 17 | ||
@@ -234,4 +235,10 @@ class ApplicationController < ActionController::Base | @@ -234,4 +235,10 @@ class ApplicationController < ActionController::Base | ||
234 | def hexdigest(string) | 235 | def hexdigest(string) |
235 | Digest::SHA1.hexdigest string | 236 | Digest::SHA1.hexdigest string |
236 | end | 237 | end |
238 | + | ||
239 | + def require_email | ||
240 | + if current_user && current_user.temp_oauth_email? | ||
241 | + redirect_to profile_path, notice: 'Please complete your profile with email address' and return | ||
242 | + end | ||
243 | + end | ||
237 | end | 244 | end |
app/controllers/profiles/emails_controller.rb
@@ -8,7 +8,7 @@ class Profiles::EmailsController < ApplicationController | @@ -8,7 +8,7 @@ class Profiles::EmailsController < ApplicationController | ||
8 | 8 | ||
9 | def create | 9 | def create |
10 | @email = current_user.emails.new(params[:email]) | 10 | @email = current_user.emails.new(params[:email]) |
11 | - | 11 | + |
12 | flash[:alert] = @email.errors.full_messages.first unless @email.save | 12 | flash[:alert] = @email.errors.full_messages.first unless @email.save |
13 | 13 | ||
14 | redirect_to profile_emails_url | 14 | redirect_to profile_emails_url |
app/controllers/profiles_controller.rb
@@ -3,6 +3,7 @@ class ProfilesController < ApplicationController | @@ -3,6 +3,7 @@ class ProfilesController < ApplicationController | ||
3 | 3 | ||
4 | before_filter :user | 4 | before_filter :user |
5 | before_filter :authorize_change_username!, only: :update_username | 5 | before_filter :authorize_change_username!, only: :update_username |
6 | + skip_before_filter :require_email, only: [:show, :update] | ||
6 | 7 | ||
7 | layout 'profile' | 8 | layout 'profile' |
8 | 9 |
app/models/user.rb
@@ -462,4 +462,12 @@ class User < ActiveRecord::Base | @@ -462,4 +462,12 @@ class User < ActiveRecord::Base | ||
462 | def all_ssh_keys | 462 | def all_ssh_keys |
463 | keys.map(&:key) | 463 | keys.map(&:key) |
464 | end | 464 | end |
465 | + | ||
466 | + def temp_oauth_email? | ||
467 | + email =~ /\Atemp-email-for-oauth/ | ||
468 | + end | ||
469 | + | ||
470 | + def generate_tmp_oauth_email | ||
471 | + self.email = "temp-email-for-oauth-#{username}" | ||
472 | + end | ||
465 | end | 473 | end |
app/views/profiles/show.html.haml
@@ -30,7 +30,10 @@ | @@ -30,7 +30,10 @@ | ||
30 | %span.help-block.light | 30 | %span.help-block.light |
31 | Email is read-only for LDAP user | 31 | Email is read-only for LDAP user |
32 | - else | 32 | - else |
33 | - = f.text_field :email, class: "form-control", required: true | 33 | + - if @user.temp_oauth_email? |
34 | + = f.text_field :email, class: "form-control", required: true, value: nil | ||
35 | + - else | ||
36 | + = f.text_field :email, class: "form-control", required: true | ||
34 | - if @user.unconfirmed_email.present? | 37 | - if @user.unconfirmed_email.present? |
35 | %span.help-block | 38 | %span.help-block |
36 | We sent confirmation email to | 39 | We sent confirmation email to |
lib/gitlab/oauth/user.rb
@@ -29,7 +29,13 @@ module Gitlab | @@ -29,7 +29,13 @@ module Gitlab | ||
29 | 29 | ||
30 | user = model.build_user(opts, as: :admin) | 30 | user = model.build_user(opts, as: :admin) |
31 | user.skip_confirmation! | 31 | user.skip_confirmation! |
32 | - user.save! | 32 | + |
33 | + if user.email.blank? | ||
34 | + user.generate_tmp_oauth_email | ||
35 | + end | ||
36 | + | ||
37 | + user.save!(validate: false) | ||
38 | + | ||
33 | log.info "(OAuth) Creating user #{email} from login with extern_uid => #{uid}" | 39 | log.info "(OAuth) Creating user #{email} from login with extern_uid => #{uid}" |
34 | 40 | ||
35 | if Gitlab.config.omniauth['block_auto_created_users'] && !ldap? | 41 | if Gitlab.config.omniauth['block_auto_created_users'] && !ldap? |
@@ -58,7 +64,7 @@ module Gitlab | @@ -58,7 +64,7 @@ module Gitlab | ||
58 | end | 64 | end |
59 | 65 | ||
60 | def username | 66 | def username |
61 | - email.match(/^[^@]*/)[0] | 67 | + auth.info.nickname.to_s.force_encoding("utf-8") |
62 | end | 68 | end |
63 | 69 | ||
64 | def provider | 70 | def provider |