routes.js
4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* eslint-disable max-len */
import React from 'react';
import { render } from 'react-dom';
import { Router, Route,
IndexRoute, browserHistory } from 'react-router';
import { Meteor } from 'meteor/meteor';
/**
* General Components
*/
import Index from '/imports/client/views/app/module/Index';
/**
* Org Components
*/
import App from '/imports/client/layouts/OrgApp';
import { AppModule } from '/imports/client/views/org/app/module/Index';
import { orgLoginController } from '/imports/client/views/org/enter/login/index';
import RecoverPassword from '/imports/client/views/org/enter/RecoverPassword';
import ResetPassword from '/imports/client/views/org/enter/ResetPassword';
import { Orgs } from '/imports/collections/orgs/index';
import NotFound from '/imports/client/views/org/NotFound';
/**
* NonOrg Components
*/
import Signup from '/imports/client/views/nonOrg/enter/SignupView';
/**
* Invalid Org Components
*/
const authenticate = (nextState, replace) => {
if (!Meteor.loggingIn() && !Meteor.userId()) {
replace({
pathname: '/login',
state: { nextPathname: nextState.location.pathname },
});
}
};
const detectOrg = () => {
orgSlug = "";
var hostnameArray = document.location.hostname.split( "." );
if(hostnameArray[1]=='localhost'){
orgSlug = hostnameArray[0];
}
if(orgSlug!=""){
Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) {
if(res){
Session.set('orgId', res._id._str);
render(getOrgRoutes(),document.getElementById('app'));
}else{
render(getInvalidOrgRoute(),document.getElementById('app'));
}
});
}else{
render(getNonOrgRoutes(),document.getElementById('app'));
}
}
const checkSlug = (nextState, replace) => {
orgId = Session.get('orgId');
}
/**
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
**/
const getOrgRoutes = () => (
<Router history={ browserHistory }>
<Route path="/" component={ App }>
<IndexRoute name="index" component={ AppModule } />
<Route name="login" path="/login" component={ orgLoginController } />
<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>
)
const getInvalidOrgRoute = () => (
<Router history={ browserHistory }>
<Route path="/" component={ App }>
<IndexRoute name="index" component={ NotFound } />
<Route path="*" component={ NotFound } />
</Route>
</Router>
)
const getNonOrgRoutes = () => (
<Router history={ browserHistory }>
<Route path="/" component={ App }>
<IndexRoute name="index" component={ Index } />
<Route name="signup" path="/signup" component={ Signup } />
<Route path="*" component={ NotFound } />
</Route>
</Router>
)
Meteor.startup(() => {
detectOrg();
});