mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-01-29 21:51:31 +00:00
perf: Custom SMS (files) support obtaining more user information. (#14486)
* perf: Custom SMS (files) support obtaining more user information. * perf: Remove the useless modules * perf: modify --------- Co-authored-by: jiangweidong <1053570670@qq.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from common.utils import validate_ssh_public_key
|
||||
@@ -103,7 +104,9 @@ class UserForgotPasswordForm(forms.Form):
|
||||
label=_('SMS'), required=False,
|
||||
help_text=_('The phone number must contain an area code, for example, +86')
|
||||
)
|
||||
code = forms.CharField(label=_('Verify code'), max_length=6, required=False)
|
||||
code = forms.CharField(
|
||||
label=_('Verify code'), max_length=settings.SMS_CODE_LENGTH, required=False
|
||||
)
|
||||
form_type = forms.ChoiceField(
|
||||
choices=[('sms', _('SMS')), ('email', _('Email'))],
|
||||
widget=forms.HiddenInput({'value': 'email'})
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
|
||||
from functools import partial
|
||||
|
||||
from django.conf import settings
|
||||
@@ -27,6 +26,7 @@ from ..models import User
|
||||
|
||||
__all__ = [
|
||||
"UserSerializer",
|
||||
"SmsUserSerializer",
|
||||
"MiniUserSerializer",
|
||||
"InviteSerializer",
|
||||
"ServiceAccountSerializer",
|
||||
@@ -411,6 +411,14 @@ class UserRetrieveSerializer(UserSerializer):
|
||||
fields = UserSerializer.Meta.fields + ["login_confirm_settings"]
|
||||
|
||||
|
||||
class SmsUserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = [
|
||||
'id', 'username', 'name', 'email', 'phone', 'source', 'is_active', 'comment'
|
||||
]
|
||||
|
||||
|
||||
class MiniUserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
|
||||
@@ -16,6 +16,7 @@ from authentication.utils import check_user_property_is_correct
|
||||
from common.const.choices import COUNTRY_CALLING_CODES
|
||||
from common.utils import FlashMessageUtil, get_object_or_none, random_string
|
||||
from common.utils.verify_code import SendAndVerifyCodeUtil
|
||||
from users.serializers import SmsUserSerializer
|
||||
from users.notifications import ResetPasswordSuccessMsg
|
||||
from ... import forms
|
||||
from ...models import User
|
||||
@@ -51,8 +52,7 @@ class UserForgotPasswordPreviewingView(FormView):
|
||||
if token_sent_at:
|
||||
raise IntervalTooShort(sent_ttl)
|
||||
token = random_string(36)
|
||||
user_info = {'username': user.username, 'phone': user.phone, 'email': user.email}
|
||||
cache.set(token, user_info, 5 * 60)
|
||||
cache.set(token, SmsUserSerializer(user).data, 5 * 60)
|
||||
cache.set(token_sent_at_key, time.time(), sent_ttl)
|
||||
return token
|
||||
|
||||
|
||||
Reference in New Issue
Block a user