forgeplus-react/src/forge/Component/EducoderAccount.jsx

90 lines
2.8 KiB
React
Raw Normal View History

2021-04-02 17:39:13 +08:00
import React , {forwardRef, useEffect} from 'react';
2023-03-14 11:39:02 +08:00
import { Modal , Form , Input , Button , message} from 'antd';
2021-04-02 17:39:13 +08:00
import './EAccount.scss';
2021-09-08 16:50:16 +08:00
import axios from 'axios';
2021-04-02 17:39:13 +08:00
2023-04-18 16:58:23 +08:00
function EducoderAccount({form , visible , current_user , onCancel,isCancel,showNotification}){
2021-04-02 17:39:13 +08:00
const { getFieldDecorator, validateFields , setFieldsValue } = form;
useEffect(()=>{
2021-09-08 16:50:16 +08:00
if(current_user && current_user.email){
setFieldsValue({email:current_user.email})
2021-04-02 17:39:13 +08:00
}
2021-09-08 16:50:16 +08:00
},[current_user])
function onOk(values){
let url = `/accounts/gitea_register.json`;
2023-08-07 14:12:32 +08:00
// const { email , is_sync_pwd} = current_user;
// if(email && !is_sync_pwd){
// url = `/users/change_password.json`;
// }
2021-09-08 16:50:16 +08:00
axios.post(url,{
login:current_user && current_user.login,
...values
}).then(result=>{
if(result && result.data && result.data.status === 0){
window.location.reload();
}
}).catch(error=>{})
}
2021-04-02 17:39:13 +08:00
function onSure(){
validateFields((error,values)=>{
if(!error){
2023-04-18 16:58:23 +08:00
let reg = /^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
if (reg.test(values.email)) {
onOk(values);
}else{
showNotification && showNotification("请输入正确的邮箱账号!");
}
2021-04-02 17:39:13 +08:00
}
})
}
const layout = {
labelCol: { span: 5 },
wrapperCol: { span: 18 },
};
return(
<Modal
visible={visible}
title="提示"
width="500px"
2022-08-31 10:02:23 +08:00
maskClosable={isCancel}
2021-09-08 17:47:40 +08:00
onCancel={onCancel}
2021-04-02 17:39:13 +08:00
footer={
<Button type="primary" onClick={onSure}>确定</Button>
}
centered
>
<div>
<p className="mb15 edu-txt-center" style={{maxWidth:"350px",margin:"0px auto"}}>
2021-03-19 09:33:22 +08:00
{
2021-09-08 16:50:16 +08:00
current_user && current_user.email ?
`平台已检测到您已绑定邮箱${current_user.email},请您确认如下操作`
2021-03-19 09:33:22 +08:00
:
2023-04-18 15:56:53 +08:00
"平台已检测到您未绑定邮箱,为了不影响协同开发部分功能的使用,建议先绑定邮箱"
2021-03-19 09:33:22 +08:00
}
2021-04-02 17:39:13 +08:00
</p>
<Form {...layout}>
<Form.Item label="邮箱">
{getFieldDecorator("email",{
2023-04-18 16:58:23 +08:00
rules:[
{required:true,message:"请输入邮箱账号"}
]
2021-04-02 17:39:13 +08:00
})(
2021-09-08 16:50:16 +08:00
<Input placeholder="请输入您的邮箱账号" width="220px" disabled={current_user && current_user.email}/>
2021-04-02 17:39:13 +08:00
)}
</Form.Item>
<Form.Item label="密码">
{getFieldDecorator("password",{
2021-04-07 15:00:09 +08:00
rules:[{required:true,message:"请输入您的平台密码"}]
2021-04-02 17:39:13 +08:00
})(
2021-04-07 15:00:09 +08:00
<Input.Password placeholder="请输入您的平台密码" width="220px"/>
2021-04-02 17:39:13 +08:00
)}
</Form.Item>
</Form>
</div>
</Modal>
)
}
export default Form.create()(forwardRef(EducoderAccount));