Commit 089605fe6b9850ff87e1b1535d084b73e305d627

Authored by Izaak Alpert
1 parent 2c191ab0

Allow the ldap logins with email or username

Change-Id: I73b4aa4c46afd56ae02fb24abcd673c0724547e4
config/gitlab.yml.example
@@ -97,6 +97,7 @@ production: &base @@ -97,6 +97,7 @@ production: &base
97 method: 'ssl' # "ssl" or "plain" 97 method: 'ssl' # "ssl" or "plain"
98 bind_dn: '_the_full_dn_of_the_user_you_will_bind_with' 98 bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
99 password: '_the_password_of_the_bind_user' 99 password: '_the_password_of_the_bind_user'
  100 + allow_username_or_email_login: true
100 101
101 ## OmniAuth settings 102 ## OmniAuth settings
102 omniauth: 103 omniauth:
config/initializers/devise.rb
@@ -206,6 +206,12 @@ Devise.setup do |config| @@ -206,6 +206,12 @@ Devise.setup do |config|
206 # end 206 # end
207 207
208 if Gitlab.config.ldap.enabled 208 if Gitlab.config.ldap.enabled
  209 + if Gitlab.config.ldap.allow_username_or_email_login
  210 + email_stripping_proc = Proc.new {|name| name.gsub(/@.*$/,'')}
  211 + else
  212 + email_stripping_proc = lambda {|n|n}
  213 +
  214 + end
209 config.omniauth :ldap, 215 config.omniauth :ldap,
210 host: Gitlab.config.ldap['host'], 216 host: Gitlab.config.ldap['host'],
211 base: Gitlab.config.ldap['base'], 217 base: Gitlab.config.ldap['base'],
@@ -213,7 +219,8 @@ Devise.setup do |config| @@ -213,7 +219,8 @@ Devise.setup do |config|
213 port: Gitlab.config.ldap['port'], 219 port: Gitlab.config.ldap['port'],
214 method: Gitlab.config.ldap['method'], 220 method: Gitlab.config.ldap['method'],
215 bind_dn: Gitlab.config.ldap['bind_dn'], 221 bind_dn: Gitlab.config.ldap['bind_dn'],
216 - password: Gitlab.config.ldap['password'] 222 + password: Gitlab.config.ldap['password'],
  223 + name_proc: email_stripping_proc
217 end 224 end
218 225
219 Gitlab.config.omniauth.providers.each do |provider| 226 Gitlab.config.omniauth.providers.each do |provider|