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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
d6a0b8f4
Commit
d6a0b8f4
authored
Jan 28, 2012
by
vsizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LDAP done
parent
d885f24f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
24 deletions
+37
-24
app/controllers/omniauth_callbacks_controller.rb
app/controllers/omniauth_callbacks_controller.rb
+13
-0
app/controllers/users/omniauth_callbacks_controller.rb
app/controllers/users/omniauth_callbacks_controller.rb
+0
-22
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+4
-0
app/models/user.rb
app/models/user.rb
+16
-0
app/views/devise/sessions/new.html.erb
app/views/devise/sessions/new.html.erb
+3
-1
config/routes.rb
config/routes.rb
+1
-1
No files found.
app/controllers/omniauth_callbacks_controller.rb
0 → 100644
View file @
d6a0b8f4
class
OmniauthCallbacksController
<
Devise
::
OmniauthCallbacksController
def
ldap
# We only find ourselves here if the authentication to LDAP was successful.
omniauth
=
request
.
env
[
"omniauth.auth"
][
"extra"
][
"raw_info"
]
@user
=
User
.
find_for_ldap_auth
(
omniauth
)
if
@user
.
persisted?
@user
.
remember_me
=
true
end
sign_in_and_redirect
@user
end
end
app/controllers/users/omniauth_callbacks_controller.rb
deleted
100644 → 0
View file @
d885f24f
class
Users::OmniauthCallbacksController
<
Devise
::
OmniauthCallbacksController
def
ldap
# We only find ourselves here if the authentication to LDAP was successful.
ldap
=
request
.
env
[
"omniauth.auth"
][
"extra"
][
"raw_info"
]
username
=
ldap
.
sAMAccountName
[
0
].
to_s
email
=
ldap
.
proxyaddresses
[
0
][
5
..-
1
].
to_s
if
@user
=
User
.
find_by_email
(
email
)
sign_in_and_redirect
root_path
else
password
=
User
.
generate_random_password
@user
=
User
.
create
(
:name
=>
username
,
:email
=>
email
,
:password
=>
password
,
:password_confirmation
=>
password
)
sign_in_and_redirect
@user
end
end
end
app/helpers/application_helper.rb
View file @
d6a0b8f4
...
@@ -93,4 +93,8 @@ module ApplicationHelper
...
@@ -93,4 +93,8 @@ module ApplicationHelper
def
help_layout
def
help_layout
controller
.
controller_name
==
"help"
controller
.
controller_name
==
"help"
end
end
def
ldap_enable?
Devise
.
omniauth_providers
.
include?
(
:ldap
)
end
end
end
app/models/user.rb
View file @
d6a0b8f4
...
@@ -66,6 +66,22 @@ class User < ActiveRecord::Base
...
@@ -66,6 +66,22 @@ class User < ActiveRecord::Base
def
self
.
generate_random_password
def
self
.
generate_random_password
(
0
...
8
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
(
0
...
8
).
map
{
(
'a'
..
'z'
).
to_a
[
rand
(
26
)]
}.
join
end
end
def
self
.
find_for_ldap_auth
(
omniauth
)
username
=
omniauth
.
sAMAccountName
[
0
]
email
=
omniauth
.
userprincipalname
[
0
]
if
@user
=
User
.
find_by_email
(
email
)
@user
else
password
=
generate_random_password
@user
=
User
.
create
(
:name
=>
username
,
:email
=>
email
,
:password
=>
password
,
:password_confirmation
=>
password
)
end
end
end
end
# == Schema Information
# == Schema Information
#
#
...
...
app/views/devise/sessions/new.html.erb
View file @
d6a0b8f4
...
@@ -9,5 +9,7 @@
...
@@ -9,5 +9,7 @@
<br/>
<br/>
<%=
f
.
submit
"Sign in"
,
:class
=>
"grey-button"
%>
<%=
f
.
submit
"Sign in"
,
:class
=>
"grey-button"
%>
<div
class=
"right"
>
<%=
render
:partial
=>
"devise/shared/links"
%>
</div>
<div
class=
"right"
>
<%=
render
:partial
=>
"devise/shared/links"
%>
</div>
<%=
user_omniauth_authorize_path
(
:ldap
)
%>
<%
if
ldap_enable?
-%>
<p>
<%=
link_to
"via LDAP"
,
user_omniauth_authorize_path
(
:ldap
)
%>
</p>
<%
end
-%>
<%
end
%>
<%
end
%>
config/routes.rb
View file @
d6a0b8f4
...
@@ -39,7 +39,7 @@ Gitlab::Application.routes.draw do
...
@@ -39,7 +39,7 @@ Gitlab::Application.routes.draw do
resources
:projects
,
:constraints
=>
{
:id
=>
/[^\/]+/
},
:only
=>
[
:new
,
:create
,
:index
]
resources
:projects
,
:constraints
=>
{
:id
=>
/[^\/]+/
},
:only
=>
[
:new
,
:create
,
:index
]
resources
:keys
resources
:keys
devise_for
:users
,
:controllers
=>
{
:omniauth_callbacks
=>
"users/omniauth_callbacks"
}
devise_for
:users
,
:controllers
=>
{
:omniauth_callbacks
=>
:omniauth_callbacks
}
resources
:projects
,
:constraints
=>
{
:id
=>
/[^\/]+/
},
:except
=>
[
:new
,
:create
,
:index
],
:path
=>
"/"
do
resources
:projects
,
:constraints
=>
{
:id
=>
/[^\/]+/
},
:except
=>
[
:new
,
:create
,
:index
],
:path
=>
"/"
do
member
do
member
do
...
...
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