Blame view
imports/startup/client/routes.js
4.13 KB
c42d4eeac
|
1 |
/* eslint-disable max-len */ |
6be49625f
|
2 3 4 5 |
import React from 'react'; import { render } from 'react-dom'; import { Router, Route, IndexRoute, browserHistory } from 'react-router'; import { Meteor } from 'meteor/meteor'; |
48c0461d6
|
6 7 8 9 |
/** * General Components */ |
cc8fd8a94
|
10 |
import Index from '/imports/client/views/app/module/Index'; |
48c0461d6
|
11 12 13 14 15 16 17 |
/** * Org Components */ import App from '/imports/client/layouts/OrgApp'; import Login from '/imports/client/views/org/enter/login/LoginView'; |
cc8fd8a94
|
18 19 20 |
import NotFound from '/imports/client/views/org/NotFound'; import RecoverPassword from '/imports/client/views/org/enter/RecoverPassword'; import ResetPassword from '/imports/client/views/org/enter/ResetPassword'; |
6be49625f
|
21 |
import { Orgs } from '/imports/collections/orgs/index'; |
48c0461d6
|
22 23 24 25 26 27 28 29 |
/** * NonOrg Components */ import Signup from '/imports/client/views/nonOrg/enter/SignupView'; /** * Invalid Org Components */ |
2b1ad7917
|
30 |
|
4c9b3dfc1
|
31 |
const authenticate = (nextState, replace) => { |
cac7cbc73
|
32 |
if (!Meteor.loggingIn() && !Meteor.userId()) { |
2b1ad7917
|
33 34 |
replace({ pathname: '/login', |
cac7cbc73
|
35 |
state: { nextPathname: nextState.location.pathname }, |
2b1ad7917
|
36 37 38 |
}); } }; |
cc8fd8a94
|
39 |
|
48c0461d6
|
40 |
const detectOrg = () => { |
6be49625f
|
41 |
orgSlug = ""; |
ff976df49
|
42 43 44 |
var hostnameArray = document.location.hostname.split( "." ); if(hostnameArray[1]=='localhost'){ orgSlug = hostnameArray[0]; |
6be49625f
|
45 46 47 |
} if(orgSlug!=""){ Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) { |
cc8fd8a94
|
48 49 50 |
console.log(res); if(res){ Session.set('orgId', res._id._str); |
48c0461d6
|
51 |
render(getOrgRoutes(),document.getElementById('app')); |
6be49625f
|
52 |
}else{ |
48c0461d6
|
53 |
render(getInvalidOrgRoute(),document.getElementById('app')); |
6be49625f
|
54 55 |
} }); |
ff976df49
|
56 |
}else{ |
48c0461d6
|
57 |
render(getNonOrgRoutes(),document.getElementById('app')); |
ff976df49
|
58 |
} |
ff976df49
|
59 |
} |
6be49625f
|
60 61 |
const checkSlug = (nextState, replace) => { orgId = Session.get('orgId'); |
6be49625f
|
62 |
} |
cc8fd8a94
|
63 64 65 66 67 68 69 |
/** There are three types of routes 1)getOrgRoutes: all the routes that should be present for a registered org 2)getInvalidOrgRoute: all the routes where someone tries to enter a subdomain which hasn't been registered yet (404 mostly :D) 3)getNonOrgRoutes: all routes linked to normal site, ie signing up a new org. CHeking out demo and everything internal **/ |
6be49625f
|
70 71 72 73 74 75 76 77 78 79 80 |
const getOrgRoutes = () => ( <Router history={ browserHistory }> <Route path="/" component={ App }> <IndexRoute name="index" component={ Index } onEnter={ checkSlug } /> <Route name="login" path="/login" component={ Login } /> <Route name="recover-password" path="/recover-password" component={ RecoverPassword } /> <Route name="reset-password" path="/reset-password/:token" component={ ResetPassword } /> <Route path="*" component={ NotFound } /> </Route> </Router> ) |
cc8fd8a94
|
81 82 |
const getInvalidOrgRoute = () => ( |
6be49625f
|
83 84 |
<Router history={ browserHistory }> <Route path="/" component={ App }> |
cc8fd8a94
|
85 |
<IndexRoute name="index" component={ NotFound } /> |
6be49625f
|
86 87 88 89 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
ff976df49
|
90 |
|
cc8fd8a94
|
91 |
const getNonOrgRoutes = () => ( |
6be49625f
|
92 93 |
<Router history={ browserHistory }> <Route path="/" component={ App }> |
cc8fd8a94
|
94 95 |
<IndexRoute name="index" component={ Index } onEnter={ checkSlug } /> <Route name="signup" path="/signup" component={ Signup } /> |
6be49625f
|
96 97 98 99 |
<Route path="*" component={ NotFound } /> </Route> </Router> ) |
2b1ad7917
|
100 |
|
27ed00b55
|
101 |
|
6be49625f
|
102 103 |
Meteor.startup(() => { detectOrg(); |
2b1ad7917
|
104 |
}); |