]>
Commit | Line | Data |
---|---|---|
1 | import SignupForm from './signup.js'; | |
2 | import SigninForm from './signin.js'; | |
3 | import PasswordResetForm from './password_reset.js'; | |
4 | import ChangePasswordForm from './change_password.js'; | |
5 | import OtpEnrollForm from './otp.js'; | |
6 | import PoloniexController from './poloniex.js'; | |
7 | import App from './app.js'; | |
8 | import Api from './api.js'; | |
9 | import cookies from './cookies.js'; | |
10 | import React from 'react'; | |
11 | import qs from 'qs'; | |
12 | ||
13 | class Header extends React.Component { | |
14 | render = () => { | |
15 | if (this.props.displayLogout === true) { | |
16 | return <div id="header" className="row"> | |
17 | <div className="offset-4 col-4"> | |
18 | <Logo /> | |
19 | </div> | |
20 | <div className="offset-2 col-2 align-self-center h-100"> | |
21 | <a href="/signout"><u>Logout</u></a> | |
22 | </div> | |
23 | </div>; | |
24 | } | |
25 | return <div id="header" className="row"> | |
26 | <div className="offset-4 col-4"> | |
27 | <Logo /> | |
28 | </div> | |
29 | </div>; | |
30 | ||
31 | } | |
32 | } | |
33 | ||
34 | class Logo extends React.Component { | |
35 | render() { | |
36 | return <div id="logo" className="w-100 h-100 align-self-center"> | |
37 | <h1><a href="/">CryptoPF</a></h1> | |
38 | </div>; | |
39 | } | |
40 | } | |
41 | ||
42 | App.page('/signup', false, function(context) { | |
43 | if (App.isUserSignedIn()) { | |
44 | App.go('/me'); | |
45 | return; | |
46 | } | |
47 | ||
48 | App.mount(<div> | |
49 | <Header /> | |
50 | <SignupForm onSuccess={App.onUserSignUp}/> | |
51 | </div>); | |
52 | }); | |
53 | ||
54 | App.page('/signin', false, function(context) { | |
55 | if (App.isUserSignedIn()) { | |
56 | App.go('/me'); | |
57 | return; | |
58 | } | |
59 | ||
60 | App.mount(<div> | |
61 | <Header /> | |
62 | <SigninForm onSuccess={App.onUserSignIn}/> | |
63 | </div>); | |
64 | }); | |
65 | ||
66 | App.page('/reset-password', false, function(context) { | |
67 | if (App.isUserSignedIn()) { | |
68 | App.go('/me'); | |
69 | return; | |
70 | } | |
71 | ||
72 | App.mount(<div> | |
73 | <Header /> | |
74 | <PasswordResetForm /> | |
75 | </div>); | |
76 | }); | |
77 | ||
78 | App.page('/change-password', false, function(context) { | |
79 | if (App.isUserSignedIn()) { | |
80 | App.go('/me'); | |
81 | return; | |
82 | } | |
83 | ||
84 | var token = qs.parse(context.querystring).token; | |
85 | ||
86 | if (token === undefined) { | |
87 | App.go('/'); | |
88 | return; | |
89 | } | |
90 | ||
91 | App.mount(<div> | |
92 | <Header /> | |
93 | <ChangePasswordForm token={token} onSuccess={App.go.bind(App, '/signin')}/> | |
94 | </div>); | |
95 | }); | |
96 | ||
97 | App.page('/signout', true, function(context) { | |
98 | cookies.removeItem('jwt'); | |
99 | ||
100 | App.go('/'); | |
101 | }); | |
102 | ||
103 | App.page('/me', true, function(context) { | |
104 | App.mount(<div> | |
105 | <Header displayLogout={true} /> | |
106 | <PoloniexController/> | |
107 | </div>); | |
108 | }); | |
109 | ||
110 | App.page('/not_confirmed', true, function(context) { | |
111 | App.mount(<div> | |
112 | <Header displayLogout={true}/> | |
113 | <div className="row"> | |
114 | <div className="box offset-3 col-6 text-center"> | |
115 | <p>Please be patient, you account is being confirmed...</p> | |
116 | <p><a href="/me"><u>Refresh</u></a></p> | |
117 | </div> | |
118 | </div> | |
119 | </div>); | |
120 | }); | |
121 | ||
122 | App.page('/otp/setup', true, function(context) { | |
123 | Api.Call('OTP_ENROLL', {}, function(err, status, data) { | |
124 | if (err) { | |
125 | console.error(err, data); | |
126 | return; | |
127 | } | |
128 | ||
129 | App.mount(<div> | |
130 | <Header displayLogout={true}/> | |
131 | <OtpEnrollForm onSuccess={App.onUserValidateOtp} img={'data:image/png;base64,' + data.base64img} secret={data.secret}/> | |
132 | </div>); | |
133 | ||
134 | }); | |
135 | }); | |
136 | ||
137 | App.page('/otp/validate', true, function(context) { | |
138 | App.mount(<div> | |
139 | <Header displayLogout={true}/> | |
140 | <OtpEnrollForm onSuccess={App.onUserValidateOtp} /> | |
141 | </div>); | |
142 | }); | |
143 | ||
144 | App.page('/', false, function(context) { | |
145 | App.go('/me'); | |
146 | }); | |
147 | ||
148 | $(document).ready(function() { | |
149 | App.start(); | |
150 | }); |