/** * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug * Copyright (c) * Released under the AGPL-3.0 License. */ import React, { useState, useEffect } from 'react'; import { Form, Input, Button, Tabs, Modal, message } from 'antd'; import { UserOutlined, LockOutlined, CopyrightOutlined, GithubOutlined, MailOutlined } from '@ant-design/icons'; import styles from './login.module.css'; import history from 'libs/history'; import { http, updatePermissions } from 'libs'; import logo from 'layout/logo-spug-txt.png'; import envStore from 'pages/config/environment/store'; import appStore from 'pages/config/app/store'; import requestStore from 'pages/deploy/request/store'; import execStore from 'pages/exec/task/store'; import hostStore from 'pages/host/store'; export default function () { const [form] = Form.useForm(); const [counter, setCounter] = useState(0); const [loading, setLoading] = useState(false); const [loginType, setLoginType] = useState('default'); const [codeVisible, setCodeVisible] = useState(false); const [codeLoading, setCodeLoading] = useState(false); useEffect(() => { envStore.records = []; appStore.records = []; requestStore.records = []; requestStore.deploys = []; hostStore.records = []; execStore.hosts = []; }, []) useEffect(() => { setTimeout(() => { if (counter > 0) { setCounter(counter - 1) } }, 1000) }, [counter]) function handleSubmit() { const formData = form.getFieldsValue(); if (codeVisible && !formData.captcha) return message.error('请输入验证码'); setLoading(true); formData['type'] = loginType; http.post('/api/account/login/', formData) .then(data => { if (data['required_mfa']) { setCodeVisible(true); setCounter(30); setLoading(false) } else if (!data['has_real_ip']) { Modal.warning({ title: '安全警告', className: styles.tips, content:
未能获取到访问者的真实IP,无法提供基于请求来源IP的合法性验证,详细信息请参考 官方文档
, onOk: () => doLogin(data) }) } else { doLogin(data) } }, () => setLoading(false)) } function doLogin(data) { localStorage.setItem('id', data['id']); localStorage.setItem('token', data['access_token']); localStorage.setItem('nickname', data['nickname']); localStorage.setItem('is_supper', data['is_supper']); localStorage.setItem('permissions', JSON.stringify(data['permissions'])); updatePermissions(); if (history.location.state && history.location.state['from']) { history.push(history.location.state['from']) } else { history.push('/home') } } function handleCaptcha() { setCodeLoading(true); const formData = form.getFieldsValue(['username', 'password']); formData['type'] = loginType; http.post('/api/account/login/', formData) .then(() => setCounter(30)) .finally(() => setCodeLoading(false)) } return (
logo
灵活、强大、易用的开源运维平台
setLoginType(v)}>
}/> }/>
官网 文档
Copyright 2021 By OpenSpug
) }