Commit 3707cc119b291c06703ebf31456c4b8140c324c6
1 parent
9028999c
Exists in
master
and in
4 other branches
Refactor Gitlab::Auth
Showing
2 changed files
with
1 additions
and
70 deletions
Show diff stats
app/models/user.rb
@@ -187,22 +187,6 @@ class User < ActiveRecord::Base | @@ -187,22 +187,6 @@ class User < ActiveRecord::Base | ||
187 | end | 187 | end |
188 | end | 188 | end |
189 | 189 | ||
190 | - def create_from_omniauth(auth, ldap = false) | ||
191 | - gitlab_auth.create_from_omniauth(auth, ldap) | ||
192 | - end | ||
193 | - | ||
194 | - def find_or_new_for_omniauth(auth) | ||
195 | - gitlab_auth.find_or_new_for_omniauth(auth) | ||
196 | - end | ||
197 | - | ||
198 | - def find_for_ldap_auth(auth, signed_in_resource = nil) | ||
199 | - gitlab_auth.find_for_ldap_auth(auth, signed_in_resource) | ||
200 | - end | ||
201 | - | ||
202 | - def gitlab_auth | ||
203 | - Gitlab::Auth.new | ||
204 | - end | ||
205 | - | ||
206 | def search query | 190 | def search query |
207 | where("name LIKE :query OR email LIKE :query OR username LIKE :query", query: "%#{query}%") | 191 | where("name LIKE :query OR email LIKE :query OR username LIKE :query", query: "%#{query}%") |
208 | end | 192 | end |
lib/gitlab/auth.rb
@@ -7,61 +7,12 @@ module Gitlab | @@ -7,61 +7,12 @@ module Gitlab | ||
7 | # Second chance - try LDAP authentication | 7 | # Second chance - try LDAP authentication |
8 | return nil unless ldap_conf.enabled | 8 | return nil unless ldap_conf.enabled |
9 | 9 | ||
10 | - ldap_auth(login, password) | 10 | + Gitlab::LDAP::User.authenticate(login, password) |
11 | else | 11 | else |
12 | user if user.valid_password?(password) | 12 | user if user.valid_password?(password) |
13 | end | 13 | end |
14 | end | 14 | end |
15 | 15 | ||
16 | - def create_from_omniauth(auth, ldap = false) | ||
17 | - provider = auth.provider | ||
18 | - uid = auth.info.uid || auth.uid | ||
19 | - uid = uid.to_s.force_encoding("utf-8") | ||
20 | - name = auth.info.name.to_s.force_encoding("utf-8") | ||
21 | - email = auth.info.email.to_s.downcase unless auth.info.email.nil? | ||
22 | - | ||
23 | - ldap_prefix = ldap ? '(LDAP) ' : '' | ||
24 | - raise OmniAuth::Error, "#{ldap_prefix}#{provider} does not provide an email"\ | ||
25 | - " address" if auth.info.email.blank? | ||
26 | - | ||
27 | - log.info "#{ldap_prefix}Creating user from #{provider} login"\ | ||
28 | - " {uid => #{uid}, name => #{name}, email => #{email}}" | ||
29 | - password = Devise.friendly_token[0, 8].downcase | ||
30 | - @user = User.new({ | ||
31 | - extern_uid: uid, | ||
32 | - provider: provider, | ||
33 | - name: name, | ||
34 | - username: email.match(/^[^@]*/)[0], | ||
35 | - email: email, | ||
36 | - password: password, | ||
37 | - password_confirmation: password, | ||
38 | - }, as: :admin).with_defaults | ||
39 | - @user.save! | ||
40 | - | ||
41 | - if Gitlab.config.omniauth['block_auto_created_users'] && !ldap | ||
42 | - @user.block | ||
43 | - end | ||
44 | - | ||
45 | - @user | ||
46 | - end | ||
47 | - | ||
48 | - def find_or_new_for_omniauth(auth) | ||
49 | - provider, uid = auth.provider, auth.uid | ||
50 | - email = auth.info.email.downcase unless auth.info.email.nil? | ||
51 | - | ||
52 | - if @user = User.find_by_provider_and_extern_uid(provider, uid) | ||
53 | - @user | ||
54 | - elsif @user = User.find_by_email(email) | ||
55 | - @user.update_attributes(extern_uid: uid, provider: provider) | ||
56 | - @user | ||
57 | - else | ||
58 | - if Gitlab.config.omniauth['allow_single_sign_on'] | ||
59 | - @user = create_from_omniauth(auth) | ||
60 | - @user | ||
61 | - end | ||
62 | - end | ||
63 | - end | ||
64 | - | ||
65 | def log | 16 | def log |
66 | Gitlab::AppLogger | 17 | Gitlab::AppLogger |
67 | end | 18 | end |
@@ -69,9 +20,5 @@ module Gitlab | @@ -69,9 +20,5 @@ module Gitlab | ||
69 | def ldap_conf | 20 | def ldap_conf |
70 | @ldap_conf ||= Gitlab.config.ldap | 21 | @ldap_conf ||= Gitlab.config.ldap |
71 | end | 22 | end |
72 | - | ||
73 | - def ldap_auth(login, password) | ||
74 | - Gitlab::LDAP::User.auth(login, password) | ||
75 | - end | ||
76 | end | 23 | end |
77 | end | 24 | end |