mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 12:37:20 +08:00
Feat: change user email freezes limit (#22912)
Co-authored-by: Yansong Zhang <916125788@qq.com>
This commit is contained in:
parent
206bc4b36d
commit
d6b980a2dd
@ -511,6 +511,8 @@ class CheckEmailUnique(Resource):
|
|||||||
parser = reqparse.RequestParser()
|
parser = reqparse.RequestParser()
|
||||||
parser.add_argument("email", type=email, required=True, location="json")
|
parser.add_argument("email", type=email, required=True, location="json")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
if AccountService.is_account_in_freeze(args["email"]):
|
||||||
|
raise AccountInFreezeError()
|
||||||
if not AccountService.check_email_unique(args["email"]):
|
if not AccountService.check_email_unique(args["email"]):
|
||||||
raise EmailAlreadyInUseError()
|
raise EmailAlreadyInUseError()
|
||||||
return {"result": "success"}
|
return {"result": "success"}
|
||||||
|
|||||||
@ -15,6 +15,8 @@ import {
|
|||||||
verifyEmail,
|
verifyEmail,
|
||||||
} from '@/service/common'
|
} from '@/service/common'
|
||||||
import { noop } from 'lodash-es'
|
import { noop } from 'lodash-es'
|
||||||
|
import { asyncRunSafe } from '@/utils'
|
||||||
|
import type { ResponseError } from '@/service/fetch'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
show: boolean
|
show: boolean
|
||||||
@ -39,6 +41,7 @@ const EmailChangeModal = ({ onClose, email, show }: Props) => {
|
|||||||
const [time, setTime] = useState<number>(0)
|
const [time, setTime] = useState<number>(0)
|
||||||
const [stepToken, setStepToken] = useState<string>('')
|
const [stepToken, setStepToken] = useState<string>('')
|
||||||
const [newEmailExited, setNewEmailExited] = useState<boolean>(false)
|
const [newEmailExited, setNewEmailExited] = useState<boolean>(false)
|
||||||
|
const [unAvailableEmail, setUnAvailableEmail] = useState<boolean>(false)
|
||||||
const [isCheckingEmail, setIsCheckingEmail] = useState<boolean>(false)
|
const [isCheckingEmail, setIsCheckingEmail] = useState<boolean>(false)
|
||||||
|
|
||||||
const startCount = () => {
|
const startCount = () => {
|
||||||
@ -124,9 +127,17 @@ const EmailChangeModal = ({ onClose, email, show }: Props) => {
|
|||||||
email,
|
email,
|
||||||
})
|
})
|
||||||
setNewEmailExited(false)
|
setNewEmailExited(false)
|
||||||
|
setUnAvailableEmail(false)
|
||||||
}
|
}
|
||||||
catch {
|
catch (e: any) {
|
||||||
setNewEmailExited(true)
|
if (e.status === 400) {
|
||||||
|
const [, errRespData] = await asyncRunSafe<ResponseError>(e.json())
|
||||||
|
const { code } = errRespData || {}
|
||||||
|
if (code === 'email_already_in_use')
|
||||||
|
setNewEmailExited(true)
|
||||||
|
if (code === 'account_in_freeze')
|
||||||
|
setUnAvailableEmail(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
setIsCheckingEmail(false)
|
setIsCheckingEmail(false)
|
||||||
@ -291,15 +302,18 @@ const EmailChangeModal = ({ onClose, email, show }: Props) => {
|
|||||||
placeholder={t('common.account.changeEmail.emailPlaceholder')}
|
placeholder={t('common.account.changeEmail.emailPlaceholder')}
|
||||||
value={mail}
|
value={mail}
|
||||||
onChange={e => handleNewEmailValueChange(e.target.value)}
|
onChange={e => handleNewEmailValueChange(e.target.value)}
|
||||||
destructive={newEmailExited}
|
destructive={newEmailExited || unAvailableEmail}
|
||||||
/>
|
/>
|
||||||
{newEmailExited && (
|
{newEmailExited && (
|
||||||
<div className='body-xs-regular mt-1 py-0.5 text-text-destructive'>{t('common.account.changeEmail.existingEmail')}</div>
|
<div className='body-xs-regular mt-1 py-0.5 text-text-destructive'>{t('common.account.changeEmail.existingEmail')}</div>
|
||||||
)}
|
)}
|
||||||
|
{unAvailableEmail && (
|
||||||
|
<div className='body-xs-regular mt-1 py-0.5 text-text-destructive'>{t('common.account.changeEmail.unAvailableEmail')}</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className='mt-3 space-y-2'>
|
<div className='mt-3 space-y-2'>
|
||||||
<Button
|
<Button
|
||||||
disabled={!mail || newEmailExited || isCheckingEmail || !isValidEmail(mail)}
|
disabled={!mail || newEmailExited || unAvailableEmail || isCheckingEmail || !isValidEmail(mail)}
|
||||||
className='!w-full'
|
className='!w-full'
|
||||||
variant='primary'
|
variant='primary'
|
||||||
onClick={sendCodeToNewEmail}
|
onClick={sendCodeToNewEmail}
|
||||||
|
|||||||
@ -248,6 +248,7 @@ const translation = {
|
|||||||
emailLabel: 'New email',
|
emailLabel: 'New email',
|
||||||
emailPlaceholder: 'Enter a new email',
|
emailPlaceholder: 'Enter a new email',
|
||||||
existingEmail: 'A user with this email already exists.',
|
existingEmail: 'A user with this email already exists.',
|
||||||
|
unAvailableEmail: 'This email is temporarily unavailable.',
|
||||||
sendVerifyCode: 'Send verification code',
|
sendVerifyCode: 'Send verification code',
|
||||||
continue: 'Continue',
|
continue: 'Continue',
|
||||||
changeTo: 'Change to {{email}}',
|
changeTo: 'Change to {{email}}',
|
||||||
|
|||||||
@ -249,6 +249,7 @@ const translation = {
|
|||||||
emailLabel: '新しいメール',
|
emailLabel: '新しいメール',
|
||||||
emailPlaceholder: '新しいメールを入力してください',
|
emailPlaceholder: '新しいメールを入力してください',
|
||||||
existingEmail: 'このメールアドレスのユーザーは既に存在します',
|
existingEmail: 'このメールアドレスのユーザーは既に存在します',
|
||||||
|
unAvailableEmail: 'このメールアドレスは現在使用できません。',
|
||||||
sendVerifyCode: '確認コードを送信',
|
sendVerifyCode: '確認コードを送信',
|
||||||
continue: '続行',
|
continue: '続行',
|
||||||
changeTo: '{{email}} に変更',
|
changeTo: '{{email}} に変更',
|
||||||
|
|||||||
@ -248,6 +248,7 @@ const translation = {
|
|||||||
emailLabel: '新邮箱',
|
emailLabel: '新邮箱',
|
||||||
emailPlaceholder: '输入新邮箱',
|
emailPlaceholder: '输入新邮箱',
|
||||||
existingEmail: '该邮箱已存在',
|
existingEmail: '该邮箱已存在',
|
||||||
|
unAvailableEmail: '该邮箱暂时无法使用。',
|
||||||
sendVerifyCode: '发送验证码',
|
sendVerifyCode: '发送验证码',
|
||||||
continue: '继续',
|
continue: '继续',
|
||||||
changeTo: '更改为 {{email}}',
|
changeTo: '更改为 {{email}}',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user