Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
0dd94cd8
Commit
0dd94cd8
authored
Aug 31, 2012
by
Florian Unglaub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY'ed up the user model
parent
1b0198f1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
37 deletions
+32
-37
app/models/user.rb
app/models/user.rb
+32
-37
No files found.
app/models/user.rb
View file @
0dd94cd8
...
...
@@ -86,36 +86,42 @@ class User < ActiveRecord::Base
where
(
'id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)'
)
end
def
self
.
find_or_new_for_omniauth
(
oauth
)
provider
,
uid
=
oauth
[
'provider'
],
oauth
[
'uid'
]
def
self
.
create_from_omniauth
(
auth
,
ldap
=
false
)
provider
,
uid
=
auth
.
provider
,
auth
.
uid
name
=
auth
.
info
.
name
.
force_encoding
(
"utf-8"
)
email
=
auth
.
info
.
email
.
downcase
unless
auth
.
info
.
email
.
nil?
if
@user
=
User
.
find_by_provider_and_extern_uid
(
provider
,
uid
)
@user
else
if
Gitlab
.
config
.
omniauth
.
allow_single_sign_on
# Ensure here that all required attributes were passed along with the
# oauth request:
%w(first_name last_name email)
.
each
do
|
attr
|
unless
oauth
[
:info
][
attr
].
present?
raise
OmniAuth
::
Error
,
"
#{
provider
}
does not provide the required field
#{
attr
}
"
end
end
ldap_prefix
=
ldap
?
'(LDAP) '
:
''
raise
OmniAuth
::
Error
,
"
#{
ldap_prefix
}#{
provider
}
does not provide an email"
\
" address"
if
auth
.
info
.
email
.
blank?
logger
.
info
"
#{
ldap_prefix
}
Creating user from
#{
provider
}
login"
\
" {uid =>
#{
uid
}
, name =>
#{
name
}
, email =>
#{
email
}
}"
password
=
Devise
.
friendly_token
[
0
,
8
].
downcase
@user
=
User
.
new
(
extern_uid:
uid
,
provider:
provider
,
name:
"
#{
oauth
[
:info
][
:first_name
]
}
#{
oauth
[
:info
][
:last_name
]
}
"
,
email:
oauth
[
:info
][
:email
]
,
name:
name
,
email:
email
,
password:
password
,
password_confirmation:
password
,
projects_limit:
Gitlab
.
config
.
default_projects_limit
,
)
@user
.
blocked
=
true
if
Gitlab
.
config
.
omniauth
.
block_auto_created_users
if
Gitlab
.
config
.
omniauth
.
block_auto_created_users
&&
!
ldap
@user
.
blocked
=
true
end
@user
.
save!
@user
end
def
self
.
find_or_new_for_omniauth
(
auth
)
provider
,
uid
=
auth
.
provider
,
auth
.
uid
if
@user
=
User
.
find_by_provider_and_extern_uid
(
provider
,
uid
)
@user
else
if
Gitlab
.
config
.
omniauth
.
allow_single_sign_on
@user
=
User
.
create_from_omniauth
(
auth
)
@user
end
end
...
...
@@ -124,7 +130,6 @@ class User < ActiveRecord::Base
def
self
.
find_for_ldap_auth
(
auth
,
signed_in_resource
=
nil
)
uid
=
auth
.
info
.
uid
provider
=
auth
.
provider
name
=
auth
.
info
.
name
.
force_encoding
(
"utf-8"
)
email
=
auth
.
info
.
email
.
downcase
unless
auth
.
info
.
email
.
nil?
raise
OmniAuth
::
Error
,
"LDAP accounts must provide an uid and email address"
if
uid
.
nil?
or
email
.
nil?
...
...
@@ -136,17 +141,7 @@ class User < ActiveRecord::Base
@user
.
update_attributes
(
:extern_uid
=>
uid
,
:provider
=>
provider
)
@user
else
logger
.
info
"Creating user from LDAP login {uid =>
#{
uid
}
, name =>
#{
name
}
, email =>
#{
email
}
}"
password
=
Devise
.
friendly_token
[
0
,
8
].
downcase
@user
=
User
.
create
(
:extern_uid
=>
uid
,
:provider
=>
provider
,
:name
=>
name
,
:email
=>
email
,
:password
=>
password
,
:password_confirmation
=>
password
,
:projects_limit
=>
Gitlab
.
config
.
default_projects_limit
)
create_from_omniauth
(
auth
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment