]>
git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blob - cmd/web/js/app.js
3 import cookies
from './cookies.js';
4 import page
from 'page';
5 import React
from 'react';
6 import ReactDOM
from 'react-dom';
9 var cookieExpire
= 60 * 30;
11 App
.errorCodeToMessage = function(code
) {
14 return 'The email is not valid';
15 case 'invalid_password':
16 return 'The password is not valid';
18 return 'This email is already registered';
19 case 'invalid_credentials':
20 return 'Invalid credentials';
22 return 'Invalid code !';
23 case 'user_not_confirmed':
24 return 'Your account is being confirmed. Should be very soon !';
30 App
.isUserSignedIn = function() {
31 return cookies
.hasItem('jwt');
34 App
.getUserToken = function() {
35 return cookies
.getItem('jwt');
38 App
.onUserSignIn = function(token
) {
39 if (!token
|| token
=== '') {
44 cookies
.setItem('jwt', token
, cookieExpire
);
48 App
.onUserValidateOtp = function(token
) {
49 if (!token
|| token
=== '') {
54 cookies
.setItem('jwt', token
, cookieExpire
);
58 App
.onUserSignUp = function(token
) {
59 if (!token
|| token
=== '') {
64 cookies
.setItem('jwt', token
, cookieExpire
);
67 App
.getUserJWT = function() {
68 return cookies
.getItem('jwt');
71 App
.page = function(path
, needsAuth
, fn
) {
72 page(path
, function(context
) {
73 if (needsAuth
&& !App
.isUserSignedIn()) {
82 App
.go = function(path
) {
86 App
.start = function() {
90 App
.onInternNavigation = function(href
, e
) {
95 App
.onUserNotAuthorized = function(httpCode
, apiCode
) {
97 case 'not_authorized':
98 cookies
.removeItem('jwt');
101 case 'otp_not_setup':
104 case 'need_otp_validation':
105 page('/otp/validate');
112 App
.mount = function(app
) {
113 var root
= React
.createElement(
115 {className: 'container'},
119 ReactDOM
.unmountComponentAtNode(document
.getElementById('app'));
120 ReactDOM
.render(root
, document
.getElementById('app'));