Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
802fcd05
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,发现更多精彩内容 >>
提交
802fcd05
编写于
3月 31, 2015
作者:
D
Dmitriy Zaporozhets
提交者:
Robert Speicher
5月 09, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for backup codes
上级
b66be0a2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
42 addition
and
14 deletion
+42
-14
app/controllers/profiles/two_factor_auths_controller.rb
app/controllers/profiles/two_factor_auths_controller.rb
+6
-0
app/controllers/sessions_controller.rb
app/controllers/sessions_controller.rb
+2
-1
app/views/profiles/accounts/show.html.haml
app/views/profiles/accounts/show.html.haml
+23
-12
config/initializers/devise.rb
config/initializers/devise.rb
+1
-0
config/routes.rb
config/routes.rb
+5
-1
db/migrate/20150331183602_add_devise_two_factor_backupable_to_users.rb
...150331183602_add_devise_two_factor_backupable_to_users.rb
+5
-0
未找到文件。
app/controllers/profiles/two_factor_auths_controller.rb
浏览文件 @
802fcd05
...
...
@@ -21,6 +21,12 @@ class Profiles::TwoFactorAuthsController < ApplicationController
end
end
def
codes
codes
=
current_user
.
generate_otp_backup_codes!
current_user
.
save!
send_data
codes
.
join
(
"
\n
"
),
filename:
'gitlab_recovery_codes.txt'
end
def
destroy
current_user
.
otp_required_for_login
=
false
current_user
.
save!
...
...
app/controllers/sessions_controller.rb
浏览文件 @
802fcd05
...
...
@@ -44,7 +44,8 @@ class SessionsController < Devise::SessionsController
@user
=
User
.
by_login
(
user_params
[
:login
])
if
user_params
[
:otp_attempt
].
present?
unless
@user
.
valid_otp?
(
user_params
[
:otp_attempt
])
unless
@user
.
valid_otp?
(
user_params
[
:otp_attempt
])
||
@user
.
recovery_code?
(
user_params
[
:otp_attempt
])
@error
=
'Invalid two-factor code'
render
:two_factor
and
return
end
...
...
app/views/profiles/accounts/show.html.haml
浏览文件 @
802fcd05
...
...
@@ -28,20 +28,31 @@
-
unless
current_user
.
ldap_user?
%fieldset
%legend
Two-Factor Authentication
%p
Keep your account secure by enabling two-factor authentication.
%br
Each time you log in, you’ll be required to provide your password plus a randomly generated access code.
%div
-
if
current_user
.
otp_required_for_login
%strong
.text-success
%i
.fa.fa-check
2-Factor Authentication enabled
-
if
current_user
.
otp_required_for_login
%legend
.text-success
%i
.fa.fa-check
Two-Factor Authentication enabled
%div
.pull-right
=
link_to
"Disable 2-Factor Authentication"
,
profile_two_factor_auth_path
,
method: :delete
,
class:
'btn btn-close btn-sm'
-
else
=
link_to
"Enable 2-Factor Authentication"
,
new_profile_two_factor_auth_path
,
class:
'btn btn-success'
%p
.slead
%i
.fa.fa-warning
Please
%strong
#{
link_to
"download recovery codes"
,
codes_profile_two_factor_auth_path
}
so you can access your account if you lose your phone.
%br
%i
.fa.fa-warning
Every time you download recovery codes - we generate the new codes. Previously downloaded codes won't work anymore.
-
else
%legend
Two-Factor Authentication
%div
%p
Keep your account secure by enabling two-factor authentication.
%br
Each time you log in, you’ll be required to provide your password plus a randomly generated access code.
%div
=
link_to
"Enable 2-Factor Authentication"
,
new_profile_two_factor_auth_path
,
class:
'btn btn-success'
-
if
show_profile_social_tab?
%fieldset
...
...
config/initializers/devise.rb
浏览文件 @
802fcd05
...
...
@@ -3,6 +3,7 @@
Devise
.
setup
do
|
config
|
config
.
warden
do
|
manager
|
manager
.
default_strategies
(
scope: :user
).
unshift
:two_factor_authenticatable
manager
.
default_strategies
(
scope: :user
).
unshift
:two_factor_backupable
end
# ==> Mailer Configuration
...
...
config/routes.rb
浏览文件 @
802fcd05
...
...
@@ -226,7 +226,11 @@ Gitlab::Application.routes.draw do
resources
:keys
resources
:emails
,
only:
[
:index
,
:create
,
:destroy
]
resource
:avatar
,
only:
[
:destroy
]
resource
:two_factor_auth
,
only:
[
:new
,
:create
,
:destroy
]
resource
:two_factor_auth
,
only:
[
:new
,
:create
,
:destroy
]
do
member
do
get
:codes
end
end
end
end
...
...
db/migrate/20150331183602_add_devise_two_factor_backupable_to_users.rb
0 → 100644
浏览文件 @
802fcd05
class
AddDeviseTwoFactorBackupableToUsers
<
ActiveRecord
::
Migration
def
change
add_column
:users
,
:otp_backup_codes
,
:string
,
array:
true
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录