Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
3e5d9496
J
jumpserver
项目概览
gjl2004yn
/
jumpserver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jumpserver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3e5d9496
编写于
5月 28, 2020
作者:
B
Bai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Update] 添加用户profile password序列类
上级
25c3691f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
65 addition
and
1 deletion
+65
-1
apps/users/api/profile.py
apps/users/api/profile.py
+22
-0
apps/users/serializers/user.py
apps/users/serializers/user.py
+41
-1
apps/users/urls/api_urls.py
apps/users/urls/api_urls.py
+2
-0
未找到文件。
apps/users/api/profile.py
浏览文件 @
3e5d9496
...
...
@@ -14,6 +14,7 @@ from .mixins import UserQuerysetMixin
__all__
=
[
'UserResetPasswordApi'
,
'UserResetPKApi'
,
'UserProfileApi'
,
'UserUpdatePKApi'
,
'UserPasswordApi'
,
'UserPublicKeyApi'
]
...
...
@@ -66,3 +67,24 @@ class UserProfileApi(generics.RetrieveUpdateAPIView):
age
=
request
.
session
.
get_expiry_age
()
request
.
session
.
set_expiry
(
age
)
return
super
().
retrieve
(
request
,
*
args
,
**
kwargs
)
class
UserPasswordApi
(
generics
.
RetrieveUpdateAPIView
):
permission_classes
=
(
IsAuthenticated
,)
serializer_class
=
serializers
.
UserUpdatePasswordSerializer
def
get_object
(
self
):
return
self
.
request
.
user
class
UserPublicKeyApi
(
generics
.
RetrieveUpdateAPIView
):
permission_classes
=
(
IsAuthenticated
,)
serializer_class
=
serializers
.
UserUpdatePublicKeySerializer
def
get_object
(
self
):
return
self
.
request
.
user
def
perform_update
(
self
,
serializer
):
user
=
self
.
get_object
()
user
.
public_key
=
serializer
.
validated_data
[
'public_key'
]
user
.
save
()
apps/users/serializers/user.py
浏览文件 @
3e5d9496
...
...
@@ -14,7 +14,8 @@ from ..models import User
__all__
=
[
'UserSerializer'
,
'UserPKUpdateSerializer'
,
'ChangeUserPasswordSerializer'
,
'ResetOTPSerializer'
,
'UserProfileSerializer'
,
'UserOrgSerializer'
'UserProfileSerializer'
,
'UserOrgSerializer'
,
'UserUpdatePasswordSerializer'
,
'UserUpdatePublicKeySerializer'
]
...
...
@@ -234,3 +235,42 @@ class UserProfileSerializer(UserSerializer):
if
callable
(
obj
.
public_key_obj
.
hash_md5
):
return
obj
.
public_key_obj
.
hash_md5
()
return
''
class
UserUpdatePasswordSerializer
(
serializers
.
ModelSerializer
):
old_password
=
serializers
.
CharField
(
required
=
True
,
max_length
=
128
,
write_only
=
True
)
new_password
=
serializers
.
CharField
(
required
=
True
,
max_length
=
128
,
write_only
=
True
)
new_password_again
=
serializers
.
CharField
(
required
=
True
,
max_length
=
128
,
write_only
=
True
)
class
Meta
:
model
=
User
fields
=
[
'old_password'
,
'new_password'
,
'new_password_again'
]
def
validate_old_password
(
self
,
value
):
if
not
self
.
instance
.
check_password
(
value
):
msg
=
'The old password is incorrect'
raise
serializers
.
ValidationError
(
msg
)
return
value
@
staticmethod
def
validate_new_password
(
value
):
from
..utils
import
check_password_rules
if
not
check_password_rules
(
value
):
msg
=
_
(
'Password does not match security rules'
)
raise
serializers
.
ValidationError
(
msg
)
return
value
def
validate_new_password_again
(
self
,
value
):
if
value
!=
self
.
initial_data
.
get
(
'new_password'
,
''
):
msg
=
'The newly set password is inconsistent'
raise
serializers
.
ValidationError
(
msg
)
return
value
def
update
(
self
,
instance
,
validated_data
):
new_password
=
self
.
validated_data
.
get
(
'new_password'
)
instance
.
reset_password
(
new_password
)
return
instance
class
UserUpdatePublicKeySerializer
(
serializers
.
ModelSerializer
):
pass
apps/users/urls/api_urls.py
浏览文件 @
3e5d9496
...
...
@@ -21,6 +21,8 @@ urlpatterns = [
path
(
'connection-token/'
,
auth_api
.
UserConnectionTokenApi
.
as_view
(),
name
=
'connection-token'
),
path
(
'profile/'
,
api
.
UserProfileApi
.
as_view
(),
name
=
'user-profile'
),
path
(
'profile/password/'
,
api
.
UserPasswordApi
.
as_view
(),
name
=
'user-password'
),
path
(
'profile/public-key/'
,
api
.
UserPublicKeyApi
.
as_view
(),
name
=
'user-public-key'
),
path
(
'otp/reset/'
,
api
.
UserResetOTPApi
.
as_view
(),
name
=
'my-otp-reset'
),
path
(
'users/<uuid:pk>/otp/reset/'
,
api
.
UserResetOTPApi
.
as_view
(),
name
=
'user-reset-otp'
),
path
(
'users/<uuid:pk>/password/'
,
api
.
UserChangePasswordApi
.
as_view
(),
name
=
'change-user-password'
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录