import SignupForm from './signup.js';
import SigninForm from './signin.js';
import PasswordResetForm from './password_reset.js';
import ChangePasswordForm from './change_password.js';
import OtpEnrollForm from './otp.js';
import PoloniexController from './poloniex.js';
import App from './app.js';
import Api from './api.js';
import cookies from './cookies.js';
import React from 'react';
import qs from 'qs';
App.page('/signup', false, function(context) {
if (App.isUserSignedIn()) {
App.go('/me');
return;
}
App.mount(<div>
<SignupForm onSuccess={App.onUserSignUp}/>
</div>);
});
App.page('/signin', false, function(context) {
if (App.isUserSignedIn()) {
App.go('/me');
return;
}
App.mount(<div>
<SigninForm onSuccess={App.onUserSignIn}/>
</div>);
});
App.page('/reset-password', false, function(context) {
if (App.isUserSignedIn()) {
App.go('/me');
return;
}
App.mount(<div>
<PasswordResetForm />
</div>);
});
App.page('/change-password', false, function(context) {
if (App.isUserSignedIn()) {
App.go('/me');
return;
}
var token = qs.parse(context.querystring).token;
if (token === undefined) {
App.go('/');
return;
}
App.mount(<div>
<ChangePasswordForm token={token} onSuccess={App.go.bind(App, '/signin')}/>
</div>);
});
App.page('/signout', true, function(context) {
cookies.removeItem('jwt');
App.go('/');
});
App.page('/me', true, function(context) {
App.mount(<div>
<PoloniexController/>
</div>);
});
App.page('/not_confirmed', true, function(context) {
App.mount(<div>
<div className="row">
<div className="box offset-3 col-6 text-center">
<p>Please be patient, you account is being confirmed...</p>
<p><a href="/me"><u>Refresh</u></a></p>
</div>
</div>
</div>);
});
App.page('/otp/setup', true, function(context) {
Api.Call('OTP_ENROLL', {}, function(err, status, data) {
if (err) {
console.error(err, data);
return;
}
App.mount(<div>
<OtpEnrollForm onSuccess={App.onUserValidateOtp} img={'data:image/png;base64,' + data.base64img} secret={data.secret}/>
</div>);
});
});
App.page('/otp/validate', true, function(context) {
App.mount(<div>
<OtpEnrollForm onSuccess={App.onUserValidateOtp} />
</div>);
});
App.page('/', false, function(context) {
App.go('/me');
});
$(document).ready(function() {
App.start();
});