Commit 650d0bc6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'improve-oauth'

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>

Conflicts:
	CHANGELOG
parents 5d6e9ea8 e6f58cb8
...@@ -10,6 +10,7 @@ v 6.8.0 ...@@ -10,6 +10,7 @@ v 6.8.0
- Protected branch does not allow force push - Protected branch does not allow force push
- Fix popen bug in `rake gitlab:satellites:create` - Fix popen bug in `rake gitlab:satellites:create`
- Disable connection reaping for MySQL - Disable connection reaping for MySQL
- Allow oauth signup without email for twitter and github
v 6.7.3 v 6.7.3
- Fix the merge notification email not being sent (Pierre de La Morinerie) - Fix the merge notification email not being sent (Pierre de La Morinerie)
......
...@@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base ...@@ -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, unless: :devise_controller?
protect_from_forgery protect_from_forgery
...@@ -234,4 +235,10 @@ class ApplicationController < ActionController::Base ...@@ -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
...@@ -8,7 +8,7 @@ class Profiles::EmailsController < ApplicationController ...@@ -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
......
...@@ -3,6 +3,7 @@ class ProfilesController < ApplicationController ...@@ -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'
......
...@@ -462,4 +462,12 @@ class User < ActiveRecord::Base ...@@ -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}@gitlab.localhost"
end
end end
...@@ -9,5 +9,3 @@ ...@@ -9,5 +9,3 @@
= link_to authbutton(provider, 32), omniauth_authorize_path(resource_name, provider) = link_to authbutton(provider, 32), omniauth_authorize_path(resource_name, provider)
- else - else
= link_to provider.to_s.titleize, omniauth_authorize_path(resource_name, provider), class: "btn" = link_to provider.to_s.titleize, omniauth_authorize_path(resource_name, provider), class: "btn"
%br
%small * Make sure your email address is public
...@@ -30,7 +30,10 @@ ...@@ -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
Please click the link in the confirmation email before continuing, it was send to Please click the link in the confirmation email before continuing, it was send to
......
...@@ -29,6 +29,17 @@ module Gitlab ...@@ -29,6 +29,17 @@ module Gitlab
user = model.build_user(opts, as: :admin) user = model.build_user(opts, as: :admin)
user.skip_confirmation! 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! user.save!
log.info "(OAuth) Creating user #{email} from login with extern_uid => #{uid}" log.info "(OAuth) Creating user #{email} from login with extern_uid => #{uid}"
...@@ -58,7 +69,7 @@ module Gitlab ...@@ -58,7 +69,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
......
...@@ -8,6 +8,7 @@ describe Gitlab::OAuth::User do ...@@ -8,6 +8,7 @@ describe Gitlab::OAuth::User do
@info = double( @info = double(
uid: '12djsak321', uid: '12djsak321',
nickname: 'john',
name: 'John', name: 'John',
email: 'john@mail.com' email: 'john@mail.com'
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment