Allow oauth signup without email

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2014-04-07 14:09:29 +03:00
parent 4e002a7167
commit a73df4f72d
No known key found for this signature in database
GPG key ID: 627C5F589F467F17
6 changed files with 29 additions and 4 deletions

View file

@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base
before_filter :default_headers before_filter :default_headers
before_filter :add_gon_variables before_filter :add_gon_variables
before_filter :configure_permitted_parameters, if: :devise_controller? before_filter :configure_permitted_parameters, if: :devise_controller?
before_filter :require_email
protect_from_forgery protect_from_forgery
@ -234,4 +235,10 @@ class ApplicationController < ActionController::Base
def hexdigest(string) def hexdigest(string)
Digest::SHA1.hexdigest string Digest::SHA1.hexdigest string
end 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 end

View file

@ -8,7 +8,7 @@ class Profiles::EmailsController < ApplicationController
def create def create
@email = current_user.emails.new(params[:email]) @email = current_user.emails.new(params[:email])
flash[:alert] = @email.errors.full_messages.first unless @email.save flash[:alert] = @email.errors.full_messages.first unless @email.save
redirect_to profile_emails_url redirect_to profile_emails_url

View file

@ -3,6 +3,7 @@ class ProfilesController < ApplicationController
before_filter :user before_filter :user
before_filter :authorize_change_username!, only: :update_username before_filter :authorize_change_username!, only: :update_username
skip_before_filter :require_email, only: [:show, :update]
layout 'profile' layout 'profile'

View file

@ -462,4 +462,12 @@ class User < ActiveRecord::Base
def all_ssh_keys def all_ssh_keys
keys.map(&:key) keys.map(&:key)
end end
def temp_oauth_email?
email =~ /\Atemp-email-for-oauth/
end
def generate_tmp_oauth_email
self.email = "temp-email-for-oauth-#{username}"
end
end end

View file

@ -30,7 +30,10 @@
%span.help-block.light %span.help-block.light
Email is read-only for LDAP user Email is read-only for LDAP user
- else - 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? - if @user.unconfirmed_email.present?
%span.help-block %span.help-block
We sent confirmation email to We sent confirmation email to

View file

@ -29,7 +29,13 @@ module Gitlab
user = model.build_user(opts, as: :admin) user = model.build_user(opts, as: :admin)
user.skip_confirmation! user.skip_confirmation!
user.save!
if user.email.blank?
user.generate_tmp_oauth_email
end
user.save!(validate: false)
log.info "(OAuth) Creating user #{email} from login with extern_uid => #{uid}" log.info "(OAuth) Creating user #{email} from login with extern_uid => #{uid}"
if Gitlab.config.omniauth['block_auto_created_users'] && !ldap? if Gitlab.config.omniauth['block_auto_created_users'] && !ldap?
@ -58,7 +64,7 @@ module Gitlab
end end
def username def username
email.match(/^[^@]*/)[0] auth.info.nickname.to_s.force_encoding("utf-8")
end end
def provider def provider