perf: 优化忘记密码,用户无手机号时无法使用手机号重置密码

pull/9060/head
jiangweidong 2022-11-14 17:16:30 +08:00 committed by Jiangjie.Bai
parent 7280c6726e
commit b6f86e8fb6
6 changed files with 227 additions and 183 deletions

View File

@ -4,6 +4,7 @@ from rest_framework.permissions import AllowAny
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.core.cache import cache from django.core.cache import cache
from django.shortcuts import reverse
from common.utils.verify_code import SendAndVerifyCodeUtil from common.utils.verify_code import SendAndVerifyCodeUtil
from common.permissions import IsValidUser from common.permissions import IsValidUser
@ -37,10 +38,14 @@ class UserResetPasswordSendCodeApi(CreateAPIView):
return user, None return user, None
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
token = request.GET.get('token')
userinfo = cache.get(token)
if not userinfo:
return reverse('authentication:forgot-previewing')
serializer = self.get_serializer(data=request.data) serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
token = request.GET.get('token') username = userinfo.get('username')
username = cache.get(token)
form_type = serializer.validated_data['form_type'] form_type = serializer.validated_data['form_type']
code = random_string(6, lower=False, upper=False) code = random_string(6, lower=False, upper=False)
other_args = {} other_args = {}

View File

@ -62,7 +62,7 @@ class CustomCaptchaTextInput(CaptchaTextInput):
class CaptchaMixin(forms.Form): class CaptchaMixin(forms.Form):
captcha = CaptchaField(widget=CustomCaptchaTextInput) captcha = CaptchaField(widget=CustomCaptchaTextInput, label=_('Captcha'))
class ChallengeMixin(forms.Form): class ChallengeMixin(forms.Form):

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-10 16:37+0800\n" "POT-Creation-Date: 2022-11-14 17:07+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -161,7 +161,7 @@ msgstr "コンマ区切り文字列の形式。* はすべて一致すること
#: authentication/models.py:260 #: authentication/models.py:260
#: authentication/templates/authentication/_msg_different_city.html:9 #: authentication/templates/authentication/_msg_different_city.html:9
#: authentication/templates/authentication/_msg_oauth_bind.html:9 #: authentication/templates/authentication/_msg_oauth_bind.html:9
#: ops/models/adhoc.py:159 users/forms/profile.py:32 users/forms/profile.py:109 #: ops/models/adhoc.py:159 users/forms/profile.py:32 users/forms/profile.py:112
#: users/models/user.py:671 users/templates/users/_msg_user_created.html:12 #: users/models/user.py:671 users/templates/users/_msg_user_created.html:12
#: xpack/plugins/change_auth_plan/models/asset.py:34 #: xpack/plugins/change_auth_plan/models/asset.py:34
#: xpack/plugins/change_auth_plan/models/asset.py:195 #: xpack/plugins/change_auth_plan/models/asset.py:195
@ -224,7 +224,7 @@ msgid "None of the reviewers belong to Organization `{}`"
msgstr "いずれのレビューアも組織 '{}' に属していません" msgstr "いずれのレビューアも組織 '{}' に属していません"
#: acls/serializers/rules/rules.py:20 #: acls/serializers/rules/rules.py:20
#: xpack/plugins/cloud/serializers/task.py:23 #: xpack/plugins/cloud/serializers/task.py:24
msgid "IP address invalid: `{}`" msgid "IP address invalid: `{}`"
msgstr "IPアドレスが無効: '{}'" msgstr "IPアドレスが無効: '{}'"
@ -324,7 +324,7 @@ msgstr "タイプ"
msgid "Domain" msgid "Domain"
msgstr "ドメイン" msgstr "ドメイン"
#: applications/models/application.py:230 xpack/plugins/cloud/models.py:33 #: applications/models/application.py:230 xpack/plugins/cloud/models.py:32
#: xpack/plugins/cloud/serializers/account.py:64 #: xpack/plugins/cloud/serializers/account.py:64
msgid "Attrs" msgid "Attrs"
msgstr "ツールバーの" msgstr "ツールバーの"
@ -363,7 +363,7 @@ msgstr "タイプ表示"
#: orgs/models.py:72 orgs/models.py:223 perms/models/base.py:92 #: orgs/models.py:72 orgs/models.py:223 perms/models/base.py:92
#: users/models/group.py:18 users/models/user.py:937 #: users/models/group.py:18 users/models/user.py:937
#: xpack/plugins/change_auth_plan/models/base.py:45 #: xpack/plugins/change_auth_plan/models/base.py:45
#: xpack/plugins/cloud/models.py:125 #: xpack/plugins/cloud/models.py:127
msgid "Date created" msgid "Date created"
msgstr "作成された日付" msgstr "作成された日付"
@ -608,7 +608,7 @@ msgstr "ホスト名生"
#: assets/models/asset.py:215 assets/serializers/account.py:16 #: assets/models/asset.py:215 assets/serializers/account.py:16
#: assets/serializers/asset.py:65 perms/serializers/asset/user_permission.py:41 #: assets/serializers/asset.py:65 perms/serializers/asset/user_permission.py:41
#: xpack/plugins/cloud/models.py:107 xpack/plugins/cloud/serializers/task.py:43 #: xpack/plugins/cloud/models.py:106 xpack/plugins/cloud/serializers/task.py:44
msgid "Protocols" msgid "Protocols"
msgstr "プロトコル" msgstr "プロトコル"
@ -630,7 +630,7 @@ msgstr "アクティブです。"
msgid "Admin user" msgid "Admin user"
msgstr "管理ユーザー" msgstr "管理ユーザー"
#: assets/models/asset.py:225 #: assets/models/asset.py:225 xpack/plugins/cloud/const.py:32
msgid "Public IP" msgid "Public IP"
msgstr "パブリックIP" msgstr "パブリックIP"
@ -649,7 +649,7 @@ msgstr "ラベル"
#: orgs/models.py:225 perms/models/base.py:91 users/models/user.py:720 #: orgs/models.py:225 perms/models/base.py:91 users/models/user.py:720
#: users/serializers/group.py:33 #: users/serializers/group.py:33
#: xpack/plugins/change_auth_plan/models/base.py:48 #: xpack/plugins/change_auth_plan/models/base.py:48
#: xpack/plugins/cloud/models.py:122 xpack/plugins/gathered_user/models.py:30 #: xpack/plugins/cloud/models.py:124 xpack/plugins/gathered_user/models.py:30
msgid "Created by" msgid "Created by"
msgstr "によって作成された" msgstr "によって作成された"
@ -761,7 +761,7 @@ msgstr "トリガーモード"
#: xpack/plugins/change_auth_plan/models/base.py:201 #: xpack/plugins/change_auth_plan/models/base.py:201
#: xpack/plugins/change_auth_plan/serializers/app.py:66 #: xpack/plugins/change_auth_plan/serializers/app.py:66
#: xpack/plugins/change_auth_plan/serializers/asset.py:180 #: xpack/plugins/change_auth_plan/serializers/asset.py:180
#: xpack/plugins/cloud/models.py:179 #: xpack/plugins/cloud/models.py:181
msgid "Reason" msgid "Reason"
msgstr "理由" msgstr "理由"
@ -791,7 +791,7 @@ msgstr "OK"
#: assets/models/base.py:32 audits/models.py:136 #: assets/models/base.py:32 audits/models.py:136
#: xpack/plugins/change_auth_plan/serializers/app.py:88 #: xpack/plugins/change_auth_plan/serializers/app.py:88
#: xpack/plugins/change_auth_plan/serializers/asset.py:199 #: xpack/plugins/change_auth_plan/serializers/asset.py:199
#: xpack/plugins/cloud/const.py:36 #: xpack/plugins/cloud/const.py:41
msgid "Failed" msgid "Failed"
msgstr "失敗しました" msgstr "失敗しました"
@ -842,10 +842,7 @@ msgstr "帯域幅"
msgid "Contact" msgid "Contact"
msgstr "連絡先" msgstr "連絡先"
#: assets/models/cluster.py:22 authentication/serializers/password_mfa.py:25 #: assets/models/cluster.py:22 users/models/user.py:693
#: users/forms/profile.py:103 users/models/user.py:693
#: users/templates/users/forgot_password.html:55
#: users/templates/users/forgot_password.html:121
msgid "Phone" msgid "Phone"
msgstr "電話" msgstr "電話"
@ -1011,7 +1008,7 @@ msgid "Parent key"
msgstr "親キー" msgstr "親キー"
#: assets/models/node.py:566 assets/serializers/system_user.py:267 #: assets/models/node.py:566 assets/serializers/system_user.py:267
#: xpack/plugins/cloud/models.py:96 xpack/plugins/cloud/serializers/task.py:70 #: xpack/plugins/cloud/models.py:95 xpack/plugins/cloud/serializers/task.py:72
msgid "Node" msgid "Node"
msgstr "ノード" msgstr "ノード"
@ -1168,8 +1165,8 @@ msgstr "CPU情報"
msgid "Actions" msgid "Actions"
msgstr "アクション" msgstr "アクション"
#: assets/serializers/backup.py:31 ops/mixin.py:106 ops/mixin.py:147 #: assets/serializers/backup.py:31 ops/mixin.py:26 ops/mixin.py:106
#: settings/serializers/auth/ldap.py:66 #: ops/mixin.py:147 settings/serializers/auth/ldap.py:66
#: xpack/plugins/change_auth_plan/serializers/base.py:43 #: xpack/plugins/change_auth_plan/serializers/base.py:43
msgid "Periodic perform" msgid "Periodic perform"
msgstr "定期的なパフォーマンス" msgstr "定期的なパフォーマンス"
@ -1579,8 +1576,8 @@ msgid "MFA"
msgstr "MFA" msgstr "MFA"
#: audits/models.py:146 terminal/models/status.py:33 #: audits/models.py:146 terminal/models/status.py:33
#: tickets/models/ticket/general.py:281 xpack/plugins/cloud/models.py:175 #: tickets/models/ticket/general.py:281 xpack/plugins/cloud/models.py:177
#: xpack/plugins/cloud/models.py:227 #: xpack/plugins/cloud/models.py:229
msgid "Status" msgid "Status"
msgstr "ステータス" msgstr "ステータス"
@ -1617,7 +1614,7 @@ msgid "Hosts display"
msgstr "ホスト表示" msgstr "ホスト表示"
#: audits/serializers.py:102 ops/models/command.py:27 #: audits/serializers.py:102 ops/models/command.py:27
#: xpack/plugins/cloud/models.py:173 #: xpack/plugins/cloud/models.py:175
msgid "Result" msgid "Result"
msgstr "結果" msgstr "結果"
@ -1681,16 +1678,16 @@ msgstr "この操作には、MFAを検証する必要があります"
msgid "Current user not support mfa type: {}" msgid "Current user not support mfa type: {}"
msgstr "現在のユーザーはmfaタイプをサポートしていません: {}" msgstr "現在のユーザーはmfaタイプをサポートしていません: {}"
#: authentication/api/password.py:30 terminal/api/session.py:224 #: authentication/api/password.py:31 terminal/api/session.py:224
#: users/views/profile/reset.py:45 users/views/profile/reset.py:107 #: users/views/profile/reset.py:44
msgid "User does not exist: {}" msgid "User does not exist: {}"
msgstr "ユーザーが存在しない: {}" msgstr "ユーザーが存在しない: {}"
#: authentication/api/password.py:30 #: authentication/api/password.py:31 users/views/profile/reset.py:122
msgid "No user matched" msgid "No user matched"
msgstr "ユーザーにマッチしなかった" msgstr "ユーザーにマッチしなかった"
#: authentication/api/password.py:34 #: authentication/api/password.py:35
msgid "" msgid ""
"The user is from {}, please go to the corresponding system to change the " "The user is from {}, please go to the corresponding system to change the "
"password" "password"
@ -1698,10 +1695,10 @@ msgstr ""
"ユーザーは {}からです。対応するシステムにアクセスしてパスワードを変更してくだ" "ユーザーは {}からです。対応するシステムにアクセスしてパスワードを変更してくだ"
"さい。" "さい。"
#: authentication/api/password.py:61 #: authentication/api/password.py:59
#: authentication/templates/authentication/login.html:256 #: authentication/templates/authentication/login.html:256
#: users/templates/users/forgot_password.html:33 #: users/templates/users/forgot_password.html:27
#: users/templates/users/forgot_password.html:34 #: users/templates/users/forgot_password.html:28
#: users/templates/users/forgot_password_previewing.html:13 #: users/templates/users/forgot_password_previewing.html:13
#: users/templates/users/forgot_password_previewing.html:14 #: users/templates/users/forgot_password_previewing.html:14
msgid "Forgot password" msgid "Forgot password"
@ -1957,6 +1954,11 @@ msgstr "MFAコード"
msgid "MFA type" msgid "MFA type"
msgstr "MFAタイプ" msgstr "MFAタイプ"
#: authentication/forms.py:65
#: authentication/templates/authentication/_captcha_field.html:15
msgid "Captcha"
msgstr "キャプチャ"
#: authentication/forms.py:70 users/forms/profile.py:28 #: authentication/forms.py:70 users/forms/profile.py:28
msgid "MFA code" msgid "MFA code"
msgstr "MFAコード" msgstr "MFAコード"
@ -2012,12 +2014,15 @@ msgstr "Radius globalが有効になり、無効にできません"
#: authentication/mfa/sms.py:7 #: authentication/mfa/sms.py:7
msgid "SMS verify code invalid" msgid "SMS verify code invalid"
msgstr "SMS検証コードが無効" msgstr "メッセージ検証コードが無効"
#: authentication/mfa/sms.py:12 settings/serializers/auth/sms.py:27 #: authentication/mfa/sms.py:12 authentication/serializers/password_mfa.py:16
#: users/templates/users/forgot_password.html:74 #: authentication/serializers/password_mfa.py:24
#: settings/serializers/auth/sms.py:27 users/forms/profile.py:103
#: users/forms/profile.py:106 users/templates/users/forgot_password.html:111
#: users/views/profile/reset.py:74
msgid "SMS" msgid "SMS"
msgstr "SMS" msgstr "メッセージ"
#: authentication/mfa/sms.py:13 #: authentication/mfa/sms.py:13
msgid "SMS verification code" msgid "SMS verification code"
@ -2136,7 +2141,7 @@ msgid "binding reminder"
msgstr "バインディングリマインダー" msgstr "バインディングリマインダー"
#: authentication/serializers/connection_token.py:23 #: authentication/serializers/connection_token.py:23
#: xpack/plugins/cloud/models.py:34 #: xpack/plugins/cloud/models.py:33
msgid "Validity" msgid "Validity"
msgstr "有効性" msgstr "有効性"
@ -2148,21 +2153,21 @@ msgstr "期限切れ時間"
msgid "Asset or application required" msgid "Asset or application required"
msgstr "アセットまたはアプリが必要" msgstr "アセットまたはアプリが必要"
#: authentication/serializers/password_mfa.py:25 #: authentication/serializers/password_mfa.py:16
#: authentication/serializers/password_mfa.py:29 #: authentication/serializers/password_mfa.py:24
#: users/templates/users/forgot_password.html:117
msgid "The {} cannot be empty"
msgstr "{} 空にしてはならない"
#: authentication/serializers/password_mfa.py:29
#: notifications/backends/__init__.py:10 settings/serializers/email.py:19 #: notifications/backends/__init__.py:10 settings/serializers/email.py:19
#: settings/serializers/email.py:50 users/forms/profile.py:102 #: settings/serializers/email.py:50 users/forms/profile.py:102
#: users/models/user.py:675 users/templates/users/forgot_password.html:51 #: users/forms/profile.py:106 users/models/user.py:675
#: users/templates/users/forgot_password.html:70 #: users/templates/users/forgot_password.html:116
#: users/templates/users/forgot_password.html:126 #: users/views/profile/reset.py:68
msgid "Email" msgid "Email"
msgstr "メール" msgstr "メール"
#: authentication/serializers/password_mfa.py:29
#: users/templates/users/forgot_password.html:107
msgid "The {} cannot be empty"
msgstr "{} 空にしてはならない"
#: authentication/serializers/token.py:79 #: authentication/serializers/token.py:79
#: perms/serializers/application/permission.py:20 #: perms/serializers/application/permission.py:20
#: perms/serializers/application/permission.py:41 #: perms/serializers/application/permission.py:41
@ -2225,10 +2230,6 @@ msgstr "閉じる"
msgid "Play CAPTCHA as audio file" msgid "Play CAPTCHA as audio file"
msgstr "CAPTCHAをオーディオファイルとして再生する" msgstr "CAPTCHAをオーディオファイルとして再生する"
#: authentication/templates/authentication/_captcha_field.html:15
msgid "Captcha"
msgstr "キャプチャ"
#: authentication/templates/authentication/_mfa_confirm_modal.html:5 #: authentication/templates/authentication/_mfa_confirm_modal.html:5
msgid "MFA confirm" msgid "MFA confirm"
msgstr "MFA確認" msgstr "MFA確認"
@ -2254,7 +2255,7 @@ msgstr "コードエラー"
#: authentication/templates/authentication/_msg_reset_password_code.html:9 #: authentication/templates/authentication/_msg_reset_password_code.html:9
#: authentication/templates/authentication/_msg_rest_password_success.html:2 #: authentication/templates/authentication/_msg_rest_password_success.html:2
#: authentication/templates/authentication/_msg_rest_public_key_success.html:2 #: authentication/templates/authentication/_msg_rest_public_key_success.html:2
#: jumpserver/conf.py:406 ops/tasks.py:145 ops/tasks.py:148 #: jumpserver/conf.py:413 ops/tasks.py:145 ops/tasks.py:148
#: perms/templates/perms/_msg_item_permissions_expire.html:3 #: perms/templates/perms/_msg_item_permissions_expire.html:3
#: perms/templates/perms/_msg_permed_items_expire.html:3 #: perms/templates/perms/_msg_permed_items_expire.html:3
#: tickets/templates/tickets/approve_check_password.html:33 #: tickets/templates/tickets/approve_check_password.html:33
@ -2313,7 +2314,7 @@ msgstr "新しいものを要求する"
#: authentication/templates/authentication/_msg_reset_password_code.html:12 #: authentication/templates/authentication/_msg_reset_password_code.html:12
#: terminal/models/sharing.py:26 terminal/models/sharing.py:80 #: terminal/models/sharing.py:26 terminal/models/sharing.py:80
#: users/forms/profile.py:104 users/templates/users/forgot_password.html:59 #: users/forms/profile.py:104 users/templates/users/forgot_password.html:65
msgid "Verify code" msgid "Verify code"
msgstr "コードの確認" msgstr "コードの確認"
@ -2738,11 +2739,11 @@ msgstr "特殊文字を含むべきではない"
msgid "The mobile phone number format is incorrect" msgid "The mobile phone number format is incorrect"
msgstr "携帯電話番号の形式が正しくありません" msgstr "携帯電話番号の形式が正しくありません"
#: jumpserver/conf.py:405 #: jumpserver/conf.py:412
msgid "Create account successfully" msgid "Create account successfully"
msgstr "アカウントを正常に作成" msgstr "アカウントを正常に作成"
#: jumpserver/conf.py:407 #: jumpserver/conf.py:414
msgid "Your account has been created successfully" msgid "Your account has been created successfully"
msgstr "アカウントが正常に作成されました" msgstr "アカウントが正常に作成されました"
@ -4761,17 +4762,16 @@ msgstr ""
" " " "
#: templates/_mfa_login_field.html:28 #: templates/_mfa_login_field.html:28
#: users/templates/users/forgot_password.html:61
msgid "Send verification code" msgid "Send verification code"
msgstr "確認コードを送信" msgstr "確認コードを送信"
#: templates/_mfa_login_field.html:106 #: templates/_mfa_login_field.html:106
#: users/templates/users/forgot_password.html:139 #: users/templates/users/forgot_password.html:129
msgid "Wait: " msgid "Wait: "
msgstr "待つ:" msgstr "待つ:"
#: templates/_mfa_login_field.html:116 #: templates/_mfa_login_field.html:116
#: users/templates/users/forgot_password.html:155 #: users/templates/users/forgot_password.html:145
msgid "The verification code has been sent" msgid "The verification code has been sent"
msgstr "確認コードが送信されました" msgstr "確認コードが送信されました"
@ -5248,7 +5248,7 @@ msgstr "アクセスキー"
msgid "Access key secret" msgid "Access key secret"
msgstr "アクセスキーシークレット" msgstr "アクセスキーシークレット"
#: terminal/serializers/storage.py:65 xpack/plugins/cloud/models.py:220 #: terminal/serializers/storage.py:65 xpack/plugins/cloud/models.py:222
msgid "Region" msgid "Region"
msgstr "リージョン" msgstr "リージョン"
@ -5774,40 +5774,40 @@ msgstr "パスワードの確認"
msgid "Password does not match" msgid "Password does not match"
msgstr "パスワードが一致しない" msgstr "パスワードが一致しない"
#: users/forms/profile.py:115 #: users/forms/profile.py:118
msgid "Old password" msgid "Old password"
msgstr "古いパスワード" msgstr "古いパスワード"
#: users/forms/profile.py:125 #: users/forms/profile.py:128
msgid "Old password error" msgid "Old password error"
msgstr "古いパスワードエラー" msgstr "古いパスワードエラー"
#: users/forms/profile.py:135 #: users/forms/profile.py:138
msgid "Automatically configure and download the SSH key" msgid "Automatically configure and download the SSH key"
msgstr "SSHキーの自動設定とダウンロード" msgstr "SSHキーの自動設定とダウンロード"
#: users/forms/profile.py:137 #: users/forms/profile.py:140
msgid "ssh public key" msgid "ssh public key"
msgstr "ssh公開キー" msgstr "ssh公開キー"
#: users/forms/profile.py:138 #: users/forms/profile.py:141
msgid "ssh-rsa AAAA..." msgid "ssh-rsa AAAA..."
msgstr "ssh-rsa AAAA.." msgstr "ssh-rsa AAAA.."
#: users/forms/profile.py:139 #: users/forms/profile.py:142
msgid "Paste your id_rsa.pub here." msgid "Paste your id_rsa.pub here."
msgstr "ここにid_rsa.pubを貼り付けます。" msgstr "ここにid_rsa.pubを貼り付けます。"
#: users/forms/profile.py:152 #: users/forms/profile.py:155
msgid "Public key should not be the same as your old one." msgid "Public key should not be the same as your old one."
msgstr "公開鍵は古いものと同じであってはなりません。" msgstr "公開鍵は古いものと同じであってはなりません。"
#: users/forms/profile.py:156 users/serializers/profile.py:100 #: users/forms/profile.py:159 users/serializers/profile.py:100
#: users/serializers/profile.py:183 users/serializers/profile.py:210 #: users/serializers/profile.py:183 users/serializers/profile.py:210
msgid "Not a valid ssh public key" msgid "Not a valid ssh public key"
msgstr "有効なssh公開鍵ではありません" msgstr "有効なssh公開鍵ではありません"
#: users/forms/profile.py:167 users/models/user.py:706 #: users/forms/profile.py:170 users/models/user.py:706
msgid "Public key" msgid "Public key"
msgstr "公開キー" msgstr "公開キー"
@ -5887,7 +5887,7 @@ msgstr "ユーザーパスワード履歴"
msgid "Reset password" msgid "Reset password"
msgstr "パスワードのリセット" msgstr "パスワードのリセット"
#: users/notifications.py:85 users/views/profile/reset.py:172 #: users/notifications.py:85 users/views/profile/reset.py:189
msgid "Reset password success" msgid "Reset password success"
msgstr "パスワードのリセット成功" msgstr "パスワードのリセット成功"
@ -6079,11 +6079,28 @@ msgstr "あなたのssh公開鍵はサイト管理者によってリセットさ
msgid "click here to set your password" msgid "click here to set your password"
msgstr "ここをクリックしてパスワードを設定してください" msgstr "ここをクリックしてパスワードを設定してください"
#: users/templates/users/forgot_password.html:38 #: users/templates/users/forgot_password.html:32
msgid "Input your email, that will send a mail to your" msgid "Input your email account, that will send a email to your"
msgstr "あなたのメールを入力し、それはあなたにメールを送信します" msgstr "電子メールアカウントを入力し、メールをメールアドレスに送信します"
#: users/templates/users/forgot_password.html:64 #: users/templates/users/forgot_password.html:35
msgid ""
"Enter your mobile number and a verification code will be sent to your phone"
msgstr "携帯電話番号を入力すると認証コードが送信されます"
#: users/templates/users/forgot_password.html:57
msgid "Email account"
msgstr "メールアドレスアカウント"
#: users/templates/users/forgot_password.html:61
msgid "Mobile number"
msgstr "携帯番号"
#: users/templates/users/forgot_password.html:68
msgid "Send"
msgstr "送信"
#: users/templates/users/forgot_password.html:72
#: users/templates/users/forgot_password_previewing.html:30 #: users/templates/users/forgot_password_previewing.html:30
msgid "Submit" msgid "Submit"
msgstr "送信" msgstr "送信"
@ -6234,23 +6251,23 @@ msgstr "OTP無効化成功、ログインページを返す"
msgid "Password invalid" msgid "Password invalid"
msgstr "パスワード無効" msgstr "パスワード無効"
#: users/views/profile/reset.py:96 users/views/profile/reset.py:107 #: users/views/profile/reset.py:144 users/views/profile/reset.py:155
msgid "Token invalid or expired" msgid "Token invalid or expired"
msgstr "トークンが無効または期限切れ" msgstr "トークンが無効または期限切れ"
#: users/views/profile/reset.py:145 #: users/views/profile/reset.py:160
msgid "User auth from {}, go there change password" msgid "User auth from {}, go there change password"
msgstr "ユーザー認証ソース {}, 対応するシステムにパスワードを変更してください" msgstr "ユーザー認証ソース {}, 対応するシステムにパスワードを変更してください"
#: users/views/profile/reset.py:152 #: users/views/profile/reset.py:167
msgid "* Your password does not meet the requirements" msgid "* Your password does not meet the requirements"
msgstr "* パスワードが要件を満たしていない" msgstr "* パスワードが要件を満たしていない"
#: users/views/profile/reset.py:158 #: users/views/profile/reset.py:173
msgid "* The new password cannot be the last {} passwords" msgid "* The new password cannot be the last {} passwords"
msgstr "* 新しいパスワードを最後の {} パスワードにすることはできません" msgstr "* 新しいパスワードを最後の {} パスワードにすることはできません"
#: users/views/profile/reset.py:173 #: users/views/profile/reset.py:190
msgid "Reset password success, return to login page" msgid "Reset password success, return to login page"
msgstr "パスワードの成功をリセットし、ログインページに戻る" msgstr "パスワードの成功をリセットし、ログインページに戻る"
@ -6521,27 +6538,27 @@ msgstr "プライベートIP"
msgid "Instance name" msgid "Instance name"
msgstr "インスタンス名" msgstr "インスタンス名"
#: xpack/plugins/cloud/const.py:32 #: xpack/plugins/cloud/const.py:37
msgid "Instance name and Partial IP" msgid "Instance name and Partial IP"
msgstr "インスタンス名と部分IP" msgstr "インスタンス名と部分IP"
#: xpack/plugins/cloud/const.py:37 #: xpack/plugins/cloud/const.py:42
msgid "Succeed" msgid "Succeed"
msgstr "成功" msgstr "成功"
#: xpack/plugins/cloud/const.py:41 #: xpack/plugins/cloud/const.py:46
msgid "Unsync" msgid "Unsync"
msgstr "同期していません" msgstr "同期していません"
#: xpack/plugins/cloud/const.py:42 #: xpack/plugins/cloud/const.py:47
msgid "New Sync" msgid "New Sync"
msgstr "新しい同期" msgstr "新しい同期"
#: xpack/plugins/cloud/const.py:43 #: xpack/plugins/cloud/const.py:48
msgid "Synced" msgid "Synced"
msgstr "同期済み" msgstr "同期済み"
#: xpack/plugins/cloud/const.py:44 #: xpack/plugins/cloud/const.py:49
msgid "Released" msgid "Released"
msgstr "リリース済み" msgstr "リリース済み"
@ -6549,19 +6566,19 @@ msgstr "リリース済み"
msgid "Cloud center" msgid "Cloud center"
msgstr "クラウドセンター" msgstr "クラウドセンター"
#: xpack/plugins/cloud/models.py:30 #: xpack/plugins/cloud/models.py:29
msgid "Provider" msgid "Provider"
msgstr "プロバイダー" msgstr "プロバイダー"
#: xpack/plugins/cloud/models.py:39 #: xpack/plugins/cloud/models.py:38
msgid "Cloud account" msgid "Cloud account"
msgstr "クラウドアカウント" msgstr "クラウドアカウント"
#: xpack/plugins/cloud/models.py:41 #: xpack/plugins/cloud/models.py:40
msgid "Test cloud account" msgid "Test cloud account"
msgstr "クラウドアカウントのテスト" msgstr "クラウドアカウントのテスト"
#: xpack/plugins/cloud/models.py:85 xpack/plugins/cloud/serializers/task.py:67 #: xpack/plugins/cloud/models.py:84 xpack/plugins/cloud/serializers/task.py:69
msgid "Account" msgid "Account"
msgstr "アカウント" msgstr "アカウント"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: JumpServer 0.3.3\n" "Project-Id-Version: JumpServer 0.3.3\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-10 10:55+0800\n" "POT-Creation-Date: 2022-11-14 17:07+0800\n"
"PO-Revision-Date: 2021-05-20 10:54+0800\n" "PO-Revision-Date: 2021-05-20 10:54+0800\n"
"Last-Translator: ibuler <ibuler@qq.com>\n" "Last-Translator: ibuler <ibuler@qq.com>\n"
"Language-Team: JumpServer team<ibuler@qq.com>\n" "Language-Team: JumpServer team<ibuler@qq.com>\n"
@ -160,7 +160,7 @@ msgstr "格式为逗号分隔的字符串, * 表示匹配所有. "
#: authentication/models.py:260 #: authentication/models.py:260
#: authentication/templates/authentication/_msg_different_city.html:9 #: authentication/templates/authentication/_msg_different_city.html:9
#: authentication/templates/authentication/_msg_oauth_bind.html:9 #: authentication/templates/authentication/_msg_oauth_bind.html:9
#: ops/models/adhoc.py:159 users/forms/profile.py:32 users/forms/profile.py:109 #: ops/models/adhoc.py:159 users/forms/profile.py:32 users/forms/profile.py:112
#: users/models/user.py:671 users/templates/users/_msg_user_created.html:12 #: users/models/user.py:671 users/templates/users/_msg_user_created.html:12
#: xpack/plugins/change_auth_plan/models/asset.py:34 #: xpack/plugins/change_auth_plan/models/asset.py:34
#: xpack/plugins/change_auth_plan/models/asset.py:195 #: xpack/plugins/change_auth_plan/models/asset.py:195
@ -837,10 +837,7 @@ msgstr "带宽"
msgid "Contact" msgid "Contact"
msgstr "联系人" msgstr "联系人"
#: assets/models/cluster.py:22 authentication/serializers/password_mfa.py:25 #: assets/models/cluster.py:22 users/models/user.py:693
#: users/forms/profile.py:103 users/models/user.py:693
#: users/templates/users/forgot_password.html:55
#: users/templates/users/forgot_password.html:121
msgid "Phone" msgid "Phone"
msgstr "手机" msgstr "手机"
@ -1669,25 +1666,25 @@ msgstr "此操作需要验证您的 MFA"
msgid "Current user not support mfa type: {}" msgid "Current user not support mfa type: {}"
msgstr "当前用户不支持 MFA 类型: {}" msgstr "当前用户不支持 MFA 类型: {}"
#: authentication/api/password.py:30 terminal/api/session.py:224 #: authentication/api/password.py:31 terminal/api/session.py:224
#: users/views/profile/reset.py:45 users/views/profile/reset.py:107 #: users/views/profile/reset.py:44
msgid "User does not exist: {}" msgid "User does not exist: {}"
msgstr "用户不存在: {}" msgstr "用户不存在: {}"
#: authentication/api/password.py:30 #: authentication/api/password.py:31 users/views/profile/reset.py:122
msgid "No user matched" msgid "No user matched"
msgstr "没有匹配到用户" msgstr "没有匹配到用户"
#: authentication/api/password.py:34 #: authentication/api/password.py:35
msgid "" msgid ""
"The user is from {}, please go to the corresponding system to change the " "The user is from {}, please go to the corresponding system to change the "
"password" "password"
msgstr "用户来自 {} 请去相应系统修改密码" msgstr "用户来自 {} 请去相应系统修改密码"
#: authentication/api/password.py:61 #: authentication/api/password.py:59
#: authentication/templates/authentication/login.html:256 #: authentication/templates/authentication/login.html:256
#: users/templates/users/forgot_password.html:33 #: users/templates/users/forgot_password.html:27
#: users/templates/users/forgot_password.html:34 #: users/templates/users/forgot_password.html:28
#: users/templates/users/forgot_password_previewing.html:13 #: users/templates/users/forgot_password_previewing.html:13
#: users/templates/users/forgot_password_previewing.html:14 #: users/templates/users/forgot_password_previewing.html:14
msgid "Forgot password" msgid "Forgot password"
@ -1934,6 +1931,11 @@ msgstr "MFA 验证码"
msgid "MFA type" msgid "MFA type"
msgstr "MFA 类型" msgstr "MFA 类型"
#: authentication/forms.py:65
#: authentication/templates/authentication/_captcha_field.html:15
msgid "Captcha"
msgstr "验证码"
#: authentication/forms.py:70 users/forms/profile.py:28 #: authentication/forms.py:70 users/forms/profile.py:28
msgid "MFA code" msgid "MFA code"
msgstr "MFA 验证码" msgstr "MFA 验证码"
@ -1990,8 +1992,11 @@ msgstr "Radius MFA 全局开启,无法被禁用"
msgid "SMS verify code invalid" msgid "SMS verify code invalid"
msgstr "短信验证码校验失败" msgstr "短信验证码校验失败"
#: authentication/mfa/sms.py:12 settings/serializers/auth/sms.py:27 #: authentication/mfa/sms.py:12 authentication/serializers/password_mfa.py:16
#: users/templates/users/forgot_password.html:74 #: authentication/serializers/password_mfa.py:24
#: settings/serializers/auth/sms.py:27 users/forms/profile.py:103
#: users/forms/profile.py:106 users/templates/users/forgot_password.html:111
#: users/views/profile/reset.py:74
msgid "SMS" msgid "SMS"
msgstr "短信" msgstr "短信"
@ -2120,20 +2125,20 @@ msgstr "过期时间"
msgid "Asset or application required" msgid "Asset or application required"
msgstr "资产或应用必填" msgstr "资产或应用必填"
#: authentication/serializers/password_mfa.py:25 #: authentication/serializers/password_mfa.py:16
#: authentication/serializers/password_mfa.py:29 #: authentication/serializers/password_mfa.py:24
#: users/templates/users/forgot_password.html:117
msgid "The {} cannot be empty"
msgstr "{} 不能为空"
#: authentication/serializers/password_mfa.py:29
#: notifications/backends/__init__.py:10 settings/serializers/email.py:19 #: notifications/backends/__init__.py:10 settings/serializers/email.py:19
#: settings/serializers/email.py:50 users/forms/profile.py:102 #: settings/serializers/email.py:50 users/forms/profile.py:102
#: users/models/user.py:675 users/templates/users/forgot_password.html:51 #: users/forms/profile.py:106 users/models/user.py:675
#: users/templates/users/forgot_password.html:70 #: users/templates/users/forgot_password.html:116
#: users/templates/users/forgot_password.html:126 #: users/views/profile/reset.py:68
msgid "Email" msgid "Email"
msgstr "邮件" msgstr "邮箱"
#: authentication/serializers/password_mfa.py:29
#: users/templates/users/forgot_password.html:107
msgid "The {} cannot be empty"
msgstr "{} 不能为空"
#: authentication/serializers/token.py:79 #: authentication/serializers/token.py:79
#: perms/serializers/application/permission.py:20 #: perms/serializers/application/permission.py:20
@ -2197,10 +2202,6 @@ msgstr "关闭"
msgid "Play CAPTCHA as audio file" msgid "Play CAPTCHA as audio file"
msgstr "语言播放验证码" msgstr "语言播放验证码"
#: authentication/templates/authentication/_captcha_field.html:15
msgid "Captcha"
msgstr "验证码"
#: authentication/templates/authentication/_mfa_confirm_modal.html:5 #: authentication/templates/authentication/_mfa_confirm_modal.html:5
msgid "MFA confirm" msgid "MFA confirm"
msgstr "MFA 认证校验" msgstr "MFA 认证校验"
@ -2226,7 +2227,7 @@ msgstr "代码错误"
#: authentication/templates/authentication/_msg_reset_password_code.html:9 #: authentication/templates/authentication/_msg_reset_password_code.html:9
#: authentication/templates/authentication/_msg_rest_password_success.html:2 #: authentication/templates/authentication/_msg_rest_password_success.html:2
#: authentication/templates/authentication/_msg_rest_public_key_success.html:2 #: authentication/templates/authentication/_msg_rest_public_key_success.html:2
#: jumpserver/conf.py:406 ops/tasks.py:145 ops/tasks.py:148 #: jumpserver/conf.py:413 ops/tasks.py:145 ops/tasks.py:148
#: perms/templates/perms/_msg_item_permissions_expire.html:3 #: perms/templates/perms/_msg_item_permissions_expire.html:3
#: perms/templates/perms/_msg_permed_items_expire.html:3 #: perms/templates/perms/_msg_permed_items_expire.html:3
#: tickets/templates/tickets/approve_check_password.html:33 #: tickets/templates/tickets/approve_check_password.html:33
@ -2281,7 +2282,7 @@ msgstr "重新申请"
#: authentication/templates/authentication/_msg_reset_password_code.html:12 #: authentication/templates/authentication/_msg_reset_password_code.html:12
#: terminal/models/sharing.py:26 terminal/models/sharing.py:80 #: terminal/models/sharing.py:26 terminal/models/sharing.py:80
#: users/forms/profile.py:104 users/templates/users/forgot_password.html:59 #: users/forms/profile.py:104 users/templates/users/forgot_password.html:65
msgid "Verify code" msgid "Verify code"
msgstr "验证码" msgstr "验证码"
@ -2701,11 +2702,11 @@ msgstr "不能包含特殊字符"
msgid "The mobile phone number format is incorrect" msgid "The mobile phone number format is incorrect"
msgstr "手机号格式不正确" msgstr "手机号格式不正确"
#: jumpserver/conf.py:405 #: jumpserver/conf.py:412
msgid "Create account successfully" msgid "Create account successfully"
msgstr "创建账号成功" msgstr "创建账号成功"
#: jumpserver/conf.py:407 #: jumpserver/conf.py:414
msgid "Your account has been created successfully" msgid "Your account has been created successfully"
msgstr "你的账号已创建成功" msgstr "你的账号已创建成功"
@ -4686,17 +4687,16 @@ msgstr ""
" " " "
#: templates/_mfa_login_field.html:28 #: templates/_mfa_login_field.html:28
#: users/templates/users/forgot_password.html:61
msgid "Send verification code" msgid "Send verification code"
msgstr "发送验证码" msgstr "发送验证码"
#: templates/_mfa_login_field.html:106 #: templates/_mfa_login_field.html:106
#: users/templates/users/forgot_password.html:139 #: users/templates/users/forgot_password.html:129
msgid "Wait: " msgid "Wait: "
msgstr "等待:" msgstr "等待:"
#: templates/_mfa_login_field.html:116 #: templates/_mfa_login_field.html:116
#: users/templates/users/forgot_password.html:155 #: users/templates/users/forgot_password.html:145
msgid "The verification code has been sent" msgid "The verification code has been sent"
msgstr "验证码已发送" msgstr "验证码已发送"
@ -5683,40 +5683,40 @@ msgstr "确认密码"
msgid "Password does not match" msgid "Password does not match"
msgstr "密码不一致" msgstr "密码不一致"
#: users/forms/profile.py:115 #: users/forms/profile.py:118
msgid "Old password" msgid "Old password"
msgstr "原来密码" msgstr "原来密码"
#: users/forms/profile.py:125 #: users/forms/profile.py:128
msgid "Old password error" msgid "Old password error"
msgstr "原来密码错误" msgstr "原来密码错误"
#: users/forms/profile.py:135 #: users/forms/profile.py:138
msgid "Automatically configure and download the SSH key" msgid "Automatically configure and download the SSH key"
msgstr "自动配置并下载SSH密钥" msgstr "自动配置并下载SSH密钥"
#: users/forms/profile.py:137 #: users/forms/profile.py:140
msgid "ssh public key" msgid "ssh public key"
msgstr "SSH公钥" msgstr "SSH公钥"
#: users/forms/profile.py:138 #: users/forms/profile.py:141
msgid "ssh-rsa AAAA..." msgid "ssh-rsa AAAA..."
msgstr "ssh-rsa AAAA..." msgstr "ssh-rsa AAAA..."
#: users/forms/profile.py:139 #: users/forms/profile.py:142
msgid "Paste your id_rsa.pub here." msgid "Paste your id_rsa.pub here."
msgstr "复制你的公钥到这里" msgstr "复制你的公钥到这里"
#: users/forms/profile.py:152 #: users/forms/profile.py:155
msgid "Public key should not be the same as your old one." msgid "Public key should not be the same as your old one."
msgstr "不能和原来的密钥相同" msgstr "不能和原来的密钥相同"
#: users/forms/profile.py:156 users/serializers/profile.py:100 #: users/forms/profile.py:159 users/serializers/profile.py:100
#: users/serializers/profile.py:183 users/serializers/profile.py:210 #: users/serializers/profile.py:183 users/serializers/profile.py:210
msgid "Not a valid ssh public key" msgid "Not a valid ssh public key"
msgstr "SSH密钥不合法" msgstr "SSH密钥不合法"
#: users/forms/profile.py:167 users/models/user.py:706 #: users/forms/profile.py:170 users/models/user.py:706
msgid "Public key" msgid "Public key"
msgstr "SSH公钥" msgstr "SSH公钥"
@ -5796,7 +5796,7 @@ msgstr "用户密码历史"
msgid "Reset password" msgid "Reset password"
msgstr "重置密码" msgstr "重置密码"
#: users/notifications.py:85 users/views/profile/reset.py:172 #: users/notifications.py:85 users/views/profile/reset.py:189
msgid "Reset password success" msgid "Reset password success"
msgstr "重置密码成功" msgstr "重置密码成功"
@ -5986,11 +5986,28 @@ msgstr "你的 SSH 密钥已经被管理员重置"
msgid "click here to set your password" msgid "click here to set your password"
msgstr "点击这里设置密码" msgstr "点击这里设置密码"
#: users/templates/users/forgot_password.html:38 #: users/templates/users/forgot_password.html:32
msgid "Input your email, that will send a mail to your" msgid "Input your email account, that will send a email to your"
msgstr "输入您的邮箱, 将会发一封重置邮件到您的邮箱中" msgstr "输入您的邮箱账号, 将会发一封重置邮件到您的邮箱中"
#: users/templates/users/forgot_password.html:64 #: users/templates/users/forgot_password.html:35
msgid ""
"Enter your mobile number and a verification code will be sent to your phone"
msgstr "输入您的手机号码,验证码将发送到您的手机"
#: users/templates/users/forgot_password.html:57
msgid "Email account"
msgstr "邮箱账号"
#: users/templates/users/forgot_password.html:61
msgid "Mobile number"
msgstr "手机号码"
#: users/templates/users/forgot_password.html:68
msgid "Send"
msgstr "发送"
#: users/templates/users/forgot_password.html:72
#: users/templates/users/forgot_password_previewing.html:30 #: users/templates/users/forgot_password_previewing.html:30
msgid "Submit" msgid "Submit"
msgstr "提交" msgstr "提交"
@ -6133,23 +6150,23 @@ msgstr "MFA(OTP) 禁用成功,返回登录页面"
msgid "Password invalid" msgid "Password invalid"
msgstr "用户名或密码无效" msgstr "用户名或密码无效"
#: users/views/profile/reset.py:129 users/views/profile/reset.py:140 #: users/views/profile/reset.py:144 users/views/profile/reset.py:155
msgid "Token invalid or expired" msgid "Token invalid or expired"
msgstr "Token错误或失效" msgstr "Token错误或失效"
#: users/views/profile/reset.py:145 #: users/views/profile/reset.py:160
msgid "User auth from {}, go there change password" msgid "User auth from {}, go there change password"
msgstr "用户认证源来自 {}, 请去相应系统修改密码" msgstr "用户认证源来自 {}, 请去相应系统修改密码"
#: users/views/profile/reset.py:152 #: users/views/profile/reset.py:167
msgid "* Your password does not meet the requirements" msgid "* Your password does not meet the requirements"
msgstr "* 您的密码不符合要求" msgstr "* 您的密码不符合要求"
#: users/views/profile/reset.py:158 #: users/views/profile/reset.py:173
msgid "* The new password cannot be the last {} passwords" msgid "* The new password cannot be the last {} passwords"
msgstr "* 新密码不能是最近 {} 次的密码" msgstr "* 新密码不能是最近 {} 次的密码"
#: users/views/profile/reset.py:173 #: users/views/profile/reset.py:190
msgid "Reset password success, return to login page" msgid "Reset password success, return to login page"
msgstr "重置密码成功,返回到登录页面" msgstr "重置密码成功,返回到登录页面"

View File

@ -29,10 +29,10 @@
{% block content %} {% block content %}
<p id="validate-email-tip" class="validate-field"> <p id="validate-email-tip" class="validate-field">
{% trans 'Input your email, that will send a mail to your' %} {% trans 'Input your email account, that will send a email to your' %}
</p> </p>
<p id="validate-sms-tip" class="validate-field"> <p id="validate-sms-tip" class="validate-field">
Enter your phone number and a verification code will be sent to your phone {% trans 'Enter your mobile number and a verification code will be sent to your phone' %}
</p> </p>
{% if 'code' in form.errors %} {% if 'code' in form.errors %}
@ -54,18 +54,18 @@
{% bootstrap_field form.form_type layout="horizontal" %} {% bootstrap_field form.form_type layout="horizontal" %}
<div id="validate-email" class="validate-field margin-bottom"> <div id="validate-email" class="validate-field margin-bottom">
<input type="email" id="email" name="email" class="form-control input-style" <input type="email" id="email" name="email" class="form-control input-style"
placeholder="{% trans 'Email' %}" value="{{ email }}"> placeholder="{% trans 'Email account' %}" value="{{ email }}">
</div> </div>
<div id="validate-sms" class="validate-field margin-bottom"> <div id="validate-sms" class="validate-field margin-bottom">
<input type="tel" id="sms" name="sms" class="form-control input-style" <input type="tel" id="sms" name="sms" class="form-control input-style"
placeholder="{% trans 'SMS' %}" value="{{ sms }}"> placeholder="{% trans 'Mobile number' %}" value="{{ sms }}">
</div> </div>
<div class="margin-bottom challenge-required"> <div class="margin-bottom challenge-required">
<input type="text" id="code" name="code" class="form-control input-style" <input type="text" id="code" name="code" class="form-control input-style"
placeholder="{% trans 'Verify code' %}"> placeholder="{% trans 'Verify code' %}">
<button class="btn btn-primary full-width btn-challenge" <button class="btn btn-primary full-width btn-challenge"
type='button' onclick="sendChallengeCode(this)"> type='button' onclick="sendChallengeCode(this)">
{% trans 'Send verification code' %} {% trans 'Send' %}
</button> </button>
</div> </div>
<div class="margin-bottom"> <div class="margin-bottom">

View File

@ -1,27 +1,26 @@
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals from __future__ import unicode_literals
from django.views.generic import RedirectView
from django.shortcuts import reverse, redirect
from django.utils.translation import ugettext as _
from django.conf import settings
from django.urls import reverse_lazy
from django.views.generic import FormView
from django.core.cache import cache
from users.notifications import ResetPasswordSuccessMsg from common.utils import FlashMessageUtil, get_object_or_none, random_string
from common.utils import get_object_or_none, FlashMessageUtil, random_string
from common.utils.verify_code import SendAndVerifyCodeUtil from common.utils.verify_code import SendAndVerifyCodeUtil
from ...models import User from django.conf import settings
from ...utils import ( from django.core.cache import cache
get_password_check_rules, check_password_rules, from django.shortcuts import redirect, reverse
) from django.urls import reverse_lazy
from ... import forms from django.utils.translation import ugettext as _
from django.views.generic import FormView, RedirectView
from users.notifications import ResetPasswordSuccessMsg
from ... import forms
from ...models import User
from ...utils import check_password_rules, get_password_check_rules
__all__ = [ __all__ = [
'UserLoginView', 'UserResetPasswordView', 'UserForgotPasswordView', 'UserLoginView',
'UserForgotPasswordPreviewingView' 'UserResetPasswordView',
'UserForgotPasswordView',
'UserForgotPasswordPreviewingView',
] ]
@ -46,7 +45,8 @@ class UserForgotPasswordPreviewingView(FormView):
return super().form_invalid(form) return super().form_invalid(form)
token = random_string(36) token = random_string(36)
cache.set(token, username, 5 * 60) user_map = {'username': user.username, 'phone': user.phone, 'email': user.email}
cache.set(token, user_map, 5 * 60)
return redirect(self.get_redirect_url(token)) return redirect(self.get_redirect_url(token))
@ -56,19 +56,18 @@ class UserForgotPasswordView(FormView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
token = self.request.GET.get('token') token = self.request.GET.get('token')
username = cache.get(token) userinfo = cache.get(token)
if not username: if not userinfo:
return redirect(self.get_redirect_url(return_previewing=True)) return redirect(self.get_redirect_url(return_previewing=True))
else: else:
return super().get(request, *args, **kwargs) context = self.get_context_data(has_phone=bool(userinfo['phone']))
return self.render_to_response(context)
@staticmethod @staticmethod
def get_validate_backends_context(): def get_validate_backends_context(has_phone):
validate_backends = [ validate_backends = [{'name': _('Email'), 'is_active': True, 'value': 'email'}]
{'name': _('Email'), 'is_active': True, 'value': 'email'}
]
if settings.XPACK_ENABLED: if settings.XPACK_ENABLED:
if settings.SMS_ENABLED: if settings.SMS_ENABLED and has_phone:
is_active = True is_active = True
else: else:
is_active = False is_active = False
@ -76,19 +75,18 @@ class UserForgotPasswordView(FormView):
validate_backends.append(sms_backend) validate_backends.append(sms_backend)
return {'validate_backends': validate_backends} return {'validate_backends': validate_backends}
def get_context_data(self, **kwargs): def get_context_data(self, has_phone=False, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
form = context['form'] form = context['form']
if getattr(form, 'errors', None):
e = getattr(form, 'errors')
context['errors'] = e
context['form_type'] = 'email'
context['XPACK_ENABLED'] = settings.XPACK_ENABLED
cleaned_data = getattr(form, 'cleaned_data', {}) cleaned_data = getattr(form, 'cleaned_data', {})
for k, v in cleaned_data.items(): for k, v in cleaned_data.items():
if v: if v:
context[k] = v context[k] = v
validate_backends = self.get_validate_backends_context()
context['form_type'] = 'email'
context['XPACK_ENABLED'] = settings.XPACK_ENABLED
validate_backends = self.get_validate_backends_context(has_phone)
context.update(validate_backends) context.update(validate_backends)
return context return context
@ -102,10 +100,15 @@ class UserForgotPasswordView(FormView):
def form_valid(self, form): def form_valid(self, form):
token = self.request.GET.get('token') token = self.request.GET.get('token')
username = cache.get(token) userinfo = cache.get(token)
if not userinfo:
return redirect(self.get_redirect_url(return_previewing=True))
username = userinfo.get('username')
form_type = form.cleaned_data['form_type'] form_type = form.cleaned_data['form_type']
code = form.cleaned_data['code']
target = form.cleaned_data[form_type] target = form.cleaned_data[form_type]
code = form.cleaned_data['code']
try: try:
sender_util = SendAndVerifyCodeUtil(target, backend=form_type) sender_util = SendAndVerifyCodeUtil(target, backend=form_type)
sender_util.verify(code) sender_util.verify(code)
@ -116,7 +119,7 @@ class UserForgotPasswordView(FormView):
query_key = 'phone' if form_type == 'sms' else form_type query_key = 'phone' if form_type == 'sms' else form_type
user = get_object_or_none(User, **{'username': username, query_key: target}) user = get_object_or_none(User, **{'username': username, query_key: target})
if not user: if not user:
form.add_error('username', _('User does not exist: {}').format(username)) form.add_error('code', _('No user matched'))
return super().form_invalid(form) return super().form_invalid(form)
return redirect(self.get_redirect_url(user)) return redirect(self.get_redirect_url(user))
@ -167,7 +170,9 @@ class UserResetPasswordView(FormView):
if user.is_history_password(password): if user.is_history_password(password):
limit_count = settings.OLD_PASSWORD_HISTORY_LIMIT_COUNT limit_count = settings.OLD_PASSWORD_HISTORY_LIMIT_COUNT
error = _('* The new password cannot be the last {} passwords').format(limit_count) error = _('* The new password cannot be the last {} passwords').format(
limit_count
)
form.add_error('new_password', error) form.add_error('new_password', error)
return self.form_invalid(form) return self.form_invalid(form)