diff --git a/src/forge/users/Material/Password.jsx b/src/forge/users/Material/Password.jsx index aae00b3fb..9aaeb2027 100644 --- a/src/forge/users/Material/Password.jsx +++ b/src/forge/users/Material/Password.jsx @@ -1,6 +1,7 @@ -import React , { forwardRef, useState } from 'react'; +import React , { forwardRef, Fragment, useState } from 'react'; import { Form , Input , Button, message } from 'antd'; import { AlignCenter } from '../../Component/layout'; +import Modals from '../../Component/PublicModal/Index'; import Axios from 'axios'; import img1 from '../../Images/personalInfo3.png'; import { setmiyah } from '../../../common/Component'; @@ -8,7 +9,7 @@ import { useEffect } from 'react'; export default Form.create()( forwardRef((props)=>{ - const { getFieldDecorator, validateFields, resetFields } = props && props.form; + const { getFieldDecorator, validateFields, resetFields, getFieldsValue } = props && props.form; const { current_user, type, resetUserInfo} = props; const [ NewPass , setNewPass ] = useState(undefined); @@ -16,7 +17,8 @@ export default Form.create()( const [ countDown, setCountDown] = useState(undefined); const [ emailValue, setEmailValue] = useState(undefined); const [ passMap, setPassMap] = useState({password: undefined, email: undefined, code: undefined}); - const [ updatePsdMap, setUpdatePsdMap] = useState({oldPassword: undefined, password: undefined, password1: undefined}) + const [ updatePsdMap, setUpdatePsdMap] = useState({oldPassword: undefined, password: undefined, password1: undefined}); + const [ visible, setVisible] = useState(false); useEffect(()=>{ setPassMap({password: undefined, email: undefined, code: undefined}); @@ -26,25 +28,11 @@ export default Form.create()( function submit() { validateFields((error,values)=>{ if(!error){ - submitFunc(values); + setVisible(true); } }) } - function submitFunc(values) { - const url = `/accounts/change_password.json`; - Axios.post(url,{ - login:current_user && current_user.login, - ...values - }).then(result=>{ - if(result && result.data){ - resetFields(); - setUpdatePsdMap({oldPassword: undefined, password: undefined, password1: undefined}); - message.success('密码重置成功!'); - } - }).catch(error=>{}) - } - // 判断两次输入的密码是否一致 var reg = /(?!.*\s)(?!^[\u4e00-\u9fa5]+$)^.{8,16}$/; function checkIdentifier(rule, value, callback , inputValue){ @@ -89,7 +77,9 @@ export default Form.create()( email: emailValue, smscode: setmiyah(emailValue) }}).then(res=>{ - console.log('res', res); + if(res && !res.data.status){ + message.success('发送成功') + } }) // 获取验证码 startCountDown(); @@ -110,196 +100,260 @@ export default Form.create()( // 校验用户密码是否正确 function checkPsd(rule, value, callback){ - current_user && Axios.post(`/v1/${current_user.login}/check_password.json`,{ - password: value - }).then(res=>{ - const map = type === '0' ? passMap : updatePsdMap; - if(res && !res.data.status){ - if(type === '0'){ - map.password = value; - setPassMap(map); + const map = type === '0' ? passMap : updatePsdMap; + if(value){ + current_user && Axios.post(`/v1/${current_user.login}/check_password.json`,{ + password: value + }).then(res=>{ + if(res && !res.data.status){ + if(type === '0'){ + map.password = value; + setPassMap(map); + }else{ + map.oldPassword = value; + setUpdatePsdMap(map); + } + callback(); }else{ - map.oldPassword = value; - setUpdatePsdMap(map); + if(type === '0'){ + map.password = undefined; + setPassMap(map); + }else{ + map.oldPassword = undefined; + setUpdatePsdMap(map); + } + callback(res.data.message); } - callback(); + }) + }else{ + if(type === '0'){ + map.password = undefined; + setPassMap(map); }else{ - if(type === '0'){ - map.password = undefined; - setPassMap(map); - }else{ - map.oldPassword = undefined; - setUpdatePsdMap(map); - } - callback(res.data.message); + map.oldPassword = undefined; + setUpdatePsdMap(map); } - }) + callback(); + } } // 校验用户邮箱是否正确 function checkEmail(rule, value, callback){ - current_user && Axios.post(`/v1/${current_user.login}/check_email.json`,{ - email: value - }).then(res=>{ - const map = passMap; - if(res && !res.data.status){ - map.email = value; - setPassMap(map); - setEmailValue(value); - callback(); - }else{ - map.email = undefined; - setPassMap(map); - callback(res.data.message); - } - }) + const map = passMap; + if(value){ + current_user && Axios.post(`/v1/${current_user.login}/check_email.json`,{ + email: value + }).then(res=>{ + if(res && !res.data.status){ + map.email = value; + setPassMap(map); + setEmailValue(value); + callback(); + }else{ + setEmailValue(undefined); + map.email = undefined; + setPassMap(map); + callback(res.data.message); + } + }) + }else{ + setEmailValue(undefined); + map.email = undefined; + setPassMap(map); + callback(); + } } // 校验用户填写验证码是否正确 function checkCode(rule, value, callback){ - current_user && value && value.length > 4 && Axios.post(`/v1/${current_user.login}/check_email_verify_code.json`,{ - code_type: 10, - email: emailValue, - code: value - }).then(res=>{ - const map = passMap; - if(res && !res.data.status){ - map.code = value; - setPassMap(map); - callback(); - }else{ - map.code = undefined; - setPassMap(map); - callback(res.data.message); + const map = passMap; + if(value){ + current_user && value && value.length > 4 && Axios.post(`/v1/${current_user.login}/check_email_verify_code.json`,{ + code_type: 10, + email: emailValue, + code: value + }).then(res=>{ + if(res && !res.data.status){ + map.code = value; + setPassMap(map); + callback(); + }else{ + map.code = undefined; + setPassMap(map); + callback(res.data.message); + } + }) + }else{ + map.code = undefined; + setPassMap(map); + callback(); + } + } + + // 提交更改邮箱表单 + function confirmUpdateEmail(e){ + validateFields((error,values)=>{ + if(!error){ + setVisible(true); } }) } - // 提交更改邮箱表单 - function updateEmail(e){ - console.log('提交更改邮箱表单', e); - validateFields((error,values)=>{ - if(!error){ - const {code, email, password1} = values; - if(code && email && password1){ - current_user && Axios.patch(`/v1/${current_user.login}/update_email.json`,{ - code, email, password: password1 - }).then(res=>{ - if(res && !res.data.status){ - setPassMap({password: undefined, email: undefined, code: undefined}); - resetFields(); - resetUserInfo(); - message.success('更新成功'); - }else{ - message.error(res.data.message || '更新失败'); - } - }) - } + function updateEmailOrPsd(){ + if(type === '0'){ + const {code, email, password1} = getFieldsValue(); + if(code && email && password1){ + current_user && Axios.patch(`/v1/${current_user.login}/update_email.json`,{ + code, email, password: password1 + }).then(res=>{ + if(res && !res.data.status){ + setPassMap({password: undefined, email: undefined, code: undefined}); + resetFields(); + resetUserInfo(); + setVisible(false); + message.success('更新成功'); + }else{ + setVisible(false); + message.error(res.data.message || '更新失败'); + } + }) + } + }else{ + const values = getFieldsValue(); + const url = `/accounts/change_password.json`; + Axios.post(url,{ + login:current_user && current_user.login, + ...values + }).then(result=>{ + if(result && result.data){ + resetFields(); + setUpdatePsdMap({oldPassword: undefined, password: undefined, password1: undefined}); + setVisible(false); + setNewPass(undefined); + setNewPassRepeat(undefined); + message.success('密码重置成功!'); + } + }).catch(error=>{}) } - }) } -console.log('1111', updatePsdMap.password1); // type: 0邮箱管理 1密码管理 2账号注销 return( - type === '0' ?
{type === '0' ? '更改邮箱后,您在GitLink的登录账号、接收通知的邮件地址、git config 邮件地址将同步变更。请再次确认。' : '更改密码后,您在GitLink的登录密码将同步变更。请再次确认。'}
+