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
Léo-Paul Géneau
gitlab-ce
Commits
6c8f0fe9
Commit
6c8f0fe9
authored
Jun 19, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add convenience methods to User for getting and setting 2FA status
parent
7964e7d6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
1 deletion
+37
-1
app/models/user.rb
app/models/user.rb
+12
-0
spec/factories.rb
spec/factories.rb
+1
-1
spec/models/user_spec.rb
spec/models/user_spec.rb
+24
-0
No files found.
app/models/user.rb
View file @
6c8f0fe9
...
...
@@ -300,6 +300,18 @@ class User < ActiveRecord::Base
@reset_token
end
# Check if the user has enabled Two-factor Authentication
def
two_factor_enabled?
otp_required_for_login
end
# Set whether or not Two-factor Authentication is enabled for the current user
#
# setting - Boolean
def
two_factor_enabled
=
(
setting
)
self
.
otp_required_for_login
=
setting
end
def
namespace_uniq
namespace_name
=
self
.
username
existing_namespace
=
Namespace
.
by_path
(
namespace_name
)
...
...
spec/factories.rb
View file @
6c8f0fe9
...
...
@@ -30,7 +30,7 @@ FactoryGirl.define do
trait
:two_factor
do
before
(
:create
)
do
|
user
|
user
.
otp_required_for_login
=
true
user
.
two_factor_enabled
=
true
user
.
otp_secret
=
User
.
generate_otp_secret
(
32
)
end
end
...
...
spec/models/user_spec.rb
View file @
6c8f0fe9
...
...
@@ -210,6 +210,30 @@ describe User do
end
end
describe
'#two_factor_enabled'
do
it
'returns two-factor authentication status'
do
enabled
=
build_stubbed
(
:user
,
two_factor_enabled:
true
)
disabled
=
build_stubbed
(
:user
)
expect
(
enabled
).
to
be_two_factor_enabled
expect
(
disabled
).
not_to
be_two_factor_enabled
end
end
describe
'#two_factor_enabled='
do
it
'enables two-factor authentication'
do
user
=
build_stubbed
(
:user
,
two_factor_enabled:
false
)
expect
{
user
.
two_factor_enabled
=
true
}.
to
change
{
user
.
two_factor_enabled?
}.
to
(
true
)
end
it
'disables two-factor authentication'
do
user
=
build_stubbed
(
:user
,
two_factor_enabled:
true
)
expect
{
user
.
two_factor_enabled
=
false
}.
to
change
{
user
.
two_factor_enabled?
}.
to
(
false
)
end
end
describe
'authentication token'
do
it
"should have authentication token"
do
user
=
create
(
:user
)
...
...
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