add oidc login button
This commit is contained in:
@@ -1,26 +1,19 @@
|
||||
import oidcLogo from '@/assets/oidc-logo.svg';
|
||||
import { PageFooter } from '@/components';
|
||||
import { login } from '@/services/ant-design-pro/api';
|
||||
import { getFakeCaptcha } from '@/services/ant-design-pro/login';
|
||||
import {
|
||||
AlipayCircleOutlined,
|
||||
LockOutlined,
|
||||
MobileOutlined,
|
||||
TaobaoCircleOutlined,
|
||||
UserOutlined,
|
||||
WeiboCircleOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import {
|
||||
LoginForm,
|
||||
ProFormCaptcha,
|
||||
ProFormCheckbox,
|
||||
ProFormText,
|
||||
} from '@ant-design/pro-components';
|
||||
import { LockOutlined, UserOutlined } from '@ant-design/icons';
|
||||
import { LoginForm, ProFormCheckbox, ProFormText } from '@ant-design/pro-components';
|
||||
import { Helmet, history, useModel } from '@umijs/max';
|
||||
import { Alert, Tabs, message } from 'antd';
|
||||
import { Alert, Button, Tabs, message } from 'antd';
|
||||
import { createStyles } from 'antd-style';
|
||||
import React, { useState } from 'react';
|
||||
import React, { CSSProperties, useState } from 'react';
|
||||
import { flushSync } from 'react-dom';
|
||||
import Settings from '../../../../config/defaultSettings';
|
||||
|
||||
const iconStyles: CSSProperties = {
|
||||
transform: 'translateY(-12%)',
|
||||
};
|
||||
|
||||
const useStyles = createStyles(({ token }) => {
|
||||
return {
|
||||
action: {
|
||||
@@ -56,16 +49,6 @@ const useStyles = createStyles(({ token }) => {
|
||||
},
|
||||
};
|
||||
});
|
||||
const ActionIcons = () => {
|
||||
const { styles } = useStyles();
|
||||
return (
|
||||
<>
|
||||
<AlipayCircleOutlined key="AlipayCircleOutlined" className={styles.action} />
|
||||
<TaobaoCircleOutlined key="TaobaoCircleOutlined" className={styles.action} />
|
||||
<WeiboCircleOutlined key="WeiboCircleOutlined" className={styles.action} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
const LoginMessage: React.FC<{
|
||||
content: string;
|
||||
}> = ({ content }) => {
|
||||
@@ -80,6 +63,21 @@ const LoginMessage: React.FC<{
|
||||
/>
|
||||
);
|
||||
};
|
||||
const generateLink = () => {
|
||||
const preLink =
|
||||
'https://auth.zjueva.net/connect/authorize?response_type=code&client_id=tea&redirect_uri=https://xms.zjueva.net/api/external_sign&scope=openid&state=';
|
||||
return preLink + randomString(30);
|
||||
};
|
||||
|
||||
const randomString = (length: number) => {
|
||||
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
const maxPos = chars.length;
|
||||
let randomStr = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
randomStr += chars.charAt(Math.floor(Math.random() * maxPos));
|
||||
}
|
||||
return randomStr;
|
||||
};
|
||||
const Login: React.FC = () => {
|
||||
const [userLoginState, setUserLoginState] = useState<API.LoginResult>({});
|
||||
const [type, setType] = useState<string>('account');
|
||||
@@ -140,12 +138,11 @@ const Login: React.FC = () => {
|
||||
maxWidth: '75vw',
|
||||
}}
|
||||
logo={<img alt="logo" src="/logo.svg" />}
|
||||
title="Ant Design"
|
||||
subTitle={'Ant Design 是西湖区最具影响力的 Web 设计规范'}
|
||||
title="EVA Tea"
|
||||
subTitle={'E志者协会是东区教学楼最专业的志愿维修组织'}
|
||||
initialValues={{
|
||||
autoLogin: true,
|
||||
}}
|
||||
actions={['其他登录方式 :', <ActionIcons key="icons" />]}
|
||||
onFinish={async (values) => {
|
||||
await handleSubmit(values as API.LoginParams);
|
||||
}}
|
||||
@@ -159,10 +156,6 @@ const Login: React.FC = () => {
|
||||
key: 'account',
|
||||
label: '账户密码登录',
|
||||
},
|
||||
{
|
||||
key: 'mobile',
|
||||
label: '手机号登录',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
@@ -202,61 +195,6 @@ const Login: React.FC = () => {
|
||||
</>
|
||||
)}
|
||||
|
||||
{status === 'error' && loginType === 'mobile' && <LoginMessage content="验证码错误" />}
|
||||
{type === 'mobile' && (
|
||||
<>
|
||||
<ProFormText
|
||||
fieldProps={{
|
||||
size: 'large',
|
||||
prefix: <MobileOutlined />,
|
||||
}}
|
||||
name="mobile"
|
||||
placeholder={'请输入手机号!'}
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '手机号是必填项!',
|
||||
},
|
||||
{
|
||||
pattern: /^1\d{10}$/,
|
||||
message: '不合法的手机号!',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<ProFormCaptcha
|
||||
fieldProps={{
|
||||
size: 'large',
|
||||
prefix: <LockOutlined />,
|
||||
}}
|
||||
captchaProps={{
|
||||
size: 'large',
|
||||
}}
|
||||
placeholder={'请输入验证码!'}
|
||||
captchaTextRender={(timing, count) => {
|
||||
if (timing) {
|
||||
return `${count} ${'秒后重新获取'}`;
|
||||
}
|
||||
return '获取验证码';
|
||||
}}
|
||||
name="captcha"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: '验证码是必填项!',
|
||||
},
|
||||
]}
|
||||
onGetCaptcha={async (phone) => {
|
||||
const result = await getFakeCaptcha({
|
||||
phone,
|
||||
});
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
message.success('获取验证码成功!验证码为:1234');
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<div
|
||||
style={{
|
||||
marginBottom: 24,
|
||||
@@ -265,13 +203,21 @@ const Login: React.FC = () => {
|
||||
<ProFormCheckbox noStyle name="autoLogin">
|
||||
自动登录
|
||||
</ProFormCheckbox>
|
||||
<a
|
||||
style={{
|
||||
float: 'right',
|
||||
}}
|
||||
</div>
|
||||
<div style={{ marginBottom: '2vh' }}>
|
||||
{' '}
|
||||
<Button
|
||||
type="default"
|
||||
block
|
||||
size="large"
|
||||
href={generateLink()}
|
||||
style={{ backgroundColor: '#e0af68', color: '#ffffff' }}
|
||||
>
|
||||
忘记密码 ?
|
||||
</a>
|
||||
<div>
|
||||
<img src={oidcLogo} width="23px" style={iconStyles} />
|
||||
使用 EVA 统一身份认证
|
||||
</div>
|
||||
</Button>
|
||||
</div>
|
||||
</LoginForm>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user