Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
366c0065
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
366c0065
编写于
8月 21, 2012
作者:
R
randx
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'better_ldap' of
https://github.com/jirutka/gitlabhq
into jirutka-better_ldap
Conflicts: app/models/user.rb
上级
b2b88b2f
335b3ed1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
14 deletion
+36
-14
app/controllers/omniauth_callbacks_controller.rb
app/controllers/omniauth_callbacks_controller.rb
+1
-2
app/models/user.rb
app/models/user.rb
+23
-11
db/migrate/20120729131232_add_extern_auth_provider_to_users.rb
...grate/20120729131232_add_extern_auth_provider_to_users.rb
+8
-0
db/schema.rb
db/schema.rb
+4
-1
未找到文件。
app/controllers/omniauth_callbacks_controller.rb
浏览文件 @
366c0065
...
...
@@ -12,8 +12,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def
ldap
# We only find ourselves here if the authentication to LDAP was successful.
info
=
request
.
env
[
"omniauth.auth"
][
"info"
]
@user
=
User
.
find_for_ldap_auth
(
info
)
@user
=
User
.
find_for_ldap_auth
(
request
.
env
[
"omniauth.auth"
],
current_user
)
if
@user
.
persisted?
@user
.
remember_me
=
true
end
...
...
app/models/user.rb
浏览文件 @
366c0065
...
...
@@ -7,7 +7,7 @@ class User < ActiveRecord::Base
attr_accessible
:email
,
:password
,
:password_confirmation
,
:remember_me
,
:bio
,
:name
,
:projects_limit
,
:skype
,
:linkedin
,
:twitter
,
:dark_scheme
,
:theme_id
,
:force_random_password
:theme_id
,
:force_random_password
,
:extern_uid
,
:provider
attr_accessor
:force_random_password
...
...
@@ -54,6 +54,8 @@ class User < ActiveRecord::Base
validates
:bio
,
length:
{
within:
0
..
255
}
validates
:extern_uid
,
:allow_blank
=>
true
,
:uniqueness
=>
{
:scope
=>
:provider
}
before_save
:ensure_authentication_token
alias_attribute
:private_token
,
:authentication_token
...
...
@@ -84,21 +86,31 @@ class User < ActiveRecord::Base
where
(
'id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)'
)
end
def
self
.
find_for_ldap_auth
(
omniauth_info
)
name
=
omniauth_info
.
name
.
force_encoding
(
"utf-8"
)
email
=
omniauth_info
.
email
.
downcase
unless
omniauth_info
.
email
.
nil?
raise
OmniAuth
::
Error
,
"LDAP accounts must provide an email address"
if
email
.
nil?
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?
if
@user
=
User
.
find_by_email
(
email
)
if
@user
=
User
.
find_by_extern_uid_and_provider
(
uid
,
provider
)
@user
# workaround for backward compatibility
elsif
@user
=
User
.
find_by_email
(
email
)
logger
.
info
"Updating legacy LDAP user
#{
email
}
with extern_uid =>
#{
uid
}
"
@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
(
name:
name
,
email:
email
,
password:
password
,
password_confirmation:
password
,
projects_limit:
Gitlab
.
config
.
default_projects_limit
:extern_uid
=>
uid
,
:provider
=>
provider
,
:name
=>
name
,
:email
=>
email
,
:password
=>
password
,
:password_confirmation
=>
password
,
:projects_limit
=>
Gitlab
.
config
.
default_projects_limit
)
end
end
...
...
db/migrate/20120729131232_add_extern_auth_provider_to_users.rb
0 → 100644
浏览文件 @
366c0065
class
AddExternAuthProviderToUsers
<
ActiveRecord
::
Migration
def
change
add_column
:users
,
:extern_uid
,
:string
add_column
:users
,
:provider
,
:string
add_index
:users
,
[
:extern_uid
,
:provider
],
:unique
=>
true
end
end
db/schema.rb
浏览文件 @
366c0065
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
:version
=>
201207
12080407
)
do
ActiveRecord
::
Schema
.
define
(
:version
=>
201207
29131232
)
do
create_table
"events"
,
:force
=>
true
do
|
t
|
t
.
string
"target_type"
...
...
@@ -171,9 +171,12 @@ ActiveRecord::Schema.define(:version => 20120712080407) do
t
.
boolean
"blocked"
,
:default
=>
false
,
:null
=>
false
t
.
integer
"failed_attempts"
,
:default
=>
0
t
.
datetime
"locked_at"
t
.
string
"extern_uid"
t
.
string
"provider"
end
add_index
"users"
,
[
"email"
],
:name
=>
"index_users_on_email"
,
:unique
=>
true
add_index
"users"
,
[
"extern_uid"
,
"provider"
],
:name
=>
"index_users_on_extern_uid_and_provider"
,
:unique
=>
true
add_index
"users"
,
[
"reset_password_token"
],
:name
=>
"index_users_on_reset_password_token"
,
:unique
=>
true
create_table
"users_projects"
,
:force
=>
true
do
|
t
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录