登录增加错误延迟提醒

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 } };
} 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(
config.authConfigFile,
JSON.stringify({
@ -76,9 +65,23 @@ export default class AuthService {
retries: retries + 1,
lastlogon: timestamp,
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 };
}
} else {

View File

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

View File

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

View File

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