Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
b026e867
Commit
b026e867
authored
Jun 06, 2018
by
BaiJiangJie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改判断MFA是否全局启用的逻辑,放到User.otp_force_enabled中
parent
fcd17460
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
21 deletions
+17
-21
user.py
apps/users/models/user.py
+5
-1
user_profile.html
apps/users/templates/users/user_profile.html
+1
-1
login.py
apps/users/views/login.py
+11
-18
user.py
apps/users/views/user.py
+0
-1
No files found.
apps/users/models/user.py
View file @
b026e867
...
@@ -14,6 +14,7 @@ from django.utils import timezone
...
@@ -14,6 +14,7 @@ from django.utils import timezone
from
django.shortcuts
import
reverse
from
django.shortcuts
import
reverse
from
common.utils
import
get_signer
,
date_expired_default
from
common.utils
import
get_signer
,
date_expired_default
from
common.models
import
Setting
__all__
=
[
'User'
]
__all__
=
[
'User'
]
...
@@ -248,10 +249,13 @@ class User(AbstractUser):
...
@@ -248,10 +249,13 @@ class User(AbstractUser):
@property
@property
def
otp_enabled
(
self
):
def
otp_enabled
(
self
):
return
self
.
otp_level
>
0
return
self
.
otp_
force_enabled
or
self
.
otp_
level
>
0
@property
@property
def
otp_force_enabled
(
self
):
def
otp_force_enabled
(
self
):
mfa_setting
=
Setting
.
objects
.
filter
(
name
=
'SECURITY_MFA_AUTH'
)
.
first
()
if
mfa_setting
and
mfa_setting
.
cleaned_value
:
return
True
return
self
.
otp_level
==
2
return
self
.
otp_level
==
2
def
enable_otp
(
self
):
def
enable_otp
(
self
):
...
...
apps/users/templates/users/user_profile.html
View file @
b026e867
...
@@ -155,7 +155,7 @@
...
@@ -155,7 +155,7 @@
<a
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
id=
""
<a
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
id=
""
href=
"
href=
"
{% if request.user.otp_enabled and request.user.otp_secret_key %}
{% if request.user.otp_enabled and request.user.otp_secret_key %}
{% if request.user.otp_force_enabled
or mfa_setting
%}
{% if request.user.otp_force_enabled %}
"
disabled
>
{% trans 'Disable' %}
"
disabled
>
{% trans 'Disable' %}
{% else %}
{% else %}
{% url 'users:user-otp-disable-authentication' %}
{% url 'users:user-otp-disable-authentication' %}
...
...
apps/users/views/login.py
View file @
b026e867
...
@@ -82,24 +82,17 @@ class UserLoginView(FormView):
...
@@ -82,24 +82,17 @@ class UserLoginView(FormView):
def
get_success_url
(
self
):
def
get_success_url
(
self
):
user
=
get_user_or_tmp_user
(
self
.
request
)
user
=
get_user_or_tmp_user
(
self
.
request
)
mfa_setting
=
Setting
.
objects
.
filter
(
name
=
'SECURITY_MFA_AUTH'
)
.
first
()
if
user
.
otp_enabled
and
user
.
otp_secret_key
:
if
mfa_setting
and
mfa_setting
.
cleaned_value
:
# 1,2 & T
if
user
.
otp_enabled
and
user
.
otp_secret_key
:
return
reverse
(
'users:login-otp'
)
return
reverse
(
'users:login-otp'
)
elif
user
.
otp_enabled
and
not
user
.
otp_secret_key
:
else
:
# 1,2 & F
return
reverse
(
'users:user-otp-enable-authentication'
)
return
reverse
(
'users:user-otp-enable-authentication'
)
else
:
elif
not
user
.
otp_enabled
:
if
user
.
otp_enabled
and
user
.
otp_secret_key
:
# 0 & T,F
# 1,2 & T
auth_login
(
self
.
request
,
user
)
return
reverse
(
'users:login-otp'
)
self
.
write_login_log
()
elif
user
.
otp_enabled
and
not
user
.
otp_secret_key
:
return
redirect_user_first_login_or_index
(
self
.
request
,
self
.
redirect_field_name
)
# 1,2 & F
return
reverse
(
'users:user-otp-enable-authentication'
)
elif
not
user
.
otp_enabled
:
# 0 & T,F
auth_login
(
self
.
request
,
user
)
self
.
write_login_log
()
return
redirect_user_first_login_or_index
(
self
.
request
,
self
.
redirect_field_name
)
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
context
=
{
...
...
apps/users/views/user.py
View file @
b026e867
...
@@ -337,7 +337,6 @@ class UserProfileView(LoginRequiredMixin, TemplateView):
...
@@ -337,7 +337,6 @@ class UserProfileView(LoginRequiredMixin, TemplateView):
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
mfa_setting
=
Setting
.
objects
.
filter
(
name
=
'SECURITY_MFA_AUTH'
)
.
first
()
mfa_setting
=
Setting
.
objects
.
filter
(
name
=
'SECURITY_MFA_AUTH'
)
.
first
()
context
=
{
context
=
{
'action'
:
_
(
'Profile'
),
'action'
:
_
(
'Profile'
),
'mfa_setting'
:
mfa_setting
.
cleaned_value
if
mfa_setting
else
False
,
'mfa_setting'
:
mfa_setting
.
cleaned_value
if
mfa_setting
else
False
,
...
...
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