Skip to content

Commit

Permalink
Merge pull request #208 from dengyi9/master
Browse files Browse the repository at this point in the history
初步实现register,  #202
  • Loading branch information
dengyi9 authored Mar 26, 2019
2 parents 0628230 + e314017 commit e079428
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 57 deletions.
2 changes: 2 additions & 0 deletions src/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Common.LOGIN_PEER_SSL_TARGET = 'Peer SSL Target';
Common.LOGIN_ORDERER_SSL_TARGET = 'Orderer SSL Target';
Common.LOGIN_CA_SERVER_URL = 'CA Server Url';

// user register page
Common.REGISTER_USERNAME = 'User Name';

Common.WARN = {
chaincodeName: 'chaincode name can not be null!',
Expand Down
2 changes: 2 additions & 0 deletions src/common/common_cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Common.LOGIN_PEER_SSL_TARGET = '组织节点SSL域名';
Common.LOGIN_ORDERER_SSL_TARGET = '排序节点SSL域名';
Common.LOGIN_CA_SERVER_URL = 'CA节点地址';

// user register page
Common.REGISTER_USERNAME = '用户名';

Common.WARN = {
chaincodeName: '链码名称不能为空!',
Expand Down
7 changes: 7 additions & 0 deletions src/components/BasicLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Layout, Menu, Icon } from 'antd';
import DataContent from './content/DataContent';
import ChaincodeInvokeContent from './content/ChaincodeInvokeContent';
import ChaincodeInstallContent from './content/ChaincodeInstallContent';
import CARegisterContent from './content/CARegisterContent';
import { deleteFabricClientSingleton } from '../util/fabric';

import { getConfigDBSingleton, getInvokeDBSingleton, getChaincodeDBSingleton } from '../util/createDB';
Expand Down Expand Up @@ -35,6 +36,8 @@ function ContentRoute(props) {
return <ChaincodeInstallContent />;
} else if (props.contentKey === 4) {
return <ChannelManangeContent />;
} else if (props.contentKey === 5) {
return <CARegisterContent />;
}
return <h1>The sidebar button is not bound to corresponding content</h1>;
}
Expand Down Expand Up @@ -123,6 +126,10 @@ export default class BasicLayout extends React.Component {
<Icon type="block" />
<span>{this.state.language === 'cn' ? '通道管理' : 'Channel Management' }</span>
</Menu.Item>
<Menu.Item key="5" onClick={() => this.switchContent(5)}>
<Icon type="user-add" />
<span>{this.state.language === 'cn' ? 'CA注册' : 'CA Register' }</span>
</Menu.Item>
</Menu>
</Sider>
<Layout>
Expand Down
24 changes: 11 additions & 13 deletions src/components/UserLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,22 @@ export default class UserLayout extends React.Component {
tlsOrdererPath: this.state.tlsOrdererPath,
peerSSLTarget: this.state.peerSSLTarget,
ordererSSLTarget: this.state.ordererSSLTarget,
caServerUrl: this.state.caServerUrl,
keyPath: this.state.keyPath,
certPath: this.state.certPath,
path: 'resources/key/users/' } },
{},
() => {
getFabricClientSingleton().then((fabricClient) => {
fabricClient.importCer(this.state.keyPath, this.state.certPath).then((result) => {
db.update({ id: 0 },
{ $set: { isSign: 2 } },
{}, () => {
});
this.props.onGetChildMessage(2);
logger.info('result', result);
}, () => {
message.error(this.state.Common.ERROR.certificateFailed);
});
getFabricClientSingleton().then(() => {
db.update({ id: 0 },
{ $set: { isSign: 2 } },
{}, () => {
});
this.props.onGetChildMessage(2);
}, () => {
message.error(this.state.Common.ERROR.certificateFailed);
});
});

logger.info(this.state.certPath);
}
peerGrpcUrlChange(event) {
this.setState({ peerGrpcUrl: event.target.value });
Expand Down
212 changes: 212 additions & 0 deletions src/components/content/CARegisterContent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
// Copyright 2018 The hyperledger-fabric-desktop Authors. All rights reserved.

// main feature: CA register and enroll
import React from 'react';
import { Button, Input } from 'antd';
import { getFabricClientSingleton } from '../../util/fabric';

const logger = require('electron-log');

/**
* register参数:用户名、affiliation, role等等
* enroll参数:用户名、密码
*/

export default class CARegisterContent extends React.Component {
constructor(props) {
super(props);
this.state = {
Common: localStorage.getItem('language') === 'cn' ? require('../../common/common_cn') : require('../../common/common'),

registerUserName: '',
registerAffiliation: '',
registerRole: '',
registerOptional: '',

enrollUserName: '',
enrollUserPassword: '',
enrollOptional: '',
};

this.onChangeRegisterUserName = this.onChangeRegisterUserName.bind(this);
this.onChangeRegisterAffiliation = this.onChangeRegisterAffiliation.bind(this);
this.onChangeRegisterRole = this.onChangeRegisterRole.bind(this);
this.onChangeRegisterOptional = this.onChangeRegisterOptional.bind(this);
this.onChangeEnrollUserName = this.onChangeEnrollUserName.bind(this);
this.onChangeEnrollUserPassword = this.onChangeEnrollUserPassword.bind(this);
this.onChangeEnrollOptional = this.onChangeEnrollOptional.bind(this);

this.handleRegister = this.handleRegister.bind(this);
this.handleEnroll = this.handleEnroll.bind(this);
}

onChangeRegisterUserName(event) {
this.setState({ registerUserName: event.target.value });
}
onChangeRegisterAffiliation(event) {
this.setState({ registerAffiliation: event.target.value });
}
onChangeRegisterRole(event) {
this.setState({ registerRole: event.target.value });
}
onChangeRegisterOptional(event) {
this.setState({ registerOptional: event.target.value });
}
onChangeEnrollUserName(event) {
this.setState({ enrollUserName: event.target.value });
}
onChangeEnrollUserPassword(event) {
this.setState({ enrollUserPassword: event.target.value });
}
onChangeEnrollOptional(event) {
this.setState({ enrollOptional: event.target.value });
}

handleRegister() {
// FIXME: Object.assign is shallow copy. Be careful.
const tmpReq = {
enrollmentID: this.state.registerUserName,
affiliation: this.state.registerAffiliation,
role: this.state.role,
};
let req = tmpReq;
if (this.state.registerOptional) {
req = Object.assign({}, tmpReq, JSON.parse(this.state.registerOptional));
}

logger.info('start to register user, RegisterRequest: ', req);
getFabricClientSingleton()
.then((client) => {
logger.info('client: ', client.toString());
return client.register(req);
})
.then((enrollment) => {
// TODO: 输出密码,到页面上。
logger.info('register successfully, enrollment: ', enrollment);
})
.catch((err) => {
logger.info('fail to register user, err: ', err);
throw err;
});
}

handleEnroll() {

}

render() {
const outerDivStyle = {
padding: '24px',
};
const spanStyle = {
marginRight: '10px',
display: 'inline-block',
width: '100px',
};
const SpanStyle = {
marginTop: '30px',
};
const fileStyle = {
width: '0.1px',
height: '0.1px',
opacity: 0,
overflow: 'hidden',
position: 'absolute',
zIndex: -1,
};
const labelStyle = {
fontSize: '1.1em',
border: '1px solid rgb(217, 217, 217)',
borderRadius: '4px',
display: 'block',
width: '60%',
height: '32px',
verticalAlign: 'middle',
textAlign: 'center',
lineHeight: '30px',
cursor: 'pointer',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
marginLeft: '146px',
marginTop: '-25px',
};
const configInputStyle = {
marginLeft: '30px',
width: '60%',
};
const CreateInputStyle = {
marginLeft: '36px',
width: '40%',
};
const AddInputStyle = {
marginLeft: '36px',
width: '40%',
};
const DivStyle = {
width: '560px',
marginBottom: '30px',
};
const ButtonStyle = {
marginLeft: '20px',
width: '15%',
};
const TipDivStyle = {
display: 'inline-block',
float: 'right',
marginRight: '20px',
};
const asteriskStyle = {
float: 'left',
color: '#ff0000',
};
return (
<div style={outerDivStyle}>

<div>注册</div>
<div style={DivStyle}>
<span style={asteriskStyle}>*</span>
<span style={spanStyle}>{this.state.Common.REGISTER_USERNAME}</span>
<Input placeholder="User Name" style={configInputStyle} value={this.state.registerUserName} onChange={this.onChangeRegisterUserName} />
</div>
<div style={DivStyle}>
<span style={asteriskStyle}>*</span>
<span style={spanStyle}>组织归属</span>
<Input placeholder="eg. org1.department" style={configInputStyle} value={this.state.registerAffiliation} onChange={this.onChangeRegisterAffiliation} />
</div>
<div style={DivStyle}>
<span style={asteriskStyle}>*</span>
<span style={spanStyle}>角色类型</span>
<Input placeholder="client/peer/orderer/user/app" style={configInputStyle} value={this.state.registerRole} onChange={this.onChangeRegisterRole} />
</div>
<div style={DivStyle}>
<span style={spanStyle}>其他属性</span>
<Input placeholder="Optional" style={configInputStyle} value={this.state.registerOptional} onChange={this.onChangeRegisterOptional} />
</div>
<div style={DivStyle}>
<Button style={ButtonStyle} type="primary" onClick={this.handleRegister}>注册</Button>
</div>

<div >证书私钥领取</div>
<div style={DivStyle}>
<span style={asteriskStyle}>*</span>
<span style={spanStyle}>用户名</span>
<Input placeholder="User Name" style={configInputStyle} value={this.state.enrollUserName} onChange={this.onChangeEnrollUserName} />
</div>
<div style={DivStyle}>
<span style={asteriskStyle}>*</span>
<span style={spanStyle}>密码</span>
<Input placeholder="Password" style={configInputStyle} value={this.state.enrollUserPassword} onChange={this.onChangeEnrollUserPassword} />
</div>
<div style={DivStyle}>
<span style={spanStyle}>其他属性</span>
<Input placeholder="Optional" style={configInputStyle} value={this.state.enrollOptional} onChange={this.onChangeEnrollOptional} />
</div>
<div style={DivStyle}>
<Button style={ButtonStyle} type="primary" onClick={this.handleEnroll}>领取</Button>
</div>
</div>

);
}
}
Loading

0 comments on commit e079428

Please sign in to comment.