diff --git a/public/react/src/modules/user/account/AccountSecure.js b/public/react/src/modules/user/account/AccountSecure.js index 9692e1dfc..f28b651f6 100644 --- a/public/react/src/modules/user/account/AccountSecure.js +++ b/public/react/src/modules/user/account/AccountSecure.js @@ -27,20 +27,72 @@ class AccountSecure extends Component { constructor (props) { super(props) this.state = { - updating: '' + updating: '', + secondsFlag:false, + seconds:60 } } + // 获取验证码倒计时 + remainTime=()=>{ + this.timer = setInterval(() => { + let { seconds } =this.state; + let s = parseInt(seconds)-1; + if(s > -1){ + this.setState({ + seconds:s + }) + }else{ + this.setState({ + secondsFlag:false + }) + clearInterval(this.timer); + } + },1000) + } + // 获取验证码 getCode=(index)=>{ let url=`/account/get_verification_code.json` + let login = ''; + let values=this.props.form.getFieldsValue(); if(index == 3){ //绑定手机号码 - let values=this.props.form.getFieldsValue(); - console.log(values); + login=values.phone; + let reg=/^1\d{10}$/; + if(reg.test(login)==false){ + this.props.showNotification(`请先输入正确的手机号码`); + return; + } + }else if(index == 4){ + // 绑定邮箱 + login=values.email; + 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(login)==false){ + this.props.showNotification(`请先输入正确的邮箱地址`); + return; + } + } + let type = index; + if(!login){ + this.props.showNotification(`请先输入${index==3?"手机号码":"邮箱地址"}`); + return; } + axios.get((url),{params:{ + login,type + }}).then((result)=>{ + if(result){ + // 倒计时 + this.setState({ + secondsFlag:true + }) + this.remainTime(); + } + }).catch((error)=>{ + console.log(error); + }) } - +// 绑定手机 onPhoneSubmit = () => { this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { @@ -68,10 +120,32 @@ class AccountSecure extends Component { } }) } + + // 绑定邮箱 onEmailSubmit = () => { this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { - + let {login}=this.props.current_user; + 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)){ + let url=`/users/accounts/${login}/email_bind.json` + axios.post((url),{ + email:values.email, + code:values.emailValidateCode + }).then((result)=>{ + if(result){ + this.props.showNotification("邮箱地址绑定成功!"); + this.setState({ + updating:'' + }) + this.props.getBasicInfo(); + } + }).catch((error)=>{ + console.log(error); + }) + }else{ + this.props.showNotification("请输入正确的邮箱地址"); + } } }) } @@ -93,10 +167,9 @@ class AccountSecure extends Component { render() { let {basicInfo}=this.props; const { getFieldDecorator } = this.props.form; - const { updating } = this.state + const { updating,seconds,secondsFlag } = this.state return (
-