Commit 6be49625fdb5fce08ef1bd22bb32629dc8a74b21

Authored by Deepak
1 parent 79c6eb0795
Exists in master

created route definitions for different Orgs conditions

... ... @@ -8,7 +8,7 @@ meteor-base@1.0.4 # Packages every Meteor app needs to have
8 8 mobile-experience@1.0.4 # Packages for a great mobile UX
9 9 mongo@1.1.15 # The database Meteor supports right now
10 10 reactive-var@1.0.11 # Reactive variable for tracker
11   -session@1.1.7
  11 +session
12 12 tracker@1.1.2 # Meteor's client-side reactive programming library
13 13  
14 14 standard-minifier-css@1.3.3 # CSS minifier run for production mode
... ...
imports/collections/orgs/methods.js
... ... @@ -0,0 +1,36 @@
  1 +// import { } from '/imports/collections/orgs/methods';
  2 +import _ from 'lodash';
  3 +import { Meteor } from 'meteor/meteor';
  4 +import { ValidatedMethod } from 'meteor/mdg:validated-method';
  5 +import { SimpleSchema } from 'meteor/aldeed:simple-schema';
  6 +import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
  7 +import { Bert } from 'meteor/themeteorchef:bert';
  8 +import { Users } from '/imports/collections/users/index';
  9 +import { Orgs } from '/imports/collections/orgs/index';
  10 +// import { sendNotificationAPN } from '/imports/server/push/methods';
  11 +export const orgMethod = new ValidatedMethod({
  12 + name: 'org.method',
  13 +
  14 + validate: new SimpleSchema({
  15 + itemId: { type: String },
  16 + }).validator(),
  17 +
  18 + run({itemId}) {
  19 + return {};
  20 + },
  21 +
  22 +});
  23 +
  24 +export const checkExistingOrg = new ValidatedMethod({
  25 + name: 'checkExistingOrg',
  26 + validate: new SimpleSchema({
  27 + slug: { type: String },
  28 + }).validator(),
  29 +
  30 + run({slug}) {
  31 + org = Orgs.find({slug:slug}).fetch();
  32 + console.log(org);
  33 + return org;
  34 + },
  35 +
  36 +});
... ...
imports/modules/signup.js
... ... @@ -68,9 +68,12 @@ const validate = () => {
68 68 },
69 69 },
70 70 messages: {
  71 + orgSlug: {
  72 + required: 'Choose your school url',
  73 + uniqueSlug: 'This has already been taken!'
  74 + },
71 75 firstName: {
72 76 required: 'First name?',
73   - uniqueSlug: "This Name is already taken"
74 77 },
75 78 lastName: {
76 79 required: 'Last name?',
... ...
imports/startup/client/routes.js
1 1 /* eslint-disable max-len */
2 2  
3   -import React from 'react';
4   -import { render } from 'react-dom';
5   -import { Router, Route, IndexRoute, browserHistory } from 'react-router';
6   -import { Meteor } from 'meteor/meteor';
7   -import App from '../../ui/layouts/App.js';
8   -import Documents from '../../ui/pages/Documents.js';
9   -import NewDocument from '../../ui/pages/NewDocument.js';
10   -import EditDocument from '../../ui/containers/EditDocument.js';
11   -import ViewDocument from '../../ui/containers/ViewDocument.js';
12   -import Index from '../../ui/pages/Index.js';
13   -import Login from '../../ui/pages/Login.js';
14   -import NotFound from '../../ui/pages/NotFound.js';
15   -import RecoverPassword from '../../ui/pages/RecoverPassword.js';
16   -import ResetPassword from '../../ui/pages/ResetPassword.js';
17   -import Signup from '../../ui/pages/Signup.js';
  3 +import React from 'react';
  4 +import { render } from 'react-dom';
  5 +import { Router, Route, IndexRoute, browserHistory } from 'react-router';
  6 +import { Meteor } from 'meteor/meteor';
  7 +import App from '../../ui/layouts/App.js';
  8 +import Documents from '../../ui/pages/Documents.js';
  9 +import NewDocument from '../../ui/pages/NewDocument.js';
  10 +import EditDocument from '../../ui/containers/EditDocument.js';
  11 +import ViewDocument from '../../ui/containers/ViewDocument.js';
  12 +import Index from '../../ui/pages/Index.js';
  13 +import Login from '../../ui/pages/Login.js';
  14 +import NotFound from '../../ui/pages/NotFound.js';
  15 +import RecoverPassword from '../../ui/pages/RecoverPassword.js';
  16 +import ResetPassword from '../../ui/pages/ResetPassword.js';
  17 +import Signup from '../../ui/pages/Signup.js';
  18 +import { Orgs } from '/imports/collections/orgs/index';
  19 +
18 20  
19 21 const authenticate = (nextState, replace) => {
20 22 if (!Meteor.loggingIn() && !Meteor.userId()) {
... ... @@ -24,34 +26,63 @@ const authenticate = (nextState, replace) => {
24 26 });
25 27 }
26 28 };
27   -const detectOrg = () => {
  29 +const detectOrg = (nextState, replace) => {
  30 + orgSlug = "";
28 31 var hostnameArray = document.location.hostname.split( "." );
29 32 if(hostnameArray[1]=='localhost'){
30 33 orgSlug = hostnameArray[0];
  34 + }
  35 + if(orgSlug!=""){
  36 + Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) {
  37 + if(res.length>0){
  38 + console.log(res);
  39 + console.log(res[0]._id._str);
  40 + Session.set('orgId', res[0]._id._str);
  41 + render(getOrgRoutes(),document.getElementById('react-root'));
  42 + }else{
  43 + render(getInvalidOrgRoute(),document.getElementById('react-root'));
  44 + }
  45 + });
31 46 }else{
32   - orgSlug = hostnameArray[0];
  47 + render(getNonOrgRoutes(),document.getElementById('react-root'));
33 48 }
34   -
35 49 }
  50 +const checkSlug = (nextState, replace) => {
  51 + orgId = Session.get('orgId');
  52 + console.log("orgId");
  53 + console.log(orgId);
  54 +}
  55 +const getOrgRoutes = () => (
  56 + <Router history={ browserHistory }>
  57 + <Route path="/" component={ App }>
  58 + <IndexRoute name="index" component={ Index } onEnter={ checkSlug } />
  59 + <Route name="login" path="/login" component={ Login } />
  60 + <Route name="recover-password" path="/recover-password" component={ RecoverPassword } />
  61 + <Route name="reset-password" path="/reset-password/:token" component={ ResetPassword } />
  62 + <Route path="*" component={ NotFound } />
  63 + </Route>
  64 + </Router>
  65 +)
  66 +const getNonOrgRoutes = () => (
  67 + <Router history={ browserHistory }>
  68 + <Route path="/" component={ App }>
  69 + <IndexRoute name="index" component={ Index } onEnter={ checkSlug } />
  70 + <Route name="signup" path="/signup" component={ Signup } />
  71 + <Route path="*" component={ NotFound } />
  72 + </Route>
  73 + </Router>
  74 +)
36 75  
  76 +const getInvalidOrgRoute = () => (
  77 + <Router history={ browserHistory }>
  78 + <Route path="/" component={ App }>
  79 + <IndexRoute name="index" component={ NotFound } />
  80 + <Route path="*" component={ NotFound } />
  81 + </Route>
  82 + </Router>
  83 +)
37 84  
38   -Meteor.startup(() => {
39 85  
40   - render(
41   - <Router history={ browserHistory }>
42   - <Route path="/" component={ App }>
43   - <IndexRoute name="index" component={ Index } />
44   - <Route name="documents" path="/documents" component={ Documents } onEnter={ authenticate } />
45   - <Route name="newDocument" path="/documents/new" component={ NewDocument } onEnter={ authenticate } />
46   - <Route name="editDocument" path="/documents/:_id/edit" component={ EditDocument } onEnter={ authenticate } />
47   - <Route name="viewDocument" path="/documents/:_id" component={ ViewDocument } onEnter={ authenticate } />
48   - <Route name="login" path="/login" component={ Login } />
49   - <Route name="recover-password" path="/recover-password" component={ RecoverPassword } />
50   - <Route name="reset-password" path="/reset-password/:token" component={ ResetPassword } />
51   - <Route name="signup" path="/signup" component={ Signup } />
52   - <Route path="*" component={ NotFound } />
53   - </Route>
54   - </Router>,
55   - document.getElementById('react-root')
56   - );
  86 +Meteor.startup(() => {
  87 + detectOrg();
57 88 });
... ...
imports/startup/server/api.js
1 1 import '../../api/documents/methods.js';
2 2 import '../../api/documents/server/publications.js';
  3 +
  4 +import '/imports/collections/orgs/publications'
  5 +import '/imports/collections/orgs/methods';
... ...
imports/startup/server/index.js
... ... @@ -3,7 +3,3 @@ import &#39;./accounts/creation&#39;;
3 3 import './browser-policy';
4 4 import './fixtures';
5 5 import './api';
6   -
7   -
8   -
9   -import '/imports/collections/orgs/publications'
... ...