Commit 48c0461d6bbc120885949c8cb3bf03cb56588034

Authored by Deepak
1 parent cc8fd8a946
Exists in master

some more file restructuring

1 <head> 1 <head>
2 <meta charset="utf-8"> 2 <meta charset="utf-8">
3 <title>Application Name</title> 3 <title>YoungDesk</title>
4 <meta name="description" content="A description for the application."> 4 <meta name="description" content="All your organization's need.">
5 <meta name="viewport" content="initial-scale=1, minimal-ui, maximum-scale=1, minimum-scale=1" /> 5 <meta name="viewport" content="initial-scale=1, minimal-ui, maximum-scale=1, minimum-scale=1" />
6 <link rel="shortcut icon" type="image/png" href="/favicon.png?v1" sizes="16x16 32x32 64x64"> 6 <link rel="shortcut icon" type="image/png" href="/favicon.png?v1" sizes="16x16 32x32 64x64">
7 <link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-precomposed.png"> 7 <link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-precomposed.png">
8 <link
9 href='https://fonts.googleapis.com/css?family=Alef'
10 rel='stylesheet'
11 type='text/css'
12 />
13 <link
14 href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css"
15 rel="stylesheet"
16 integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1"
17 crossorigin="anonymous"
18 />
8 </head> 19 </head>
9 20
10 <body> 21 <body>
11 <div id="react-root"></div> 22 <div id="app"></div>
12 </body> 23 </body>
13 24
imports/client/views/org/enter/Login.js
1 import React from 'react'; File was deleted
2 import { Link } from 'react-router';
3 import { Row, Col, FormGroup, ControlLabel, FormControl, Button } from 'react-bootstrap';
4 import handleLogin from './module/login';
5
6 export default class Login extends React.Component {
7 componentDidMount() {
8 handleLogin({ component: this });
9 }
10
11 handleSubmit(event) {
12 event.preventDefault();
13 }
14
15 render() {
16 return (
17 <div className="Login">
18 <Row>
19 <Col xs={ 12 } sm={ 6 } md={ 4 }>
20 <h4 className="page-header">Login</h4>
21 <form
22 ref={ form => (this.loginForm = form) }
23 className="login"
24 onSubmit={ this.handleSubmit }
25 >
26 <FormGroup>
27 <ControlLabel>Email Address</ControlLabel>
28 <FormControl
29 type="email"
30 ref="emailAddress"
31 name="emailAddress"
32 placeholder="Email Address"
33 />
34 </FormGroup>
35 <FormGroup>
36 <ControlLabel>
37 <span className="pull-left">Password</span>
38 <Link className="pull-right" to="/recover-password">Forgot Password?</Link>
39 </ControlLabel>
40 <FormControl
41 type="password"
42 ref="password"
43 name="password"
44 placeholder="Password"
45 />
46 </FormGroup>
47 <Button type="submit" bsStyle="success">Login</Button>
48 </form>
49 </Col>
50 </Row>
51 </div>
52 );
53 }
54 }
55 1 import React from 'react';
imports/client/views/org/enter/login/LoginView.js
File was created 1 import React from 'react';
2 import { Link } from 'react-router';
3 import { Row, Col, FormGroup, ControlLabel, FormControl, Button } from 'react-bootstrap';
4 import handleLogin from './login';
5
6 export default class Login extends React.Component {
7 componentDidMount() {
8 handleLogin({ component: this });
9 }
10
11 handleSubmit(event) {
12 event.preventDefault();
13 }
14
15 render() {
16 return (
17 <div className="Login">
18 <Row>
19 <Col xs={ 12 } sm={ 6 } md={ 4 }>
20 <h4 className="page-header">Login</h4>
21 <form
22 ref={ form => (this.loginForm = form) }
23 className="login"
24 onSubmit={ this.handleSubmit }
25 >
26 <FormGroup>
27 <ControlLabel>Email Address</ControlLabel>
28 <FormControl
29 type="email"
30 ref="emailAddress"
31 name="emailAddress"
32 placeholder="Email Address"
33 />
34 </FormGroup>
35 <FormGroup>
36 <ControlLabel>
37 <span className="pull-left">Password</span>
38 <Link className="pull-right" to="/recover-password">Forgot Password?</Link>
39 </ControlLabel>
40 <FormControl
41 type="password"
42 ref="password"
43 name="password"
44 placeholder="Password"
45 />
46 </FormGroup>
47 <Button type="submit" bsStyle="success">Login</Button>
48 </form>
49 </Col>
50 </Row>
51 </div>
52 );
53 }
54 }
55
imports/client/views/org/enter/login/login.js
File was created 1 /* eslint-disable no-undef */
2
3 import { browserHistory } from 'react-router';
4 import { Meteor } from 'meteor/meteor';
5 import { Bert } from 'meteor/themeteorchef:bert';
6 import '/imports/client/components/validation';
7
8 let component;
9
10 const login = () => {
11 const email = document.querySelector('[name="emailAddress"]').value;
12 const password = document.querySelector('[name="password"]').value;
13
14 Meteor.loginWithPassword(email, password, (error) => {
15 if (error) {
16 Bert.alert(error.reason, 'warning');
17 } else {
18 Bert.alert('Logged in!', 'success');
19
20 const { location } = component.props;
21 if (location.state && location.state.nextPathname) {
22 browserHistory.push(location.state.nextPathname);
23 } else {
24 browserHistory.push('/');
25 }
26 }
27 });
28 };
29
30 const validate = () => {
31 $(component.loginForm).validate({
32 rules: {
33 emailAddress: {
34 required: true,
35 email: true,
36 },
37 password: {
38 required: true,
39 },
40 },
41 messages: {
42 emailAddress: {
43 required: 'Need an email address here.',
44 email: 'Is this email address legit?',
45 },
46 password: {
47 required: 'Need a password here.',
48 },
49 },
50 submitHandler() { login(); },
51 });
52 };
53
54 export default function handleLogin(options) {
55 component = options.component;
56 validate();
57 }
58
imports/client/views/org/enter/module/login.js
1 /* eslint-disable no-undef */ File was deleted
2
3 import { browserHistory } from 'react-router';
4 import { Meteor } from 'meteor/meteor';
5 import { Bert } from 'meteor/themeteorchef:bert';
6 import '/imports/client/components/validation';
7
8 let component;
9
10 const login = () => {
11 const email = document.querySelector('[name="emailAddress"]').value;
12 const password = document.querySelector('[name="password"]').value;
13
14 Meteor.loginWithPassword(email, password, (error) => {
15 if (error) {
16 Bert.alert(error.reason, 'warning');
17 } else {
18 Bert.alert('Logged in!', 'success');
19
20 const { location } = component.props;
21 if (location.state && location.state.nextPathname) {
22 browserHistory.push(location.state.nextPathname);
23 } else {
24 browserHistory.push('/');
25 }
26 }
27 });
28 };
29
30 const validate = () => {
31 $(component.loginForm).validate({
32 rules: {
33 emailAddress: {
34 required: true,
35 email: true,
36 },
37 password: {
38 required: true,
39 },
40 },
41 messages: {
42 emailAddress: {
43 required: 'Need an email address here.',
44 email: 'Is this email address legit?',
45 },
46 password: {
47 required: 'Need a password here.',
48 },
49 },
50 submitHandler() { login(); },
51 });
52 };
53
54 export default function handleLogin(options) {
55 component = options.component;
56 validate();
57 }
58 1 /* eslint-disable no-undef */
imports/client/views/org/module/Index.js
imports/client/views/org/module/navigation/AppNavigation.js
File was created 1 import React from 'react';
2 import { Navbar } from 'react-bootstrap';
3 import { Link } from 'react-router';
4 import PublicNavigation from './PublicNavigation.js';
5 import AuthenticatedNavigation from './AuthenticatedNavigation.js';
6
7 const renderNavigation = hasUser => (hasUser ? <AuthenticatedNavigation /> : <PublicNavigation />);
8
9 const AppNavigation = ({ hasUser }) => (
10 <Navbar>
11 <Navbar.Header>
12 <Navbar.Brand>
13 <Link to="/">Application Name</Link>
14 </Navbar.Brand>
15 <Navbar.Toggle />
16 </Navbar.Header>
17 <Navbar.Collapse>
18 { renderNavigation(hasUser) }
19 </Navbar.Collapse>
20 </Navbar>
21 );
22
23 AppNavigation.propTypes = {
24 hasUser: React.PropTypes.object,
25 };
26
27 export default AppNavigation;
28
imports/client/views/org/module/navigation/AuthenticatedNavigation.js
File was created 1 import React from 'react';
2 import { browserHistory } from 'react-router';
3 import { LinkContainer } from 'react-router-bootstrap';
4 import { Nav, NavItem, NavDropdown, MenuItem } from 'react-bootstrap';
5 import { Meteor } from 'meteor/meteor';
6
7 const handleLogout = () => Meteor.logout(() => browserHistory.push('/login'));
8
9 const userName = () => {
10 const user = Meteor.user();
11 const name = user && user.profile ? user.profile.name : '';
12 return user ? `${name.first} ${name.last}` : '';
13 };
14
15 const AuthenticatedNavigation = () => (
16 <div>
17 <Nav>
18 <LinkContainer to="/documents">
19 <NavItem eventKey={ 2 } href="/documents">Documents</NavItem>
20 </LinkContainer>
21 </Nav>
22 <Nav pullRight>
23 <NavDropdown eventKey={ 3 } title={ userName() } id="basic-nav-dropdown">
24 <MenuItem eventKey={ 3.1 } onClick={ handleLogout }>Logout</MenuItem>
25 </NavDropdown>
26 </Nav>
27 </div>
28 );
29
30 export default AuthenticatedNavigation;
31
imports/client/views/org/module/navigation/Loading.js
File was created 1 import React from 'react';
2
3 const Loading = () => (
4 <svg
5 version="1.1"
6 className="Loading"
7 xmlns="http://www.w3.org/2000/svg"
8 x="0px"
9 y="0px"
10 width="40px"
11 height="40px"
12 viewBox="0 0 40 40"
13 enableBackground="new 0 0 40 40">
14 <path
15 opacity="1.0"
16 fill="#eee"
17 d="M20.201,5.169c-8.254,0-14.946,6.692-14.946,14.946c0,8.255,6.692,14.946,
18 14.946,14.946s14.946-6.691,14.946-14.946C35.146,11.861,28.455,5.169,20.201,
19 5.169z M20.201,31.749c-6.425,0-11.634-5.208-11.634-11.634c0-6.425,
20 5.209-11.634,11.634-11.634c6.425,0,11.633,5.209,11.633,11.634C31.834,
21 26.541,26.626,31.749,20.201,31.749z"/>
22 <path
23 fill="#da5347"
24 d="M26.013,10.047l1.654-2.866c-2.198-1.272-4.743-2.012-7.466-2.012h0v3.312h0
25 C22.32,8.481,24.301,9.057,26.013,10.047z">
26 </path>
27 </svg>
28 );
29
30 export default Loading;
31
imports/client/views/org/module/navigation/PublicNavigation.js
File was created 1 import React from 'react';
2 import { LinkContainer } from 'react-router-bootstrap';
3 import { Nav, NavItem } from 'react-bootstrap';
4
5 const PublicNavigation = () => (
6 <Nav pullRight>
7 <LinkContainer to="signup">
8 <NavItem eventKey={ 1 } href="/signup">Sign Up</NavItem>
9 </LinkContainer>
10 <LinkContainer to="login">
11 <NavItem eventKey={ 2 } href="/login">Log In</NavItem>
12 </LinkContainer>
13 </Nav>
14 );
15
16 export default PublicNavigation;
17
imports/client/views/org/module/navigation/index.js
File was created 1 import { composeWithTracker } from 'react-komposer';
2 import { Meteor } from 'meteor/meteor';
3 import AppNavigation from '../components/AppNavigation.js';
4
5 const composer = (props, onData) => onData(null, { hasUser: Meteor.user() });
6
7 export default composeWithTracker(composer, {}, {}, { pure: false })(AppNavigation);
8
imports/startup/client/routes.js
1 /* eslint-disable max-len */ 1 /* eslint-disable max-len */
2 2
3 import React from 'react'; 3 import React from 'react';
4 import { render } from 'react-dom'; 4 import { render } from 'react-dom';
5 import { Router, Route, IndexRoute, browserHistory } from 'react-router'; 5 import { Router, Route, IndexRoute, browserHistory } from 'react-router';
6 import { Meteor } from 'meteor/meteor'; 6 import { Meteor } from 'meteor/meteor';
7 import App from '/imports/client/layouts/OrgApp'; 7
8 /**
9 * General Components
10 */
8 import Index from '/imports/client/views/app/module/Index'; 11 import Index from '/imports/client/views/app/module/Index';
9 import Login from '/imports/client/views/org/enter/Login'; 12
13 /**
14 * Org Components
15 */
16
17 import App from '/imports/client/layouts/OrgApp';
18 import Login from '/imports/client/views/org/enter/login/LoginView';
10 import NotFound from '/imports/client/views/org/NotFound'; 19 import NotFound from '/imports/client/views/org/NotFound';
11 import RecoverPassword from '/imports/client/views/org/enter/RecoverPassword'; 20 import RecoverPassword from '/imports/client/views/org/enter/RecoverPassword';
12 import ResetPassword from '/imports/client/views/org/enter/ResetPassword'; 21 import ResetPassword from '/imports/client/views/org/enter/ResetPassword';
13 import Signup from '/imports/client/views/nonOrg/enter/SignupView';
14 import { Orgs } from '/imports/collections/orgs/index'; 22 import { Orgs } from '/imports/collections/orgs/index';
15 23
24 /**
25 * NonOrg Components
26 */
27 import Signup from '/imports/client/views/nonOrg/enter/SignupView';
28
29 /**
30 * Invalid Org Components
31 */
32
33
16 34
17 const authenticate = (nextState, replace) => { 35 const authenticate = (nextState, replace) => {
18 if (!Meteor.loggingIn() && !Meteor.userId()) { 36 if (!Meteor.loggingIn() && !Meteor.userId()) {
19 replace({ 37 replace({
20 pathname: '/login', 38 pathname: '/login',
21 state: { nextPathname: nextState.location.pathname }, 39 state: { nextPathname: nextState.location.pathname },
22 }); 40 });
23 } 41 }
24 }; 42 };
25 43
26 44
27 const detectOrg = (nextState, replace) => { 45 const detectOrg = () => {
28 orgSlug = ""; 46 orgSlug = "";
29 var hostnameArray = document.location.hostname.split( "." ); 47 var hostnameArray = document.location.hostname.split( "." );
30 if(hostnameArray[1]=='localhost'){ 48 if(hostnameArray[1]=='localhost'){
31 orgSlug = hostnameArray[0]; 49 orgSlug = hostnameArray[0];
32 } 50 }
33 if(orgSlug!=""){ 51 if(orgSlug!=""){
34 Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) { 52 Meteor.call('checkExistingOrg', {slug:orgSlug}, function(err, res) {
35 console.log(res); 53 console.log(res);
36 if(res){ 54 if(res){
37 Session.set('orgId', res._id._str); 55 Session.set('orgId', res._id._str);
38 render(getOrgRoutes(),document.getElementById('react-root')); 56 render(getOrgRoutes(),document.getElementById('app'));
39 }else{ 57 }else{
40 render(getInvalidOrgRoute(),document.getElementById('react-root')); 58 render(getInvalidOrgRoute(),document.getElementById('app'));
41 } 59 }
42 }); 60 });
43 }else{ 61 }else{
44 render(getNonOrgRoutes(),document.getElementById('react-root')); 62 render(getNonOrgRoutes(),document.getElementById('app'));
45 } 63 }
46 } 64 }
47 const checkSlug = (nextState, replace) => { 65 const checkSlug = (nextState, replace) => {
48 orgId = Session.get('orgId'); 66 orgId = Session.get('orgId');
49 } 67 }
50 68
51 /** 69 /**
52 There are three types of routes 70 There are three types of routes
53 1)getOrgRoutes: all the routes that should be present for a registered org 71 1)getOrgRoutes: all the routes that should be present for a registered org
54 2)getInvalidOrgRoute: all the routes where someone tries to enter a subdomain which hasn't been registered yet (404 mostly :D) 72 2)getInvalidOrgRoute: all the routes where someone tries to enter a subdomain which hasn't been registered yet (404 mostly :D)
55 3)getNonOrgRoutes: all routes linked to normal site, ie signing up a new org. CHeking out demo and everything internal 73 3)getNonOrgRoutes: all routes linked to normal site, ie signing up a new org. CHeking out demo and everything internal
56 **/ 74 **/
57 const getOrgRoutes = () => ( 75 const getOrgRoutes = () => (
58 <Router history={ browserHistory }> 76 <Router history={ browserHistory }>
59 <Route path="/" component={ App }> 77 <Route path="/" component={ App }>
60 <IndexRoute name="index" component={ Index } onEnter={ checkSlug } /> 78 <IndexRoute name="index" component={ Index } onEnter={ checkSlug } />
61 <Route name="login" path="/login" component={ Login } /> 79 <Route name="login" path="/login" component={ Login } />
62 <Route name="recover-password" path="/recover-password" component={ RecoverPassword } /> 80 <Route name="recover-password" path="/recover-password" component={ RecoverPassword } />
63 <Route name="reset-password" path="/reset-password/:token" component={ ResetPassword } /> 81 <Route name="reset-password" path="/reset-password/:token" component={ ResetPassword } />
64 <Route path="*" component={ NotFound } /> 82 <Route path="*" component={ NotFound } />
65 </Route> 83 </Route>
66 </Router> 84 </Router>
67 ) 85 )
68 86
69 const getInvalidOrgRoute = () => ( 87 const getInvalidOrgRoute = () => (
70 <Router history={ browserHistory }> 88 <Router history={ browserHistory }>
71 <Route path="/" component={ App }> 89 <Route path="/" component={ App }>
72 <IndexRoute name="index" component={ NotFound } /> 90 <IndexRoute name="index" component={ NotFound } />
73 <Route path="*" component={ NotFound } /> 91 <Route path="*" component={ NotFound } />
74 </Route> 92 </Route>
75 </Router> 93 </Router>
76 ) 94 )
77 95
78 const getNonOrgRoutes = () => ( 96 const getNonOrgRoutes = () => (
79 <Router history={ browserHistory }> 97 <Router history={ browserHistory }>
80 <Route path="/" component={ App }> 98 <Route path="/" component={ App }>
81 <IndexRoute name="index" component={ Index } onEnter={ checkSlug } /> 99 <IndexRoute name="index" component={ Index } onEnter={ checkSlug } />
82 <Route name="signup" path="/signup" component={ Signup } /> 100 <Route name="signup" path="/signup" component={ Signup } />
83 <Route path="*" component={ NotFound } /> 101 <Route path="*" component={ NotFound } />
84 </Route> 102 </Route>
85 </Router> 103 </Router>
86 ) 104 )
87 105
88 106
89 Meteor.startup(() => { 107 Meteor.startup(() => {
90 detectOrg(); 108 detectOrg();
91 }); 109 });
imports/startup/server/browser-policy.js
1 import { BrowserPolicy } from 'meteor/browser-policy-common'; 1 import { BrowserPolicy } from 'meteor/browser-policy-common';
2 // e.g., BrowserPolicy.content.allowOriginForAll( 's3.amazonaws.com' ); 2 // e.g., BrowserPolicy.content.allowOriginForAll( 's3.amazonaws.com' );
3 BrowserPolicy.content.allowFontOrigin("data:"); 3 BrowserPolicy.content.allowFontOrigin("data:");
4
5 BrowserPolicy.content.disallowEval();
6
7 BrowserPolicy.framing.allowAll();
8 BrowserPolicy.content.allowInlineScripts();
9 BrowserPolicy.content.allowInlineStyles();
10 BrowserPolicy.content.allowSameOriginForAll();
11 BrowserPolicy.content.allowDataUrlForAll();
12 BrowserPolicy.content.allowOriginForAll('*');
13 BrowserPolicy.content.allowOriginForAll('http://*');
14 BrowserPolicy.content.allowOriginForAll('https://*');
4 15