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
b90960e6
Commit
b90960e6
authored
Dec 20, 2019
by
BaiJiangJie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改校验用户有效性逻辑
parent
a88db3d9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
21 deletions
+5
-21
utils.py
apps/authentication/utils.py
+5
-21
No files found.
apps/authentication/utils.py
View file @
b90960e6
# -*- coding: utf-8 -*-
#
from
django.utils.translation
import
ugettext
as
_
from
django.contrib.auth
import
authenticate
from
common.utils
import
(
get_ip_city
,
get_object_or_none
,
validate_ip
)
from
users.models
import
User
from
.
import
errors
def
check_user_valid
(
**
kwargs
):
password
=
kwargs
.
pop
(
'password'
,
None
)
public_key
=
kwargs
.
pop
(
'public_key'
,
None
)
email
=
kwargs
.
pop
(
'email'
,
None
)
username
=
kwargs
.
pop
(
'username'
,
None
)
request
=
kwargs
.
get
(
'request'
)
if
username
:
user
=
get_object_or_none
(
User
,
username
=
username
)
elif
email
:
user
=
get_object_or_none
(
User
,
email
=
email
)
else
:
user
=
None
if
user
is
None
:
return
None
,
errors
.
reason_user_not_exist
user
=
authenticate
(
request
,
username
=
username
,
password
=
password
,
public_key
=
public_key
)
if
not
user
:
return
None
,
errors
.
reason_password_failed
elif
user
.
is_expired
:
return
None
,
errors
.
reason_user_inactive
elif
not
user
.
is_active
:
...
...
@@ -33,9 +22,4 @@ def check_user_valid(**kwargs):
elif
user
.
password_has_expired
:
return
None
,
errors
.
reason_password_expired
if
password
or
public_key
:
user
=
authenticate
(
request
,
username
=
username
,
password
=
password
,
public_key
=
public_key
)
if
user
:
return
user
,
''
return
None
,
errors
.
reason_password_failed
return
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