Skip to content

Commit

Permalink
Merge pull request #209 from dengyi9/master
Browse files Browse the repository at this point in the history
 CA Management. #202
  • Loading branch information
dengyi9 authored Mar 27, 2019
2 parents e079428 + 42f15ce commit b976446
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 18 deletions.
11 changes: 11 additions & 0 deletions src/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@ Common.LOGIN_ORDERER_SSL_TARGET = 'Orderer SSL Target';
Common.LOGIN_CA_SERVER_URL = 'CA Server Url';

// user register page
Common.REGISTER = 'REGISTER';
Common.REGISTER_USERNAME = 'User Name';
Common.REGISTER_AFFILIATION = 'Affiliation';
Common.REGISTER_ROLE = 'Role';
Common.REGISTER_OPTIONAL = 'Optional';
Common.REGISTER_CONFIRM = 'Register';

Common.ENROLL = 'ENROLLMENT';
Common.ENROLL_USERNAME = 'User Name';
Common.ENROLL_PASSWORD = 'Password';
Common.ENROLL_OPTIONAL = 'Optional';
Common.ENROLL_CONFIRM = 'Get';

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

// user register page
Common.REGISTER = '注册';
Common.REGISTER_USERNAME = '用户名';
Common.REGISTER_AFFILIATION = '组织归属';
Common.REGISTER_ROLE = '角色类型';
Common.REGISTER_OPTIONAL = '其他属性';
Common.REGISTER_CONFIRM = '注册';

Common.ENROLL = '证书私钥获取';
Common.ENROLL_USERNAME = '用户名';
Common.ENROLL_PASSWORD = '密码';
Common.ENROLL_OPTIONAL = '其他属性';
Common.ENROLL_CONFIRM = '获取';

Common.WARN = {
chaincodeName: '链码名称不能为空!',
Expand Down
75 changes: 57 additions & 18 deletions src/components/content/CARegisterContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import React from 'react';
import { Button, Input } from 'antd';
import { getFabricClientSingleton } from '../../util/fabric';

const { TextArea } = Input;
const logger = require('electron-log');

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

export default class CARegisterContent extends React.Component {
constructor(props) {
super(props);
Expand All @@ -22,10 +22,12 @@ export default class CARegisterContent extends React.Component {
registerAffiliation: '',
registerRole: '',
registerOptional: '',
registerResult: '',

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

this.onChangeRegisterUserName = this.onChangeRegisterUserName.bind(this);
Expand Down Expand Up @@ -73,25 +75,50 @@ export default class CARegisterContent extends React.Component {
if (this.state.registerOptional) {
req = Object.assign({}, tmpReq, JSON.parse(this.state.registerOptional));
}

const self = this;
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);
.then((secret) => {
// 输出密码,到页面上。
self.setState({ registerResult: secret });
logger.debug('register successfully, secret: ', secret);
})
.catch((err) => {
self.setState({ registerResult: 'Register fails. Please check inputs/your CA identity are valid.' });
logger.info('fail to register user, err: ', err);
throw err;
});
}

handleEnroll() {
const tmpReq = {
enrollmentID: this.state.enrollUserName,
enrollmentSecret: this.state.enrollUserPassword,
};
let req = tmpReq;
if (this.state.enrollOptional) {
req = Object.assign({}, tmpReq, JSON.parse(this.state.enrollOptional));
}
const self = this;

getFabricClientSingleton()
.then((client) => {
logger.debug('start to enroll, request: ', req);
return client.enroll(req);
})
.then((enrollment) => {
self.setState({ enrollResult: 'private key:\n' + enrollment.key.toBytes() + '\ncertificate:\n' + enrollment.certificate });
logger.debug('enroll after registering successfully, enrollment: ', enrollment);
// TODO: 输出enrollment中的证书、私钥到外部
})
.catch((err) => {
self.setState({ enrollResult: 'Register fails. Please check inputs/your CA identity are valid.' });
logger.debug(err);
});
}

render() {
Expand Down Expand Up @@ -163,47 +190,59 @@ export default class CARegisterContent extends React.Component {
return (
<div style={outerDivStyle}>

<div>注册</div>
<div>{this.state.Common.REGISTER}</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>
<span style={spanStyle}>{this.state.Common.REGISTER_AFFILIATION}</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} />
<span style={spanStyle}>{this.state.Common.REGISTER_ROLE}</span>
<Input placeholder="eg. 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} />
<span style={spanStyle}>{this.state.Common.REGISTER_OPTIONAL}</span>
<Input placeholder="Optional json parameters" style={configInputStyle} value={this.state.registerOptional} onChange={this.onChangeRegisterOptional} />
</div>
<div style={DivStyle}>
<Button style={ButtonStyle} type="primary" onClick={this.handleRegister}>注册</Button>
<Button style={ButtonStyle} type="primary" onClick={this.handleRegister}>{this.state.Common.REGISTER_CONFIRM}</Button>
<TextArea
placeholder="Register Result: Password"
value={this.state.registerResult}
autosize={{ minRows: 1, maxRows: 1 }}
readOnly
/>
</div>

<div >证书私钥领取</div>
<div >{this.state.Common.ENROLL}</div>
<div style={DivStyle}>
<span style={asteriskStyle}>*</span>
<span style={spanStyle}>用户名</span>
<span style={spanStyle}>{this.state.Common.ENROLL_USERNAME}</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>
<span style={spanStyle}>{this.state.Common.ENROLL_PASSWORD}</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} />
<span style={spanStyle}>{this.state.Common.ENROLL_OPTIONAL}</span>
<Input placeholder="Optional json parameters" style={configInputStyle} value={this.state.enrollOptional} onChange={this.onChangeEnrollOptional} />
</div>
<div style={DivStyle}>
<Button style={ButtonStyle} type="primary" onClick={this.handleEnroll}>领取</Button>
<Button style={ButtonStyle} type="primary" onClick={this.handleEnroll}>{this.state.Common.ENROLL_CONFIRM}</Button>
<TextArea
placeholder="Enroll Result"
value={this.state.enrollResult}
autosize={{ minRows: 4, maxRows: 4 }}
readOnly
/>
</div>
</div>

Expand Down

0 comments on commit b976446

Please sign in to comment.