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
Kazuhiko Shiozaki
gitlab-ce
Commits
802fcd05
Commit
802fcd05
authored
Mar 31, 2015
by
Dmitriy Zaporozhets
Committed by
Robert Speicher
May 09, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for backup codes
parent
b66be0a2
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
14 deletions
+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
No files found.
app/controllers/profiles/two_factor_auths_controller.rb
View file @
802fcd05
...
@@ -21,6 +21,12 @@ class Profiles::TwoFactorAuthsController < ApplicationController
...
@@ -21,6 +21,12 @@ class Profiles::TwoFactorAuthsController < ApplicationController
end
end
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
def
destroy
current_user
.
otp_required_for_login
=
false
current_user
.
otp_required_for_login
=
false
current_user
.
save!
current_user
.
save!
...
...
app/controllers/sessions_controller.rb
View file @
802fcd05
...
@@ -44,7 +44,8 @@ class SessionsController < Devise::SessionsController
...
@@ -44,7 +44,8 @@ class SessionsController < Devise::SessionsController
@user
=
User
.
by_login
(
user_params
[
:login
])
@user
=
User
.
by_login
(
user_params
[
:login
])
if
user_params
[
:otp_attempt
].
present?
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'
@error
=
'Invalid two-factor code'
render
:two_factor
and
return
render
:two_factor
and
return
end
end
...
...
app/views/profiles/accounts/show.html.haml
View file @
802fcd05
...
@@ -28,19 +28,30 @@
...
@@ -28,19 +28,30 @@
-
unless
current_user
.
ldap_user?
-
unless
current_user
.
ldap_user?
%fieldset
%fieldset
-
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'
%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
%legend
Two-Factor Authentication
%div
%p
%p
Keep your account secure by enabling two-factor authentication.
Keep your account secure by enabling two-factor authentication.
%br
%br
Each time you log in, you’ll be required to provide your password plus a randomly generated access code.
Each time you log in, you’ll be required to provide your password plus a randomly generated access code.
%div
%div
-
if
current_user
.
otp_required_for_login
%strong
.text-success
%i
.fa.fa-check
2-Factor Authentication enabled
.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'
=
link_to
"Enable 2-Factor Authentication"
,
new_profile_two_factor_auth_path
,
class:
'btn btn-success'
-
if
show_profile_social_tab?
-
if
show_profile_social_tab?
...
...
config/initializers/devise.rb
View file @
802fcd05
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
Devise
.
setup
do
|
config
|
Devise
.
setup
do
|
config
|
config
.
warden
do
|
manager
|
config
.
warden
do
|
manager
|
manager
.
default_strategies
(
scope: :user
).
unshift
:two_factor_authenticatable
manager
.
default_strategies
(
scope: :user
).
unshift
:two_factor_authenticatable
manager
.
default_strategies
(
scope: :user
).
unshift
:two_factor_backupable
end
end
# ==> Mailer Configuration
# ==> Mailer Configuration
...
...
config/routes.rb
View file @
802fcd05
...
@@ -226,7 +226,11 @@ Gitlab::Application.routes.draw do
...
@@ -226,7 +226,11 @@ Gitlab::Application.routes.draw do
resources
:keys
resources
:keys
resources
:emails
,
only:
[
:index
,
:create
,
:destroy
]
resources
:emails
,
only:
[
:index
,
:create
,
:destroy
]
resource
:avatar
,
only:
[
: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
end
end
...
...
db/migrate/20150331183602_add_devise_two_factor_backupable_to_users.rb
0 → 100644
View file @
802fcd05
class
AddDeviseTwoFactorBackupableToUsers
<
ActiveRecord
::
Migration
def
change
add_column
:users
,
:otp_backup_codes
,
:string
,
array:
true
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