Skip to content

Commit

Permalink
Merge pull request #210 from dengyi9/master
Browse files Browse the repository at this point in the history
CA Management: CA Update Content。  #202
  • Loading branch information
dengyi9 authored Mar 27, 2019
2 parents b976446 + 1ee68ff commit a114ac3
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 6 deletions.
17 changes: 14 additions & 3 deletions src/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,28 @@ Common.LOGIN_CA_SERVER_URL = 'CA Server Url';

// user register page
Common.REGISTER = 'REGISTER';
Common.REGISTER_USERNAME = 'User Name';
Common.REGISTER_USERNAME = 'User ID';
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_USERNAME = 'User ID';
Common.ENROLL_PASSWORD = 'Password';
Common.ENROLL_OPTIONAL = 'Optional';
Common.ENROLL_CONFIRM = 'Get';
Common.ENROLL_CONFIRM = 'Enroll';

// user update & revoke page
Common.REENROLL = 'REENROLL CURRENT USER';
Common.REENROLL_OPTIONAL = 'Optional';
Common.REENROLL_CONFIRM = 'Reenroll';

Common.REVOKE = 'REVOKE';
Common.REVOKE_USERNAME = 'User ID';
Common.REVOKE_OPTIONAL = 'Optional';
Common.REVOKE_CONFIRM = 'Revoke';


Common.WARN = {
chaincodeName: 'chaincode name can not be null!',
Expand Down
15 changes: 13 additions & 2 deletions src/common/common_cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,29 @@ Common.LOGIN_CA_SERVER_URL = 'CA节点地址';

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

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

// user update & revoke page
Common.REENROLL = '更新当前用户';
Common.REENROLL_OPTIONAL = '其他参数';
Common.REENROLL_CONFIRM = '更新';

Common.REVOKE = '吊销';
Common.REVOKE_USERNAME = '用户ID';
Common.REVOKE_OPTIONAL = '其他参数';
Common.REVOKE_CONFIRM = '吊销';


Common.WARN = {
chaincodeName: '链码名称不能为空!',
chaincodeVersion: '链码版本不能为空!',
Expand Down
9 changes: 8 additions & 1 deletion src/components/BasicLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import DataContent from './content/DataContent';
import ChaincodeInvokeContent from './content/ChaincodeInvokeContent';
import ChaincodeInstallContent from './content/ChaincodeInstallContent';
import CARegisterContent from './content/CARegisterContent';
import CAUpdateContent from './content/CAUpdateContent';
import { deleteFabricClientSingleton } from '../util/fabric';

import { getConfigDBSingleton, getInvokeDBSingleton, getChaincodeDBSingleton } from '../util/createDB';
Expand Down Expand Up @@ -38,6 +39,8 @@ function ContentRoute(props) {
return <ChannelManangeContent />;
} else if (props.contentKey === 5) {
return <CARegisterContent />;
} else if (props.contentKey === 6) {
return <CAUpdateContent />;
}
return <h1>The sidebar button is not bound to corresponding content</h1>;
}
Expand Down Expand Up @@ -128,7 +131,11 @@ export default class BasicLayout extends React.Component {
</Menu.Item>
<Menu.Item key="5" onClick={() => this.switchContent(5)}>
<Icon type="user-add" />
<span>{this.state.language === 'cn' ? 'CA注册' : 'CA Register' }</span>
<span>{this.state.language === 'cn' ? 'CA注册' : 'CA Registration' }</span>
</Menu.Item>
<Menu.Item key="6" onClick={() => this.switchContent(6)}>
<Icon type="team" />
<span>{this.state.language === 'cn' ? 'CA更新与吊销' : 'CA Update & Revoke' }</span>
</Menu.Item>
</Menu>
</Sider>
Expand Down
198 changes: 198 additions & 0 deletions src/components/content/CAUpdateContent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
// 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 { TextArea } = Input;
const logger = require('electron-log');

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

reenrollOptional: '',
reenrollResult: '',

revokeUserName: '',
revokeOptional: '',
revokeResult: '',
};

this.onChangeReenrollOptional = this.onChangeReenrollOptional.bind(this);
this.onChangeRevokeUserName = this.onChangeRevokeUserName.bind(this);
this.onChangeRevokeOptional = this.onChangeRevokeOptional.bind(this);
this.handleReenroll = this.handleReenroll.bind(this);
this.handleRevoke = this.handleRevoke.bind(this);
}

onChangeReenrollOptional(event) {
this.setState({ reenrollOptional: event.target.value });
}
onChangeRevokeUserName(event) {
this.setState({ revokeUserName: event.target.value });
}
onChangeRevokeOptional(event) {
this.setState({ revokeOptional: event.target.value });
}

handleReenroll() {
let req = null;
if (this.state.enrollOptional) {
req = JSON.parse(this.state.enrollOptional);
}
const self = this;

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

handleRevoke() {
const tmpReq = {
enrollmentID: this.state.revokeUserName,
};
let req = tmpReq;
if (this.state.revokeOptional) {
req = Object.assign({}, tmpReq, JSON.parse(this.state.revokeOptional));
}

const self = this;

getFabricClientSingleton()
.then((client) => {
logger.debug('start to revoke, request: ', req);
return client.revoke(req);
})
.then((result) => {
logger.debug('revoke successfully, result: ', result);
self.setState({ revokeResult: result.toString() });
})
.catch((err) => {
self.setState({ revokeResult: 'Revocation fails.' });
logger.debug(err);
});
}

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>{this.state.Common.REENROLL}</div>
<div style={DivStyle}>
<span style={spanStyle}>{this.state.Common.REENROLL_OPTIONAL}</span>
<Input placeholder="Optional json parameters" style={configInputStyle} value={this.state.reenrollOptional} onChange={this.onChangeReenrollOptional} />
</div>
<div style={DivStyle}>
<Button style={ButtonStyle} type="primary" onClick={this.handleReenroll}>{this.state.Common.REENROLL_CONFIRM}</Button>
<TextArea
placeholder="Reenroll Result"
value={this.state.reenrollResult}
autosize={{ minRows: 4, maxRows: 4 }}
readOnly
/>
</div>

<div >{this.state.Common.REVOKE}</div>
<div style={DivStyle}>
<span style={asteriskStyle}>*</span>
<span style={spanStyle}>{this.state.Common.REVOKE_USERNAME}</span>
<Input placeholder="User ID" style={configInputStyle} value={this.state.revokeUserName} onChange={this.onChangeRevokeUserName} />
</div>
<div style={DivStyle}>
<span style={spanStyle}>{this.state.Common.REVOKE_OPTIONAL}</span>
<Input placeholder="Optional json parameters" style={configInputStyle} value={this.state.revokeOptional} onChange={this.onChangeRevokeOptional} />
</div>
<div style={DivStyle}>
<Button style={ButtonStyle} type="primary" onClick={this.handleRevoke}>{this.state.Common.REVOKE_CONFIRM}</Button>
<TextArea
placeholder="Revoke Result"
value={this.state.revokeResult}
autosize={{ minRows: 2, maxRows: 2 }}
readOnly
/>
</div>
</div>

);
}
}

0 comments on commit a114ac3

Please sign in to comment.