1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00
onion/js/components/coa_verify_container.js
Brett Sun 7014514654 Use UrlResolver to resolve api urls based on white labelling rather than updating ApiUrl's export
Keeping an export constant is more predictable and less surprising for
most people.
2016-06-14 17:58:00 +02:00

119 lines
4.1 KiB
JavaScript

'use strict';
import React from 'react';
import GlobalNotificationModel from '../models/global_notification_model';
import GlobalNotificationActions from '../actions/global_notification_actions';
import Form from './ascribe_forms/form';
import InputTextAreaToggable from './ascribe_forms/input_textarea_toggable';
import Property from './ascribe_forms/property';
import AscribeSpinner from './ascribe_spinner';
import withContext from './context/with_context';
import { locationShape } from './prop_types';
import { setDocumentTitle } from '../utils/dom';
import { getLangText } from '../utils/lang';
import { resolveUrl } from '../utils/url_resolver';
let CoaVerifyContainer = React.createClass({
propTypes: {
// Injected through HOCs
location: locationShape.isRequired
},
render() {
const { message, signature } = this.props.location.query;
setDocumentTitle(getLangText('Verify your Certificate of Authenticity'));
return (
<div className="ascribe-login-wrapper">
<br />
<div className="ascribe-login-text ascribe-login-header">
{getLangText('Verify your Certificate of Authenticity')}
</div>
<CoaVerifyForm
message={message}
signature={signature}/>
<br />
<br />
{getLangText('ascribe is using the following public key for verification')}:
<br />
<pre>
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDddadqY31kKPFYk8PQA8BWSTbm
gaGf9KEYBALp2nWAJcwq80qBzGF+gfi0Z+yb4ooeKHl27GnuxZYValE1Z5ZujfeJ
TgO4li59ZMYiah8oXZp/OysrBwCvWw0PtWd8/D9Nc4PqyOz5gzEh6kFah5VsuAke
Znu2w7KmeLZ85SmwEQIDAQAB
-----END PUBLIC KEY-----
</pre>
</div>
);
}
});
let CoaVerifyForm = React.createClass({
propTypes: {
message: React.PropTypes.string,
signature: React.PropTypes.string
},
handleSuccess(response){
if (response.verdict) {
const notification = new GlobalNotificationModel(getLangText('Certificate of Authenticity successfully verified'), 'success');
GlobalNotificationActions.appendGlobalNotification(notification);
}
},
render() {
const { message, signature } = this.props;
return (
<Form
url={resolveUrl('coa_verify')}
handleSuccess={this.handleSuccess}
buttons={
<button
type="submit"
className="btn btn-default btn-wide">
{getLangText('Verify your Certificate of Authenticity')}
</button>
}
spinner={
<span className="btn btn-default btn-wide btn-spinner">
<AscribeSpinner color="dark-blue" size="md" />
</span>
}>
<Property
name='message'
label={getLangText('Message')}>
<input
type="text"
placeholder={getLangText('Copy paste the message on the bottom of your Certificate of Authenticity')}
autoComplete="on"
defaultValue={message}
required />
</Property>
<Property
name='signature'
label="Signature"
editable={true}
overrideForm={true}>
<InputTextAreaToggable
rows={3}
placeholder={getLangText('Copy paste the signature on the bottom of your Certificate of Authenticity')}
defaultValue={signature}
required />
</Property>
<hr />
</Form>
);
}
});
export default withContext(CoaVerifyContainer, 'location');