登录增加错误延迟提醒

This commit is contained in:
hanhh 2021-08-22 12:28:45 +08:00
parent 54bb13aad0
commit 622037ee98
4 changed files with 63 additions and 23 deletions

View File

@ -58,17 +58,6 @@ export default class AuthService {
); );
return { code: 200, data: { token, lastip, lastaddr, lastlogon } }; return { code: 200, data: { token, lastip, lastaddr, lastlogon } };
} else { } else {
if (
retries > 2 &&
Date.now() - lastlogon < Math.pow(3, retries) * 1000
) {
return {
code: 400,
message: `失败次数过多,请${Math.round(
(Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000,
)}`,
};
}
fs.writeFileSync( fs.writeFileSync(
config.authConfigFile, config.authConfigFile,
JSON.stringify({ JSON.stringify({
@ -76,9 +65,23 @@ export default class AuthService {
retries: retries + 1, retries: retries + 1,
lastlogon: timestamp, lastlogon: timestamp,
ip, ip,
address, lastaddr: address,
}), }),
); );
if (
retries > 2 &&
Date.now() - lastlogon < Math.pow(3, retries) * 1000
) {
return {
code: 410,
message: `失败次数过多,请${Math.round(
(Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000,
)}`,
data: Math.round(
(Math.pow(3, retries) * 1000 - Date.now() + lastlogon) / 1000,
),
};
}
return { code: 400, message: config.authError }; return { code: 400, message: config.authError };
} }
} else { } else {

View File

@ -241,7 +241,7 @@ input:-webkit-autofill:active {
} }
} }
.ant-message .ant-statistic { .inline-countdown.ant-statistic {
display: inline-block; display: inline-block;
.ant-statistic-content { .ant-statistic-content {
font-size: 14px; font-size: 14px;

View File

@ -57,7 +57,11 @@ const CronLogModal = ({
content: ( content: (
<span> <span>
<Countdown format="ss" value={Date.now() + 1000 * 10} /> <Countdown
className="inline-countdown"
format="ss"
value={Date.now() + 1000 * 10}
/>
</span> </span>
), ),

View File

@ -1,14 +1,28 @@
import React, { Fragment, useEffect } from 'react'; import React, { Fragment, useEffect, useState } from 'react';
import { Button, Row, Input, Form, message, notification } from 'antd'; import {
Button,
Row,
Input,
Form,
message,
notification,
Statistic,
} from 'antd';
import config from '@/utils/config'; import config from '@/utils/config';
import { history, Link } from 'umi'; import { history, Link } from 'umi';
import styles from './index.less'; import styles from './index.less';
import { request } from '@/utils/http'; import { request } from '@/utils/http';
const FormItem = Form.Item; const FormItem = Form.Item;
const { Countdown } = Statistic;
const Login = () => { const Login = () => {
const [loading, setLoading] = useState(false);
const [waitTime, setWaitTime] = useState<any>();
const handleOk = (values: any) => { const handleOk = (values: any) => {
setLoading(true);
setWaitTime(null);
request request
.post(`${config.apiPrefix}login`, { .post(`${config.apiPrefix}login`, {
data: { data: {
@ -36,12 +50,17 @@ const Login = () => {
history.push('/crontab'); history.push('/crontab');
} else if (data.code === 100) { } else if (data.code === 100) {
message.warn(data.message); message.warn(data.message);
} else if (data.code === 410) {
message.error(data.message);
setWaitTime(data.data);
} else { } else {
message.error(data.message); message.error(data.message);
} }
setLoading(false);
}) })
.catch(function (error) { .catch(function (error) {
console.log(error); console.log(error);
setLoading(false);
}); });
}; };
@ -82,13 +101,27 @@ const Login = () => {
<Input type="password" placeholder="密码" /> <Input type="password" placeholder="密码" />
</FormItem> </FormItem>
<Row> <Row>
{waitTime ? (
<Button type="primary" style={{ width: '100%' }} disabled>
<Countdown
valueStyle={{ color: 'rgba(232, 230, 227, 0.25)' }}
className="inline-countdown"
format="ss"
value={Date.now() + 1000 * waitTime}
/>
</Button>
) : (
<Button <Button
type="primary" type="primary"
htmlType="submit" htmlType="submit"
style={{ width: '100%' }} style={{ width: '100%' }}
loading={loading}
> >
</Button> </Button>
)}
</Row> </Row>
</Form> </Form>
</div> </div>