]>
git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blob - cmd/web/js/app.js
3 var cookies
= require('./cookies.js');
4 var page
= require('page');
7 var cookieExpire
= 60 * 30;
9 App
.errorCodeToMessage = function(code
) {
12 return 'The email is not valid';
13 case 'invalid_password':
14 return 'The password is not valid';
16 return 'This email is already registered';
17 case 'invalid_credentials':
18 return 'Invalid credentials';
20 return 'Invalid code !';
21 case 'user_not_confirmed':
22 return 'Your account is being confirmed. Should be very soon !';
28 App
.isUserSignedIn = function() {
29 return cookies
.hasItem('jwt');
32 App
.getUserToken = function() {
33 return cookies
.getItem('jwt');
36 App
.onUserSignIn = function(token
) {
37 if (!token
|| token
=== '') {
42 cookies
.setItem('jwt', token
, cookieExpire
);
46 App
.onUserValidateOtp = function(token
) {
47 if (!token
|| token
=== '') {
52 cookies
.setItem('jwt', token
, cookieExpire
);
56 App
.onUserSignUp = function(token
) {
57 if (!token
|| token
=== '') {
62 cookies
.setItem('jwt', token
, cookieExpire
);
65 App
.getUserJWT = function() {
66 return cookies
.getItem('jwt');
69 App
.page = function(path
, needsAuth
, fn
) {
70 page(path
, function(context
) {
71 if (needsAuth
&& !App
.isUserSignedIn()) {
80 App
.go = function(path
) {
84 App
.start = function() {
88 App
.onInternNavigation = function(href
, e
) {
93 App
.onUserNotAuthorized = function(httpCode
, apiCode
) {
95 case 'not_authorized':
96 cookies
.removeItem('jwt');
102 case 'need_otp_validation':
103 page('/otp/validate');
110 App
.mount = function(app
) {
111 var root
= React
.createElement(
113 {className: 'container'},
117 ReactDOM
.unmountComponentAtNode(document
.getElementById('app'));
118 ReactDOM
.render(root
, document
.getElementById('app'));
121 module
.exports
= App
;