aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/js
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/web/js')
-rw-r--r--cmd/web/js/api.js12
-rw-r--r--cmd/web/js/app.js8
-rw-r--r--cmd/web/js/cookies.js2
-rw-r--r--cmd/web/js/main.jsx61
-rw-r--r--cmd/web/js/otp.jsx72
-rw-r--r--cmd/web/js/poloniex.jsx154
-rw-r--r--cmd/web/js/signin.jsx66
-rw-r--r--cmd/web/js/signup.jsx100
8 files changed, 255 insertions, 220 deletions
diff --git a/cmd/web/js/api.js b/cmd/web/js/api.js
index 5c19fdf..5cbf5eb 100644
--- a/cmd/web/js/api.js
+++ b/cmd/web/js/api.js
@@ -1,6 +1,6 @@
1'use strict'; 1'use strict';
2 2
3var App = require('./app.js'); 3import App from './app.js';
4 4
5var Api = {}; 5var Api = {};
6 6
@@ -28,7 +28,7 @@ var ApiEndpoints = {
28 {'name': 'email', 'mandatory': true, 'inquery': true}, 28 {'name': 'email', 'mandatory': true, 'inquery': true},
29 {'name': 'password', 'mandatory': true, 'inquery': true} 29 {'name': 'password', 'mandatory': true, 'inquery': true}
30 ], 30 ],
31 'buildUrl': function(params) { 31 'buildUrl': function() {
32 return '/signup'; 32 return '/signup';
33 } 33 }
34 }, 34 },
@@ -39,7 +39,7 @@ var ApiEndpoints = {
39 {'name': 'email', 'mandatory': true, 'inquery': true}, 39 {'name': 'email', 'mandatory': true, 'inquery': true},
40 {'name': 'password', 'mandatory': true, 'inquery': true} 40 {'name': 'password', 'mandatory': true, 'inquery': true}
41 ], 41 ],
42 'buildUrl': function(params) { 42 'buildUrl': function() {
43 return '/signin'; 43 return '/signin';
44 } 44 }
45 }, 45 },
@@ -80,7 +80,7 @@ var ApiEndpoints = {
80 'type': 'GET', 80 'type': 'GET',
81 'auth': true, 81 'auth': true,
82 'parameters': [], 82 'parameters': [],
83 'buildUrl': function(params) { 83 'buildUrl': function() {
84 return '/otp/enroll'; 84 return '/otp/enroll';
85 } 85 }
86 }, 86 },
@@ -90,7 +90,7 @@ var ApiEndpoints = {
90 'parameters': [ 90 'parameters': [
91 {'name': 'pass', 'mandatory': true, 'inquery': true}, 91 {'name': 'pass', 'mandatory': true, 'inquery': true},
92 ], 92 ],
93 'buildUrl': function(params) { 93 'buildUrl': function() {
94 return '/otp/validate'; 94 return '/otp/validate';
95 } 95 }
96 }, 96 },
@@ -183,5 +183,5 @@ Api.DoRequest = function(type, url, params, headers, callback) {
183 }); 183 });
184}; 184};
185 185
186module.exports.Api = Api; 186export default Api;
187 187
diff --git a/cmd/web/js/app.js b/cmd/web/js/app.js
index 4946dcc..8573b6e 100644
--- a/cmd/web/js/app.js
+++ b/cmd/web/js/app.js
@@ -1,7 +1,9 @@
1'use strict'; 1'use strict';
2 2
3var cookies = require('./cookies.js'); 3import cookies from './cookies.js';
4var page = require('page'); 4import page from 'page';
5import React from 'react';
6import ReactDOM from 'react-dom';
5 7
6var App = {}; 8var App = {};
7var cookieExpire = 60 * 30; 9var cookieExpire = 60 * 30;
@@ -118,4 +120,4 @@ App.mount = function(app) {
118 ReactDOM.render(root, document.getElementById('app')); 120 ReactDOM.render(root, document.getElementById('app'));
119}; 121};
120 122
121module.exports = App; 123export default App;
diff --git a/cmd/web/js/cookies.js b/cmd/web/js/cookies.js
index 9cc7ca9..3dd0925 100644
--- a/cmd/web/js/cookies.js
+++ b/cmd/web/js/cookies.js
@@ -1,3 +1,5 @@
1/* eslint-disable */
2
1'use strict'; 3'use strict';
2 4
3/*\ 5/*\
diff --git a/cmd/web/js/main.jsx b/cmd/web/js/main.jsx
index e5e505d..827b83d 100644
--- a/cmd/web/js/main.jsx
+++ b/cmd/web/js/main.jsx
@@ -1,20 +1,21 @@
1var SignupForm = require('./signup.js').SignupForm; 1import SignupForm from './signup.js';
2var SigninForm = require('./signin.js').SigninForm; 2import SigninForm from './signin.js';
3var OtpEnrollForm = require('./otp.js').OtpEnrollForm; 3import OtpEnrollForm from './otp.js';
4var PoloniexController = require('./poloniex.js').PoloniexController; 4import PoloniexController from './poloniex.js';
5var App = require('./app.js'); 5import App from './app.js';
6var Api = require('./api.js').Api; 6import Api from './api.js';
7var cookies = require('./cookies.js'); 7import cookies from './cookies.js';
8import React from 'react';
8 9
9var Logo = React.createClass({ 10class Logo extends React.Component {
10 render: function() { 11 render() {
11 return (<div className='row'> 12 return <div className="row">
12 <div id='logo' className='offset-4 col-4'> 13 <div id="logo" className="offset-4 col-4">
13 <a href='/'>Cryptoportfolio</a> 14 <a href="/">Cryptoportfolio</a>
14 </div> 15 </div>
15 </div>); 16 </div>;
16 } 17 }
17}); 18}
18 19
19App.page('/signup', false, function(context) { 20App.page('/signup', false, function(context) {
20 if (App.isUserSignedIn()) { 21 if (App.isUserSignedIn()) {
@@ -22,12 +23,10 @@ App.page('/signup', false, function(context) {
22 return; 23 return;
23 } 24 }
24 25
25 App.mount( 26 App.mount(<div>
26 <div>
27 <Logo /> 27 <Logo />
28 <SignupForm onSuccess={App.onUserSignUp}/> 28 <SignupForm onSuccess={App.onUserSignUp}/>
29 </div> 29 </div>);
30 );
31}); 30});
32 31
33App.page('/signin', false, function(context) { 32App.page('/signin', false, function(context) {
@@ -36,12 +35,10 @@ App.page('/signin', false, function(context) {
36 return; 35 return;
37 } 36 }
38 37
39 App.mount( 38 App.mount(<div>
40 <div>
41 <Logo /> 39 <Logo />
42 <SigninForm onSuccess={App.onUserSignIn}/> 40 <SigninForm onSuccess={App.onUserSignIn}/>
43 </div> 41 </div>);
44 );
45}); 42});
46 43
47App.page('/signout', true, function(context) { 44App.page('/signout', true, function(context) {
@@ -51,12 +48,10 @@ App.page('/signout', true, function(context) {
51}); 48});
52 49
53App.page('/me', true, function(context) { 50App.page('/me', true, function(context) {
54 App.mount( 51 App.mount(<div>
55 <div>
56 <Logo /> 52 <Logo />
57 <PoloniexController/> 53 <PoloniexController/>
58 </div> 54 </div>);
59 );
60}); 55});
61 56
62App.page('/otp/setup', true, function(context) { 57App.page('/otp/setup', true, function(context) {
@@ -66,23 +61,19 @@ App.page('/otp/setup', true, function(context) {
66 return; 61 return;
67 } 62 }
68 63
69 App.mount( 64 App.mount(<div>
70 <div>
71 <Logo /> 65 <Logo />
72 <OtpEnrollForm onSuccess={App.onUserValidateOtp} img={'data:image/png;base64,' + data.base64img} secret={data.secret}/> 66 <OtpEnrollForm onSuccess={App.onUserValidateOtp} img={'data:image/png;base64,' + data.base64img} secret={data.secret}/>
73 </div> 67 </div>);
74 );
75 68
76 }.bind(this)); 69 });
77}); 70});
78 71
79App.page('/otp/validate', true, function(context) { 72App.page('/otp/validate', true, function(context) {
80 App.mount( 73 App.mount(<div>
81 <div>
82 <Logo /> 74 <Logo />
83 <OtpEnrollForm onSuccess={App.onUserValidateOtp} /> 75 <OtpEnrollForm onSuccess={App.onUserValidateOtp} />
84 </div> 76 </div>);
85 );
86}); 77});
87 78
88App.page('/', false, function(context) { 79App.page('/', false, function(context) {
diff --git a/cmd/web/js/otp.jsx b/cmd/web/js/otp.jsx
index a0ee5cc..aecf032 100644
--- a/cmd/web/js/otp.jsx
+++ b/cmd/web/js/otp.jsx
@@ -1,9 +1,10 @@
1var Api = require('./api.js').Api; 1import Api from './api.js';
2var App = require('./app.js'); 2import App from './app.js';
3var classNames = require('classnames'); 3import classNames from 'classnames';
4import React from 'react';
4 5
5var OtpQrCode = React.createClass({ 6class OtpQrCode extends React.Component {
6 render: function() { 7 render = () => {
7 return ( 8 return (
8 <div> 9 <div>
9 <img src={this.props.img} /> 10 <img src={this.props.img} />
@@ -11,13 +12,15 @@ var OtpQrCode = React.createClass({
11 </div> 12 </div>
12 ); 13 );
13 } 14 }
14}); 15}
15 16
16module.exports.OtpEnrollForm = React.createClass({ 17class OtpEnrollForm extends React.Component {
17 getInitialState: function() { 18 constructor(props) {
18 return {'hideMsg': true, 'msg': '', 'msgOk': false, 'pass': ''}; 19 super(props);
19 }, 20 this.state = {'hideMsg': true, 'msg': '', 'msgOk': false, 'pass': ''};
20 handleSubmit: function(e) { 21 }
22
23 handleSubmit = (e) => {
21 Api.Call('OTP_VALIDATE', {'pass': this.state.pass}, function(err, status, data) { 24 Api.Call('OTP_VALIDATE', {'pass': this.state.pass}, function(err, status, data) {
22 if (err) { 25 if (err) {
23 console.error(err, data); 26 console.error(err, data);
@@ -31,40 +34,45 @@ module.exports.OtpEnrollForm = React.createClass({
31 }.bind(this)); 34 }.bind(this));
32 35
33 e.preventDefault(); 36 e.preventDefault();
34 }, 37 }
35 handlePassChange: function(event) { 38
39 handlePassChange = (event) => {
36 this.setState({'pass': event.target.value}); 40 this.setState({'pass': event.target.value});
37 }, 41 }
38 hideMessage: function() { 42
43 hideMessage = () => {
39 this.setState({'hideMsg': true}); 44 this.setState({'hideMsg': true});
40 }, 45 }
41 displayMessage: function(msg, ok) { 46
47 displayMessage = (msg, ok) => {
42 this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false}); 48 this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false});
43 }, 49 }
44 render: function() { 50
51 render = () => {
45 var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); 52 var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk});
46 var qrCode = null; 53 var qrCode = null;
47 54
48 if (this.props.img) { 55 if (this.props.img) {
49 qrCode = ( 56 qrCode =
50 <div className='row justify-content-center'> 57 <div className="row justify-content-center">
51 <OtpQrCode img={this.props.img} secret={this.props.secret} /> 58 <OtpQrCode img={this.props.img} secret={this.props.secret} />
52 </div> 59 </div>;
53 ); 60}
54 }
55 return ( 61 return (
56 <div className='row otp-enroll'> 62 <div className="row otp-enroll">
57 <div className='offset-4 col-4 col-xs-offset-1 col-xs-10 text-center'> 63 <div className="offset-4 col-4 col-xs-offset-1 col-xs-10 text-center">
58 {qrCode} 64 {qrCode}
59 <div className='row justify-content-center'> 65 <div className="row justify-content-center">
60 <form role='form' onSubmit={this.handleSubmit}> 66 <form role="form" onSubmit={this.handleSubmit}>
61 <input className='form-control' type='pass' placeholder='code' onChange={this.handlePassChange} /> 67 <input className="form-control" type="pass" placeholder="code" onChange={this.handlePassChange} />
62 <input className='form-control submit' type='submit' value='Validate' /> 68 <input className="form-control submit" type="submit" value="Validate" />
63 <div className={cName} ref='message'>{this.state.msg}</div> 69 <div className={cName}>{this.state.msg}</div>
64 </form> 70 </form>
65 </div> 71 </div>
66 </div> 72 </div>
67 </div> 73 </div>
68 ); 74 );
69 } 75 }
70}); 76}
77
78export default OtpEnrollForm;
diff --git a/cmd/web/js/poloniex.jsx b/cmd/web/js/poloniex.jsx
index 8b577b4..96384fd 100644
--- a/cmd/web/js/poloniex.jsx
+++ b/cmd/web/js/poloniex.jsx
@@ -1,14 +1,18 @@
1var Api = require('./api.js').Api; 1import Api from './api.js';
2var classNames = require('classnames'); 2import classNames from 'classnames';
3 3import React from 'react';
4module.exports.PoloniexController = React.createClass({ 4
5 getInitialState: function() { 5class PoloniexController extends React.Component {
6 return {'apiKey': '', 'apiSecret': '', 'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}; 6 constructor(props) {
7 }, 7 super(props);
8 handleCredentialsChange: function(key, secret) { 8 this.state = {'apiKey': '', 'apiSecret': '', 'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null};
9 }
10
11 handleCredentialsChange = (key, secret) => {
9 this.setState({'apiKey': key, 'apiSecret': secret}); 12 this.setState({'apiKey': key, 'apiSecret': secret});
10 }, 13 }
11 handleCredentialsSubmit: function() { 14
15 handleCredentialsSubmit = () => {
12 if (!this.state.apiKey || !this.state.apiSecret) { 16 if (!this.state.apiKey || !this.state.apiSecret) {
13 return; 17 return;
14 } 18 }
@@ -21,8 +25,9 @@ module.exports.PoloniexController = React.createClass({
21 this.setState({'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); 25 this.setState({'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null});
22 this.loadBalance(); 26 this.loadBalance();
23 }.bind(this)); 27 }.bind(this));
24 }, 28 }
25 loadBalance: function() { 29
30 loadBalance = () => {
26 Api.Call('MARKET_BALANCE', {'name': 'poloniex', 'currency': 'BTC'}, function(err, status, data) { 31 Api.Call('MARKET_BALANCE', {'name': 'poloniex', 'currency': 'BTC'}, function(err, status, data) {
27 if (err) { 32 if (err) {
28 console.error(err, data); 33 console.error(err, data);
@@ -34,8 +39,9 @@ module.exports.PoloniexController = React.createClass({
34 39
35 this.setState({'flag': 'ok', 'valueCurrency': data.valueCurrency, 'balanceValue': data.value, 'balance': data.balance}); 40 this.setState({'flag': 'ok', 'valueCurrency': data.valueCurrency, 'balanceValue': data.value, 'balance': data.balance});
36 }.bind(this)); 41 }.bind(this));
37 }, 42 }
38 componentDidMount: function() { 43
44 componentDidMount = () => {
39 Api.Call('MARKET', {'name': 'poloniex'}, function(err, status, data) { 45 Api.Call('MARKET', {'name': 'poloniex'}, function(err, status, data) {
40 if (err) { 46 if (err) {
41 console.error(err, data); 47 console.error(err, data);
@@ -51,8 +57,9 @@ module.exports.PoloniexController = React.createClass({
51 57
52 this.setState({'apiKey': data.key, 'apiSecret': data.secret, 'flag': flag}); 58 this.setState({'apiKey': data.key, 'apiSecret': data.secret, 'flag': flag});
53 }.bind(this)); 59 }.bind(this));
54 }, 60 }
55 render: function() { 61
62 render = () => {
56 var displayText = null; 63 var displayText = null;
57 switch (this.state.flag) { 64 switch (this.state.flag) {
58 case 'loading': 65 case 'loading':
@@ -81,13 +88,15 @@ module.exports.PoloniexController = React.createClass({
81 </div> 88 </div>
82 ); 89 );
83 } 90 }
84}); 91}
92
93class PoloniexBalance extends React.Component {
94 constructor(props) {
95 super(props);
96 this.state = {'hideMsg': true, 'msg': '', 'msgOk': false};
97 }
85 98
86var PoloniexBalance = React.createClass({ 99 render = () => {
87 getInitialState: function() {
88 return {'hideMsg': true, 'msg': '', 'msgOk': false};
89 },
90 render: function() {
91 var dashboard = null; 100 var dashboard = null;
92 101
93 if (this.props.balanceValue !== null) { 102 if (this.props.balanceValue !== null) {
@@ -96,36 +105,33 @@ var PoloniexBalance = React.createClass({
96 return <div key={currency}><i className={classNames('cc', currency)}></i> {this.props.balance[currency]}</div>; 105 return <div key={currency}><i className={classNames('cc', currency)}></i> {this.props.balance[currency]}</div>;
97 }.bind(this)); 106 }.bind(this));
98 107
99 dashboard = ( 108 dashboard =
100 <div className='row'> 109 <div className="row">
101 <div className='col-4 align-self-center h-100'> 110 <div className="col-4 align-self-center h-100">
102 <div> 111 <div>
103 {balance} 112 {balance}
104 </div> 113 </div>
105 </div> 114 </div>
106 <div className='offset-1 col-7 h-100 align-self-center'> 115 <div className="offset-1 col-7 h-100 align-self-center">
107 <div className='text-center'> 116 <div className="text-center">
108 Balance ({this.props.balanceCurrency}): <span>{this.props.balanceValue} <i className={classNames('cc', this.props.balanceCurrency)}></i></span> 117 Balance ({this.props.balanceCurrency}): <span>{this.props.balanceValue} <i className={classNames('cc', this.props.balanceCurrency)}></i></span>
109 </div> 118 </div>
110 </div> 119 </div>
111 </div> 120 </div>;
112 ); 121} else {
113 } else { 122 dashboard =
114 dashboard = ( 123 <div className="row">
115 <div className='row'> 124 <div className="col-12 text-center">
116 <div className='col-12 text-center'>
117 <span>{this.props.displayText}</span> 125 <span>{this.props.displayText}</span>
118 </div> 126 </div>
119 </div> 127 </div>;
120 128}
121 );
122 }
123 129
124 return ( 130 return (
125 <div className='row'> 131 <div className="row">
126 <div className='box offset-2 col-8'> 132 <div className="box offset-2 col-8">
127 <div className='row'> 133 <div className="row">
128 <div className='col-4'>Portfolio</div> 134 <div className="col-4">Portfolio</div>
129 </div> 135 </div>
130 <hr/> 136 <hr/>
131 {dashboard} 137 {dashboard}
@@ -133,53 +139,57 @@ var PoloniexBalance = React.createClass({
133 </div> 139 </div>
134 ); 140 );
135 } 141 }
136}); 142}
137 143
138module.exports.PoloniexBalance = PoloniexBalance; 144class PoloniexCredentialsForm extends React.Component {
145 constructor(props) {
146 super(props);
147 this.state = {'hideMsg': true, 'msg': '', 'editMode': false, 'msgOk': false};
148 }
139 149
140var PoloniexCredentialsForm = React.createClass({ 150 handleSubmit = (e) => {
141 getInitialState: function() {
142 return {'hideMsg': true, 'msg': '', 'editMode': false, 'msgOk': false};
143 },
144 handleSubmit: function(e) {
145 this.props.onCredentialsSubmit(); 151 this.props.onCredentialsSubmit();
146 this.setState({'editMode': false}); 152 this.setState({'editMode': false});
147 e.preventDefault(); 153 e.preventDefault();
148 }, 154 }
149 handleApiKeyChange: function(event) { 155
156 handleApiKeyChange = (event) => {
150 this.props.onCredentialsChange(event.target.value, this.props.apiSecret); 157 this.props.onCredentialsChange(event.target.value, this.props.apiSecret);
151 }, 158 }
152 handleApiSecretChange: function(event) { 159
160 handleApiSecretChange = (event) => {
153 this.props.onCredentialsChange(this.props.apiKey, event.target.value); 161 this.props.onCredentialsChange(this.props.apiKey, event.target.value);
154 }, 162 }
155 onEditClick: function() { 163
164 onEditClick = () => {
156 this.setState({'editMode': true}); 165 this.setState({'editMode': true});
157 }, 166 }
158 render: function() { 167
159 var submitType = (this.state.editMode === true) ? 'submit' : 'hidden'; 168 render = () => {
160 var buttonDisplay = (this.state.editMode === true) ? 'none' : 'inline'; 169 var submitType = this.state.editMode === true ? 'submit' : 'hidden';
161 var secretDisplayed = (this.state.editMode === true) ? this.props.apiSecret : 'XXXXXXX'; 170 var buttonDisplay = this.state.editMode === true ? 'none' : 'inline';
162 var keyDisplayed = (this.state.editMode === true) ? this.props.apiKey : 'XXXXXXX'; 171 var secretDisplayed = this.state.editMode === true ? this.props.apiSecret : 'XXXXXXX';
172 var keyDisplayed = this.state.editMode === true ? this.props.apiKey : 'XXXXXXX';
163 173
164 return ( 174 return (
165 <div className='row api-credentials-form'> 175 <div className="row api-credentials-form">
166 <div className='offset-3 col-6 box'> 176 <div className="offset-3 col-6 box">
167 <span className='text-center'>Poloniex credentials</span> 177 <span className="text-center">Poloniex credentials</span>
168 <hr/> 178 <hr/>
169 <form role='form' onSubmit={this.handleSubmit}> 179 <form role="form" onSubmit={this.handleSubmit}>
170 <label className='w-100'>Key: 180 <label className="w-100">Key:
171 <input className='form-control' type='text' placeholder='key' value={keyDisplayed} onChange={this.handleApiKeyChange} disabled={!this.state.editMode}/> 181 <input className="form-control" type="text" placeholder="key" value={keyDisplayed} onChange={this.handleApiKeyChange} disabled={!this.state.editMode}/>
172 </label> 182 </label>
173 <label className='w-100'>Secret: 183 <label className="w-100">Secret:
174 <input className='form-control' type='text' placeholder='secret' value={secretDisplayed} onChange={this.handleApiSecretChange} disabled={!this.state.editMode}/> 184 <input className="form-control" type="text" placeholder="secret" value={secretDisplayed} onChange={this.handleApiSecretChange} disabled={!this.state.editMode}/>
175 </label> 185 </label>
176 <input className='form-control submit' type={submitType} value='Save' /> 186 <input className="form-control submit" type={submitType} value="Save" />
177 <button className='form-control submit' style={{display: buttonDisplay}} onSubmit={null} onClick={this.onEditClick} type='button'>Show/Edit</button> 187 <button className="form-control submit" style={{display: buttonDisplay}} onSubmit={null} onClick={this.onEditClick} type="button">Show/Edit</button>
178 </form> 188 </form>
179 </div> 189 </div>
180 </div> 190 </div>
181 ); 191 );
182 } 192 }
183}); 193}
184 194
185module.exports.PoloniexCredentialsForm = PoloniexCredentialsForm; 195export default PoloniexController;
diff --git a/cmd/web/js/signin.jsx b/cmd/web/js/signin.jsx
index a2cfd1b..bff497e 100644
--- a/cmd/web/js/signin.jsx
+++ b/cmd/web/js/signin.jsx
@@ -1,12 +1,15 @@
1var Api = require('./api.js').Api; 1import Api from './api.js';
2var App = require('./app.js'); 2import App from './app.js';
3var classNames = require('classnames'); 3import classNames from 'classnames';
4 4import React from 'react';
5module.exports.SigninForm = React.createClass({ 5
6 getInitialState: function() { 6class SigninForm extends React.Component {
7 return {'hideMsg': true, 'msg': '', 'msgOk': false, 'password': '', 'email': ''}; 7 constructor(props) {
8 }, 8 super(props);
9 handleSubmit: function(e) { 9 this.state = {'hideMsg': true, 'msg': '', 'msgOk': false, 'password': '', 'email': ''};
10 }
11
12 handleSubmit = (e) => {
10 Api.Call('SIGNIN', {'password': this.state.password, 'email': this.state.email}, function(err, status, data) { 13 Api.Call('SIGNIN', {'password': this.state.password, 'email': this.state.email}, function(err, status, data) {
11 if (err) { 14 if (err) {
12 console.error(err, data); 15 console.error(err, data);
@@ -19,34 +22,41 @@ module.exports.SigninForm = React.createClass({
19 22
20 }.bind(this)); 23 }.bind(this));
21 e.preventDefault(); 24 e.preventDefault();
22 }, 25 }
23 handlePasswordChange: function(event) { 26
27 handlePasswordChange = (event) => {
24 this.setState({'password': event.target.value}); 28 this.setState({'password': event.target.value});
25 }, 29 }
26 handleEmailChange: function(event) { 30
31 handleEmailChange = (event) => {
27 this.setState({'email': event.target.value}); 32 this.setState({'email': event.target.value});
28 }, 33 }
29 hideMessage: function() { 34
35 hideMessage = () => {
30 this.setState({'hideMsg': true}); 36 this.setState({'hideMsg': true});
31 }, 37 }
32 displayMessage: function(msg, ok) { 38
39 displayMessage = (msg, ok) => {
33 this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false}); 40 this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false});
34 }, 41 }
35 render: function() { 42
43 render = () => {
36 var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); 44 var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk});
37 return ( 45 return (
38 <div className='row sign-in'> 46 <div className="row sign-in">
39 <div className='offset-4 col-4 col-xs-offset-1 col-xs-10 text-center'> 47 <div className="offset-4 col-4 col-xs-offset-1 col-xs-10 text-center">
40 <form role='form' onSubmit={this.handleSubmit}> 48 <form role="form" onSubmit={this.handleSubmit}>
41 <input className='form-control' type='email' placeholder='email' onChange={this.handleEmailChange} /> 49 <input className="form-control" type="email" placeholder="email" onChange={this.handleEmailChange} />
42 <input className='form-control' type='password' placeholder='password' onChange={this.handlePasswordChange} /> 50 <input className="form-control" type="password" placeholder="password" onChange={this.handlePasswordChange} />
43 <input className='form-control submit' type='submit' value='Sign In' /> 51 <input className="form-control submit" type="submit" value="Sign In" />
44 <div className={cName} ref='message'>{this.state.msg}</div> 52 <div className={cName}>{this.state.msg}</div>
45 </form> 53 </form>
46 <a href='#' onClick={App.onInternNavigation.bind(this, '/signup')}><u>Sign up</u></a> 54 <a href="#" onClick={App.onInternNavigation.bind(this, '/signup')}><u>Sign up</u></a>
47 </div> 55 </div>
48 </div> 56 </div>
49 ); 57 );
50 } 58 }
51}); 59}
60
61export default SigninForm;
52 62
diff --git a/cmd/web/js/signup.jsx b/cmd/web/js/signup.jsx
index 404a828..affa18e 100644
--- a/cmd/web/js/signup.jsx
+++ b/cmd/web/js/signup.jsx
@@ -1,56 +1,68 @@
1var Api = require('./api.js').Api; 1import Api from './api.js';
2var App = require('./app.js'); 2import App from './app.js';
3var classNames = require('classnames'); 3import classNames from 'classnames';
4 4import React from 'react';
5module.exports.SignupForm = React.createClass({ 5
6 getInitialState: function() { 6class SignupForm extends React.Component {
7 return {'hideMsg': true, 'msg': '', 'msgOk': false, 'password': '', 'email': ''}; 7 constructor(props) {
8 }, 8 super(props);
9 handleSubmit: function(e) { 9 this.state = {'hideMsg': true, 'msg': '', 'msgOk': false, 'password': '', 'email': ''};
10 Api.Call('SIGNUP', 10 }
11 { 11
12 'password': this.state.password, 12 handleSubmit = (e) => {
13 'email': this.state.email 13 Api.Call(
14 }, 14 'SIGNUP',
15 function(err, status, data) { 15 {
16 if (err) { 16 'password': this.state.password,
17 console.error(err, data); 17 'email': this.state.email
18 this.displayMessage(App.errorCodeToMessage(err.code), false); 18 },
19 return; 19 function(err, status, data) {
20 } 20 if (err) {
21 21 console.error(err, data);
22 this.displayMessage('Thank You. Your account is being confirmed. Check your mailbox soon', true); 22 this.displayMessage(App.errorCodeToMessage(err.code), false);
23 this.props.onSuccess(data.token); 23 return;
24 24 }
25 }.bind(this)); 25
26 this.displayMessage('Thank You. Your account is being confirmed. Check your mailbox soon', true);
27 this.props.onSuccess(data.token);
28
29 }.bind(this)
30);
26 e.preventDefault(); 31 e.preventDefault();
27 }, 32 }
28 handlePasswordChange: function(event) { 33
34 handlePasswordChange = (event) => {
29 this.setState({'password': event.target.value}); 35 this.setState({'password': event.target.value});
30 }, 36 }
31 handleEmailChange: function(event) { 37
38 handleEmailChange = (event) => {
32 this.setState({'email': event.target.value}); 39 this.setState({'email': event.target.value});
33 }, 40 }
34 hideMessage: function() { 41
42 hideMessage = () => {
35 this.setState({'hideMsg': true}); 43 this.setState({'hideMsg': true});
36 }, 44 }
37 displayMessage: function(msg, ok) { 45
46 displayMessage = (msg, ok) => {
38 this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false}); 47 this.setState({'msg': msg, 'msgOk': ok, 'hideMsg': false});
39 }, 48 }
40 render: function() { 49
50 render = () => {
41 var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk}); 51 var cName = classNames('form-message', {'hidden': this.state.hideMsg, 'message-ok': this.state.msgOk});
42 return ( 52 return (
43 <div className='row sign-in'> 53 <div className="row sign-in">
44 <div className='offset-4 col-4 col-xs-offset-1 col-xs-10 text-center'> 54 <div className="offset-4 col-4 col-xs-offset-1 col-xs-10 text-center">
45 <form role='form' onSubmit={this.handleSubmit}> 55 <form role="form" onSubmit={this.handleSubmit}>
46 <input className='form-control' type='email' placeholder='email' onChange={this.handleEmailChange} /> 56 <input className="form-control" type="email" placeholder="email" onChange={this.handleEmailChange} />
47 <input className='form-control' type='password' placeholder='password' onChange={this.handlePasswordChange} /> 57 <input className="form-control" type="password" placeholder="password" onChange={this.handlePasswordChange} />
48 <input className='form-control submit' type='submit' value='Sign Up' /> 58 <input className="form-control submit" type="submit" value="Sign Up" />
49 <div className={cName} ref='message'>{this.state.msg}</div> 59 <div className={cName}>{this.state.msg}</div>
50 <a href='#' onClick={App.onInternNavigation.bind(this, '/signin')}><u>Sign In</u></a> 60 <a href="#" onClick={App.onInternNavigation.bind(this, '/signin')}><u>Sign In</u></a>
51 </form> 61 </form>
52 </div> 62 </div>
53 </div> 63 </div>
54 ); 64 );
55 } 65 }
56}); 66}
67
68export default SignupForm;