Commit a73df4f72d9d5fbc118b80cea6f6bda4f877f5df

Authored by Dmitriy Zaporozhets
1 parent 4e002a71

Allow oauth signup without email

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/controllers/application_controller.rb
... ... @@ -11,6 +11,7 @@ class ApplicationController &lt; ActionController::Base
11 11 before_filter :default_headers
12 12 before_filter :add_gon_variables
13 13 before_filter :configure_permitted_parameters, if: :devise_controller?
  14 + before_filter :require_email
14 15  
15 16 protect_from_forgery
16 17  
... ... @@ -234,4 +235,10 @@ class ApplicationController &lt; ActionController::Base
234 235 def hexdigest(string)
235 236 Digest::SHA1.hexdigest string
236 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 244 end
... ...
app/controllers/profiles/emails_controller.rb
... ... @@ -8,7 +8,7 @@ class Profiles::EmailsController &lt; ApplicationController
8 8  
9 9 def create
10 10 @email = current_user.emails.new(params[:email])
11   -
  11 +
12 12 flash[:alert] = @email.errors.full_messages.first unless @email.save
13 13  
14 14 redirect_to profile_emails_url
... ...
app/controllers/profiles_controller.rb
... ... @@ -3,6 +3,7 @@ class ProfilesController &lt; ApplicationController
3 3  
4 4 before_filter :user
5 5 before_filter :authorize_change_username!, only: :update_username
  6 + skip_before_filter :require_email, only: [:show, :update]
6 7  
7 8 layout 'profile'
8 9  
... ...
app/models/user.rb
... ... @@ -462,4 +462,12 @@ class User &lt; ActiveRecord::Base
462 462 def all_ssh_keys
463 463 keys.map(&:key)
464 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 473 end
... ...
app/views/profiles/show.html.haml
... ... @@ -30,7 +30,10 @@
30 30 %span.help-block.light
31 31 Email is read-only for LDAP user
32 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 37 - if @user.unconfirmed_email.present?
35 38 %span.help-block
36 39 We sent confirmation email to
... ...
lib/gitlab/oauth/user.rb
... ... @@ -29,7 +29,13 @@ module Gitlab
29 29  
30 30 user = model.build_user(opts, as: :admin)
31 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 39 log.info "(OAuth) Creating user #{email} from login with extern_uid => #{uid}"
34 40  
35 41 if Gitlab.config.omniauth['block_auto_created_users'] && !ldap?
... ... @@ -58,7 +64,7 @@ module Gitlab
58 64 end
59 65  
60 66 def username
61   - email.match(/^[^@]*/)[0]
  67 + auth.info.nickname.to_s.force_encoding("utf-8")
62 68 end
63 69  
64 70 def provider
... ...