同步账号密码

This commit is contained in:
caishi 2021-09-08 16:50:16 +08:00
parent 146e51c182
commit 5eb542cfbf
4 changed files with 53 additions and 67 deletions

View File

@ -1,15 +1,32 @@
import React , {forwardRef, useEffect} from 'react';
import { Modal , Form , Input , Button } from 'antd';
import './EAccount.scss';
import axios from 'axios';
function EducoderAccount({form , visible , onOk , email}){
function EducoderAccount({form , visible , current_user}){
const { getFieldDecorator, validateFields , setFieldsValue } = form;
useEffect(()=>{
if(email){
setFieldsValue({email})
if(current_user && current_user.email){
setFieldsValue({email:current_user.email})
}
},[email])
},[current_user])
function onOk(values){
let url = `/accounts/gitea_register.json`;
const { email , is_sync_pwd} = current_user;
if(email && !is_sync_pwd){
url = `/users/change_password.json`;
}
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=>{})
}
function onSure(){
validateFields((error,values)=>{
@ -27,7 +44,6 @@ function EducoderAccount({form , visible , onOk , email}){
visible={visible}
title="提示"
width="500px"
closable={false}
footer={
<Button type="primary" onClick={onSure}>确定</Button>
}
@ -36,8 +52,8 @@ function EducoderAccount({form , visible , onOk , email}){
<div>
<p className="mb15 edu-txt-center" style={{maxWidth:"350px",margin:"0px auto"}}>
{
email ?
`平台已检测到您已绑定邮箱${email},请您确认如下操作`
current_user && current_user.email ?
`平台已检测到您已绑定邮箱${current_user.email},请您确认如下操作`
:
"平台已检测到您未绑定邮箱,为不影响使用协同开发功能,请先绑定邮箱"
}
@ -47,7 +63,7 @@ function EducoderAccount({form , visible , onOk , email}){
{getFieldDecorator("email",{
rules:[{required:true,message:"请输入邮箱账号"}]
})(
<Input placeholder="请输入您的邮箱账号" width="220px" disabled={email}/>
<Input placeholder="请输入您的邮箱账号" width="220px" disabled={current_user && current_user.email}/>
)}
</Form.Item>
<Form.Item label="密码">

View File

@ -1,17 +1,36 @@
import React from 'react';
import { useState } from 'react';
import EducoderAccount from '../EducoderAccount';
function Profile({children,sureFunc,showCompeleteDialog , completeProfile, className}) {
function Profile({
children,
sureFunc,
showCompeleteDialog ,
completeProfile,
className ,
current_user
}) {
const [ giteaVisible , setGiteaVisible ] = useState(false);
function checkProfile() {
if(!completeProfile){
showCompeleteDialog && showCompeleteDialog();
}else{
sureFunc();
if(current_user && current_user.login){
if(!current_user.has_gitea_user || (current_user.has_gitea_user && !current_user.is_sync_pwd)){
setGiteaVisible(true);
}else{
if(!completeProfile){
showCompeleteDialog && showCompeleteDialog();
}else{
sureFunc();
}
}
}
}
return(
<a className={className} onClick={checkProfile}>{children}</a>
<React.Fragment>
<EducoderAccount visible={giteaVisible} onCancel={()=>setGiteaVisible(false)} current_user={current_user}/>
<a className={className} onClick={checkProfile}>{children}</a>
</React.Fragment>
)
}
export default Profile;

View File

@ -6,7 +6,7 @@ import CheckProfile from '../../Component/ProfileModal/Profile';
const { Search } = Input;
const limit = 20;
function ConcentrateBox({ visible , onCancel , onSure , username , choosed , history , showCompeleteDialog , completeProfile }) {
function ConcentrateBox({ visible , onCancel , onSure , username , choosed , history , showCompeleteDialog , completeProfile , current_user }) {
const [ page , setPage ]= useState(1);
const [ total , setTotal ]= useState(0);
const [ pageSize , setPageSize ] = useState(false);
@ -171,6 +171,7 @@ function ConcentrateBox({ visible , onCancel , onSure , username , choosed , his
(list && list.length === 0) && (copyList && copyList.length === 0) &&
<div style={{textAlign:"center"}}>您还没有公开的{search && `${search}`}项目先去
<CheckProfile
current_user={current_user}
showCompeleteDialog={showCompeleteDialog}
completeProfile={completeProfile}
sureFunc={()=>{history.push(`/projects/deposit/new`)}}

View File

@ -5,7 +5,6 @@ import axios from 'axios';
import { Spin } from 'antd';
import './TPMIndex.css';
import LoginDialog from '../login/LoginDialog';
import EducoderAccount from '../../forge/Component/EducoderAccount';
import ProfileModal from '../../forge/Component/ProfileModal/Index';
// import AccountProfile from '../user/AccountProfile';
// import AccountPhoneemail from '../user/AccountPhoneemail';
@ -26,11 +25,9 @@ export function TPMIndexHOC(WrappedComponent) {
dataquerys: {},
isloginCancel: undefined,
mygetHelmetapi: null,
giteaVisible:false,
email:undefined,
completeProfile:false,
showCP:false,
is_sync_pwd:undefined
}
}
@ -163,32 +160,6 @@ export function TPMIndexHOC(WrappedComponent) {
if (this.props.match.path === "/" && response.data.login) {
this.props.history.push(`/${response.data.login}`);
}
if(response.data && response.data.login){
if(response.data.need_edit_info){
this.setState({
giteaVisible:true,
email:response.data.email
})
}
}
if(response.data && response.data.login){
if(!response.data.has_gitea_user || (response.data.has_gitea_user && !response.data.is_sync_pwd)){
this.setState({
giteaVisible:true,
email:response.data.email,
is_sync_pwd:response.data.is_sync_pwd
})
}
}
if(response.data && response.data.login){
if(!response.data.has_gitea_user || (response.data.has_gitea_user && !response.data.is_sync_pwd)){
this.setState({
giteaVisible:true,
email:response.data.email,
is_sync_pwd:response.data.is_sync_pwd
})
}
}
}
}).catch((error) => {
console.log(error)
@ -212,26 +183,6 @@ export function TPMIndexHOC(WrappedComponent) {
return this.state.current_user && this.state.current_user.login != ''
}
onOk =(values)=>{
let url = `/accounts/gitea_register.json`;
const { email , current_user , is_sync_pwd } = this.state;
if(email && !is_sync_pwd){
url = `/users/change_password.json`;
}
axios.post(url,{
login:current_user && current_user.login,
...values
}).then(result=>{
if(result && result.data && result.data.status === 0){
this.setState({
giteaVisible:false,
email:undefined
})
window.location.reload();
}
}).catch(error=>{})
}
showCompeleteDialog=()=>{
this.setState({
showCP:true
@ -239,7 +190,7 @@ export function TPMIndexHOC(WrappedComponent) {
}
render() {
let { isRender , current_user , giteaVisible , email , completeProfile , showCP } = this.state;
let { isRender , current_user , completeProfile , showCP } = this.state;
const common = {
showLoginDialog: this.showLoginDialog,
checkIfLogin: this.checkIfLogin,
@ -248,7 +199,6 @@ export function TPMIndexHOC(WrappedComponent) {
};
return (
<div className="indexHOC">
<EducoderAccount visible={giteaVisible} email={email} onOk={this.onOk}/>
<ProfileModal
visible={!completeProfile && showCP}
onCancel={()=>{this.setState({showCP:false})}}