├── .DS_Store ├── .babelrc ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .travis.yml ├── LICENSE ├── Procfile ├── README.md ├── favicon.ico ├── fonts ├── material-design-icons │ ├── LICENSE.txt │ ├── Material-Design-Icons.eot │ ├── Material-Design-Icons.svg │ ├── Material-Design-Icons.ttf │ ├── Material-Design-Icons.woff │ └── Material-Design-Icons.woff2 └── roboto │ ├── Roboto-Bold.eot │ ├── Roboto-Bold.ttf │ ├── Roboto-Bold.woff │ ├── Roboto-Bold.woff2 │ ├── Roboto-Light.eot │ ├── Roboto-Light.ttf │ ├── Roboto-Light.woff │ ├── Roboto-Light.woff2 │ ├── Roboto-Medium.eot │ ├── Roboto-Medium.ttf │ ├── Roboto-Medium.woff │ ├── Roboto-Medium.woff2 │ ├── Roboto-Regular.eot │ ├── Roboto-Regular.ttf │ ├── Roboto-Regular.woff │ ├── Roboto-Regular.woff2 │ ├── Roboto-Thin.eot │ ├── Roboto-Thin.ttf │ ├── Roboto-Thin.woff │ └── Roboto-Thin.woff2 ├── global.scss ├── index.html ├── package.json ├── server ├── controllers │ ├── data │ │ └── dataController.js │ └── user │ │ └── userController.js ├── models │ ├── dataModel.js │ └── userModel.js ├── routes │ ├── apiRouter.js │ └── appRouter.js ├── server.js └── services │ └── passport.js ├── src ├── actions │ ├── constants.js │ ├── index.js │ └── login.js ├── containers │ ├── about │ │ └── index.js │ ├── app │ │ └── index.js │ ├── dashboard │ │ └── index.js │ ├── login │ │ ├── require_auth.js │ │ ├── signin.js │ │ ├── signup.js │ │ └── style.scss │ ├── navbar │ │ ├── index.js │ │ └── style.scss │ └── text-input │ │ └── index.js ├── helpers │ ├── highlight.js │ ├── progress.js │ └── spinner.js ├── index.js ├── middlewares │ └── token.js ├── reducers │ ├── main.js │ └── user.js └── store │ └── index.js ├── test ├── actions │ ├── index_spec.js │ └── login_spec.js ├── components │ ├── app_spec.js │ └── navbar_spec.js ├── reducers │ ├── students-local_spec.js │ └── user_spec.js └── test_helper.js ├── webpack-config.js └── webpack.production.config.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/.DS_Store -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "react", "stage-0"], 3 | "plugins": ["transform-runtime", "add-module-exports"] 4 | } 5 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | **/dist/* 2 | **/node_modules/* 3 | **/webpack.config.js 4 | **/webpack.production.config.js 5 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb", 3 | "env": { 4 | "browser": true, 5 | "mocha": true, 6 | "node": true 7 | }, 8 | "rules": { 9 | "valid-jsdoc": 2, 10 | 11 | "react/jsx-uses-react": 2, 12 | "react/jsx-uses-vars": 2, 13 | "react/react-in-jsx-scope": 2, 14 | "react/jsx-boolean-value": 0, 15 | 16 | "no-var": 0, 17 | "vars-on-top": 0, 18 | 19 | "comma-dangle": 0, 20 | "max-len": [2, 150, 4] 21 | }, 22 | "plugins": [ 23 | "react" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Npm Modules 2 | node_modules 3 | 4 | # Build 5 | dist 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "5.7.0" 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Oleg Umarov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: npm run start-prod 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/wunderg/ptcportal-demo.svg?branch=master)](https://travis-ci.org/wunderg/ptcportal-demo.svg) 2 | 3 | # React-Redux-Express-Mongo-Starter-Kit 4 | 5 | ## Table of Contents 6 | 7 | 1. [Usage](#Usage) 8 | 2. [Development](#development) 9 | 3. [Production](#production) 10 | 4. [Test Data](#test-data) 11 | 5. [DB Schema](#db-schema) 12 | 6. [Server API](#server-api) 13 | 14 | 15 | ## Development 16 | 17 | ### Installing Dependencies 18 | 19 | From within the root directory: 20 | 21 | ```sh 22 | npm install 23 | ``` 24 | 25 | This will handle both client and server-side dependencies as outlined in [package.json](package.json). 26 | 27 | 28 | Make sure that you have created `secrets.js` file that contains secret for JWT 29 | and address for the mongoDB instance. Example below: 30 | 31 | ```sh 32 | export default { 33 | mongo: 'mongodb://localhost/myLocalDatabaseInstance', 34 | jwt: 'mysecret' 35 | }; 36 | ``` 37 | 38 | after installation has completed 39 | ```sh 40 | npm start 41 | ``` 42 | 43 | then navigate to `localhost:3001/` 44 | 45 | ## Production 46 | 47 | // TODO add production instruction 48 | 49 | ## Usage 50 | 51 | to be determnied 52 | 53 | Make sure you have [Node](https://nodejs.org/en/) installed, and then from within the root directory: 54 | 55 | Node 5 or above has to be installed 56 | 57 | ## Internal APIs 58 | On any project there are many internal APIs. For ease of reference, for both the development team and future contributers, they are exhaustively documented here. 59 | 60 | ### Test 61 | 62 | To run test: 63 | ```sh 64 | npm test 65 | ``` 66 | 67 | To run test continiously: 68 | 69 | ```sh 70 | npm test:watch 71 | ``` 72 | 73 | 74 | ### DB Schema 75 | There are two types of objects stored in the database so far: datas and users. To minimize http requests on the server, when retrieved, all references to other objects will be fully populated with complete objects, not just is numbers. The schema are as follows: 76 | 77 | ####[User](server/controllers/datas/datasController.js) 78 | ```javascript 79 | { 80 | name : ... //String 81 | } 82 | ``` 83 | 84 | ### Server API 85 | The server uses a stateless RESTful API for all database access. It supports four HTTP verbs: `GET` for retrieving data, `POST` for creating new objects, `PUT` for updating existing objects, and `DELETE` for removing objects. *NOTE: All `POST`, `PUT`, and `DELETE` routes require an authorization token, with the exception of `POST /api/signup`.* 86 | 87 | #### The Routes 88 | Most routes follow a `/api/:data_type/:data_identifier` pattern. Note that when an aspect of a route is prefaced with a colon `:` it refers to a variable. Do not actually write down a colon in any api calls. Additionally, ALL of the following routes must be prefaced with `/api`. 89 | 90 | ```javascript 91 | GET api/datas // Get list of data 92 | POST api/data // Add new data 93 | DELETE api/data/:id // Delete the data 94 | 95 | GET api/users // Get list of user 96 | POST api/users // Add new user 97 | DELETE api/users/:id // Delete the user 98 | ``` 99 | 100 | -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/favicon.ico -------------------------------------------------------------------------------- /fonts/material-design-icons/LICENSE.txt: -------------------------------------------------------------------------------- 1 | https://github.com/google/material-design-icons/blob/master/LICENSE 2 | https://github.com/FezVrasta/bootstrap-material-design/blob/master/fonts/LICENSE.txt 3 | 4 | Attribution-ShareAlike 4.0 International 5 | 6 | ======================================================================= 7 | 8 | Creative Commons Corporation ("Creative Commons") is not a law firm and 9 | does not provide legal services or legal advice. Distribution of 10 | Creative Commons public licenses does not create a lawyer-client or 11 | other relationship. Creative Commons makes its licenses and related 12 | information available on an "as-is" basis. Creative Commons gives no 13 | warranties regarding its licenses, any material licensed under their 14 | terms and conditions, or any related information. Creative Commons 15 | disclaims all liability for damages resulting from their use to the 16 | fullest extent possible. 17 | 18 | Using Creative Commons Public Licenses 19 | 20 | Creative Commons public licenses provide a standard set of terms and 21 | conditions that creators and other rights holders may use to share 22 | original works of authorship and other material subject to copyright 23 | and certain other rights specified in the public license below. The 24 | following considerations are for informational purposes only, are not 25 | exhaustive, and do not form part of our licenses. 26 | 27 | Considerations for licensors: Our public licenses are 28 | intended for use by those authorized to give the public 29 | permission to use material in ways otherwise restricted by 30 | copyright and certain other rights. Our licenses are 31 | irrevocable. Licensors should read and understand the terms 32 | and conditions of the license they choose before applying it. 33 | Licensors should also secure all rights necessary before 34 | applying our licenses so that the public can reuse the 35 | material as expected. Licensors should clearly mark any 36 | material not subject to the license. This includes other CC- 37 | licensed material, or material used under an exception or 38 | limitation to copyright. More considerations for licensors: 39 | wiki.creativecommons.org/Considerations_for_licensors 40 | 41 | Considerations for the public: By using one of our public 42 | licenses, a licensor grants the public permission to use the 43 | licensed material under specified terms and conditions. If 44 | the licensor's permission is not necessary for any reason--for 45 | example, because of any applicable exception or limitation to 46 | copyright--then that use is not regulated by the license. Our 47 | licenses grant only permissions under copyright and certain 48 | other rights that a licensor has authority to grant. Use of 49 | the licensed material may still be restricted for other 50 | reasons, including because others have copyright or other 51 | rights in the material. A licensor may make special requests, 52 | such as asking that all changes be marked or described. 53 | Although not required by our licenses, you are encouraged to 54 | respect those requests where reasonable. More_considerations 55 | for the public: 56 | wiki.creativecommons.org/Considerations_for_licensees 57 | 58 | ======================================================================= 59 | 60 | Creative Commons Attribution-ShareAlike 4.0 International Public 61 | License 62 | 63 | By exercising the Licensed Rights (defined below), You accept and agree 64 | to be bound by the terms and conditions of this Creative Commons 65 | Attribution-ShareAlike 4.0 International Public License ("Public 66 | License"). To the extent this Public License may be interpreted as a 67 | contract, You are granted the Licensed Rights in consideration of Your 68 | acceptance of these terms and conditions, and the Licensor grants You 69 | such rights in consideration of benefits the Licensor receives from 70 | making the Licensed Material available under these terms and 71 | conditions. 72 | 73 | 74 | Section 1 -- Definitions. 75 | 76 | a. Adapted Material means material subject to Copyright and Similar 77 | Rights that is derived from or based upon the Licensed Material 78 | and in which the Licensed Material is translated, altered, 79 | arranged, transformed, or otherwise modified in a manner requiring 80 | permission under the Copyright and Similar Rights held by the 81 | Licensor. For purposes of this Public License, where the Licensed 82 | Material is a musical work, performance, or sound recording, 83 | Adapted Material is always produced where the Licensed Material is 84 | synched in timed relation with a moving image. 85 | 86 | b. Adapter's License means the license You apply to Your Copyright 87 | and Similar Rights in Your contributions to Adapted Material in 88 | accordance with the terms and conditions of this Public License. 89 | 90 | c. BY-SA Compatible License means a license listed at 91 | creativecommons.org/compatiblelicenses, approved by Creative 92 | Commons as essentially the equivalent of this Public License. 93 | 94 | d. Copyright and Similar Rights means copyright and/or similar rights 95 | closely related to copyright including, without limitation, 96 | performance, broadcast, sound recording, and Sui Generis Database 97 | Rights, without regard to how the rights are labeled or 98 | categorized. For purposes of this Public License, the rights 99 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 100 | Rights. 101 | 102 | e. Effective Technological Measures means those measures that, in the 103 | absence of proper authority, may not be circumvented under laws 104 | fulfilling obligations under Article 11 of the WIPO Copyright 105 | Treaty adopted on December 20, 1996, and/or similar international 106 | agreements. 107 | 108 | f. Exceptions and Limitations means fair use, fair dealing, and/or 109 | any other exception or limitation to Copyright and Similar Rights 110 | that applies to Your use of the Licensed Material. 111 | 112 | g. License Elements means the license attributes listed in the name 113 | of a Creative Commons Public License. The License Elements of this 114 | Public License are Attribution and ShareAlike. 115 | 116 | h. Licensed Material means the artistic or literary work, database, 117 | or other material to which the Licensor applied this Public 118 | License. 119 | 120 | i. Licensed Rights means the rights granted to You subject to the 121 | terms and conditions of this Public License, which are limited to 122 | all Copyright and Similar Rights that apply to Your use of the 123 | Licensed Material and that the Licensor has authority to license. 124 | 125 | j. Licensor means the individual(s) or entity(ies) granting rights 126 | under this Public License. 127 | 128 | k. Share means to provide material to the public by any means or 129 | process that requires permission under the Licensed Rights, such 130 | as reproduction, public display, public performance, distribution, 131 | dissemination, communication, or importation, and to make material 132 | available to the public including in ways that members of the 133 | public may access the material from a place and at a time 134 | individually chosen by them. 135 | 136 | l. Sui Generis Database Rights means rights other than copyright 137 | resulting from Directive 96/9/EC of the European Parliament and of 138 | the Council of 11 March 1996 on the legal protection of databases, 139 | as amended and/or succeeded, as well as other essentially 140 | equivalent rights anywhere in the world. 141 | 142 | m. You means the individual or entity exercising the Licensed Rights 143 | under this Public License. Your has a corresponding meaning. 144 | 145 | 146 | Section 2 -- Scope. 147 | 148 | a. License grant. 149 | 150 | 1. Subject to the terms and conditions of this Public License, 151 | the Licensor hereby grants You a worldwide, royalty-free, 152 | non-sublicensable, non-exclusive, irrevocable license to 153 | exercise the Licensed Rights in the Licensed Material to: 154 | 155 | a. reproduce and Share the Licensed Material, in whole or 156 | in part; and 157 | 158 | b. produce, reproduce, and Share Adapted Material. 159 | 160 | 2. Exceptions and Limitations. For the avoidance of doubt, where 161 | Exceptions and Limitations apply to Your use, this Public 162 | License does not apply, and You do not need to comply with 163 | its terms and conditions. 164 | 165 | 3. Term. The term of this Public License is specified in Section 166 | 6(a). 167 | 168 | 4. Media and formats; technical modifications allowed. The 169 | Licensor authorizes You to exercise the Licensed Rights in 170 | all media and formats whether now known or hereafter created, 171 | and to make technical modifications necessary to do so. The 172 | Licensor waives and/or agrees not to assert any right or 173 | authority to forbid You from making technical modifications 174 | necessary to exercise the Licensed Rights, including 175 | technical modifications necessary to circumvent Effective 176 | Technological Measures. For purposes of this Public License, 177 | simply making modifications authorized by this Section 2(a) 178 | (4) never produces Adapted Material. 179 | 180 | 5. Downstream recipients. 181 | 182 | a. Offer from the Licensor -- Licensed Material. Every 183 | recipient of the Licensed Material automatically 184 | receives an offer from the Licensor to exercise the 185 | Licensed Rights under the terms and conditions of this 186 | Public License. 187 | 188 | b. Additional offer from the Licensor -- Adapted Material. 189 | Every recipient of Adapted Material from You 190 | automatically receives an offer from the Licensor to 191 | exercise the Licensed Rights in the Adapted Material 192 | under the conditions of the Adapter's License You apply. 193 | 194 | c. No downstream restrictions. You may not offer or impose 195 | any additional or different terms or conditions on, or 196 | apply any Effective Technological Measures to, the 197 | Licensed Material if doing so restricts exercise of the 198 | Licensed Rights by any recipient of the Licensed 199 | Material. 200 | 201 | 6. No endorsement. Nothing in this Public License constitutes or 202 | may be construed as permission to assert or imply that You 203 | are, or that Your use of the Licensed Material is, connected 204 | with, or sponsored, endorsed, or granted official status by, 205 | the Licensor or others designated to receive attribution as 206 | provided in Section 3(a)(1)(A)(i). 207 | 208 | b. Other rights. 209 | 210 | 1. Moral rights, such as the right of integrity, are not 211 | licensed under this Public License, nor are publicity, 212 | privacy, and/or other similar personality rights; however, to 213 | the extent possible, the Licensor waives and/or agrees not to 214 | assert any such rights held by the Licensor to the limited 215 | extent necessary to allow You to exercise the Licensed 216 | Rights, but not otherwise. 217 | 218 | 2. Patent and trademark rights are not licensed under this 219 | Public License. 220 | 221 | 3. To the extent possible, the Licensor waives any right to 222 | collect royalties from You for the exercise of the Licensed 223 | Rights, whether directly or through a collecting society 224 | under any voluntary or waivable statutory or compulsory 225 | licensing scheme. In all other cases the Licensor expressly 226 | reserves any right to collect such royalties. 227 | 228 | 229 | Section 3 -- License Conditions. 230 | 231 | Your exercise of the Licensed Rights is expressly made subject to the 232 | following conditions. 233 | 234 | a. Attribution. 235 | 236 | 1. If You Share the Licensed Material (including in modified 237 | form), You must: 238 | 239 | a. retain the following if it is supplied by the Licensor 240 | with the Licensed Material: 241 | 242 | i. identification of the creator(s) of the Licensed 243 | Material and any others designated to receive 244 | attribution, in any reasonable manner requested by 245 | the Licensor (including by pseudonym if 246 | designated); 247 | 248 | ii. a copyright notice; 249 | 250 | iii. a notice that refers to this Public License; 251 | 252 | iv. a notice that refers to the disclaimer of 253 | warranties; 254 | 255 | v. a URI or hyperlink to the Licensed Material to the 256 | extent reasonably practicable; 257 | 258 | b. indicate if You modified the Licensed Material and 259 | retain an indication of any previous modifications; and 260 | 261 | c. indicate the Licensed Material is licensed under this 262 | Public License, and include the text of, or the URI or 263 | hyperlink to, this Public License. 264 | 265 | 2. You may satisfy the conditions in Section 3(a)(1) in any 266 | reasonable manner based on the medium, means, and context in 267 | which You Share the Licensed Material. For example, it may be 268 | reasonable to satisfy the conditions by providing a URI or 269 | hyperlink to a resource that includes the required 270 | information. 271 | 272 | 3. If requested by the Licensor, You must remove any of the 273 | information required by Section 3(a)(1)(A) to the extent 274 | reasonably practicable. 275 | 276 | b. ShareAlike. 277 | 278 | In addition to the conditions in Section 3(a), if You Share 279 | Adapted Material You produce, the following conditions also apply. 280 | 281 | 1. The Adapter's License You apply must be a Creative Commons 282 | license with the same License Elements, this version or 283 | later, or a BY-SA Compatible License. 284 | 285 | 2. You must include the text of, or the URI or hyperlink to, the 286 | Adapter's License You apply. You may satisfy this condition 287 | in any reasonable manner based on the medium, means, and 288 | context in which You Share Adapted Material. 289 | 290 | 3. You may not offer or impose any additional or different terms 291 | or conditions on, or apply any Effective Technological 292 | Measures to, Adapted Material that restrict exercise of the 293 | rights granted under the Adapter's License You apply. 294 | 295 | 296 | Section 4 -- Sui Generis Database Rights. 297 | 298 | Where the Licensed Rights include Sui Generis Database Rights that 299 | apply to Your use of the Licensed Material: 300 | 301 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 302 | to extract, reuse, reproduce, and Share all or a substantial 303 | portion of the contents of the database; 304 | 305 | b. if You include all or a substantial portion of the database 306 | contents in a database in which You have Sui Generis Database 307 | Rights, then the database in which You have Sui Generis Database 308 | Rights (but not its individual contents) is Adapted Material, 309 | 310 | including for purposes of Section 3(b); and 311 | c. You must comply with the conditions in Section 3(a) if You Share 312 | all or a substantial portion of the contents of the database. 313 | 314 | For the avoidance of doubt, this Section 4 supplements and does not 315 | replace Your obligations under this Public License where the Licensed 316 | Rights include other Copyright and Similar Rights. 317 | 318 | 319 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 320 | 321 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 322 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 323 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 324 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 325 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 326 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 327 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 328 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 329 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 330 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 331 | 332 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 333 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 334 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 335 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 336 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 337 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 338 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 339 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 340 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 341 | 342 | c. The disclaimer of warranties and limitation of liability provided 343 | above shall be interpreted in a manner that, to the extent 344 | possible, most closely approximates an absolute disclaimer and 345 | waiver of all liability. 346 | 347 | 348 | Section 6 -- Term and Termination. 349 | 350 | a. This Public License applies for the term of the Copyright and 351 | Similar Rights licensed here. However, if You fail to comply with 352 | this Public License, then Your rights under this Public License 353 | terminate automatically. 354 | 355 | b. Where Your right to use the Licensed Material has terminated under 356 | Section 6(a), it reinstates: 357 | 358 | 1. automatically as of the date the violation is cured, provided 359 | it is cured within 30 days of Your discovery of the 360 | violation; or 361 | 362 | 2. upon express reinstatement by the Licensor. 363 | 364 | For the avoidance of doubt, this Section 6(b) does not affect any 365 | right the Licensor may have to seek remedies for Your violations 366 | of this Public License. 367 | 368 | c. For the avoidance of doubt, the Licensor may also offer the 369 | Licensed Material under separate terms or conditions or stop 370 | distributing the Licensed Material at any time; however, doing so 371 | will not terminate this Public License. 372 | 373 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 374 | License. 375 | 376 | 377 | Section 7 -- Other Terms and Conditions. 378 | 379 | a. The Licensor shall not be bound by any additional or different 380 | terms or conditions communicated by You unless expressly agreed. 381 | 382 | b. Any arrangements, understandings, or agreements regarding the 383 | Licensed Material not stated herein are separate from and 384 | independent of the terms and conditions of this Public License. 385 | 386 | 387 | Section 8 -- Interpretation. 388 | 389 | a. For the avoidance of doubt, this Public License does not, and 390 | shall not be interpreted to, reduce, limit, restrict, or impose 391 | conditions on any use of the Licensed Material that could lawfully 392 | be made without permission under this Public License. 393 | 394 | b. To the extent possible, if any provision of this Public License is 395 | deemed unenforceable, it shall be automatically reformed to the 396 | minimum extent necessary to make it enforceable. If the provision 397 | cannot be reformed, it shall be severed from this Public License 398 | without affecting the enforceability of the remaining terms and 399 | conditions. 400 | 401 | c. No term or condition of this Public License will be waived and no 402 | failure to comply consented to unless expressly agreed to by the 403 | Licensor. 404 | 405 | d. Nothing in this Public License constitutes or may be interpreted 406 | as a limitation upon, or waiver of, any privileges and immunities 407 | that apply to the Licensor or You, including from the legal 408 | processes of any jurisdiction or authority. 409 | 410 | 411 | ======================================================================= 412 | 413 | Creative Commons is not a party to its public licenses. 414 | Notwithstanding, Creative Commons may elect to apply one of its public 415 | licenses to material it publishes and in those instances will be 416 | considered the "Licensor." Except for the limited purpose of indicating 417 | that material is shared under a Creative Commons public license or as 418 | otherwise permitted by the Creative Commons policies published at 419 | creativecommons.org/policies, Creative Commons does not authorize the 420 | use of the trademark "Creative Commons" or any other trademark or logo 421 | of Creative Commons without its prior written consent including, 422 | without limitation, in connection with any unauthorized modifications 423 | to any of its public licenses or any other arrangements, 424 | understandings, or agreements concerning use of licensed material. For 425 | the avoidance of doubt, this paragraph does not form part of the public 426 | licenses. 427 | 428 | Creative Commons may be contacted at creativecommons.org. 429 | -------------------------------------------------------------------------------- /fonts/material-design-icons/Material-Design-Icons.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/material-design-icons/Material-Design-Icons.eot -------------------------------------------------------------------------------- /fonts/material-design-icons/Material-Design-Icons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/material-design-icons/Material-Design-Icons.ttf -------------------------------------------------------------------------------- /fonts/material-design-icons/Material-Design-Icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/material-design-icons/Material-Design-Icons.woff -------------------------------------------------------------------------------- /fonts/material-design-icons/Material-Design-Icons.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/material-design-icons/Material-Design-Icons.woff2 -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Bold.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Bold.eot -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Bold.ttf -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Bold.woff -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Bold.woff2 -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Light.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Light.eot -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Light.ttf -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Light.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Light.woff -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Light.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Light.woff2 -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Medium.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Medium.eot -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Medium.ttf -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Medium.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Medium.woff -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Medium.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Medium.woff2 -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Regular.eot -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Regular.ttf -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Regular.woff -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Regular.woff2 -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Thin.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Thin.eot -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Thin.ttf -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Thin.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Thin.woff -------------------------------------------------------------------------------- /fonts/roboto/Roboto-Thin.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/fonts/roboto/Roboto-Thin.woff2 -------------------------------------------------------------------------------- /global.scss: -------------------------------------------------------------------------------- 1 | /*** Basic Page Setup ***/ 2 | html { 3 | overflow-y: scroll; 4 | } 5 | 6 | body { 7 | margin: 0; 8 | padding: 0; 9 | background-color: #fafafa 10 | } 11 | .container { 12 | padding-top: 4rem; 13 | margin-top: 1rem; 14 | width: 95% !important; 15 | } 16 | 17 | .add-student-form { 18 | margin-top: 1.5rem; 19 | } 20 | 21 | @import './node_modules/materialize-css/sass/components/_color.scss'; 22 | 23 | /*** Colors ***/ 24 | $primary-color: color("blue", "darken-2") !default; 25 | $primary-color-light: lighten($primary-color, 15%) !default; 26 | $primary-color-dark: darken($primary-color, 15%) !default; 27 | 28 | $secondary-color: color("deep-purple", "lighten-2") !default; 29 | $success-color: color("green", "base") !default; 30 | $error-color: color("red", "base") !default; 31 | $link-color: color("light-blue", "darken-1") !default; 32 | 33 | /*** Badges ***/ 34 | $badge-bg-color: $secondary-color !default; 35 | 36 | /*** Buttons ***/ 37 | $button-bg-color-disabled: #DFDFDF !default; 38 | $button-color: $secondary-color !default; 39 | $button-color-disabled: #9F9F9F !default; 40 | $button-color-flat: #343434 !default; 41 | $button-color-raised: #fff !default; 42 | $button-floating-size: 37px !default; 43 | $button-height: 36px !default; 44 | $button-font-size-shared: 1.3rem !default; 45 | $button-large-icon-font-size: 1.6rem !default; 46 | $button-line-height: 36px !default; 47 | 48 | /*** Cards ***/ 49 | $card-padding: 20px !default; 50 | $card-bg-color: #fff !default; 51 | $card-link-color: color("orange", "accent-2") !default; 52 | $card-link-color-light: lighten($card-link-color, 20%) !default; 53 | 54 | /*** Collapsible ***/ 55 | $collapsible-height: 3rem !default; 56 | $collapsible-header-color: #fff !default; 57 | $collapsible-border-color: #ddd !default; 58 | 59 | /*** Chips ***/ 60 | $chip-bg-color: #e4e4e4 !default; 61 | 62 | /*** Date Picker ***/ 63 | $datepicker-weekday-bg: darken($secondary_color, 7%) !default; 64 | $datepicker-date-bg: $secondary_color !default; 65 | $datepicker-year: rgba(255, 255, 255, .4) !default; 66 | $datepicker-focus: rgba(0,0,0, .05) !default; 67 | $datepicker-selected: $secondary-color !default; 68 | $datepicker-selected-outfocus: desaturate(lighten($secondary-color, 35%), 15%) !default; 69 | 70 | /*** Dropdown ***/ 71 | $dropdown-bg-color: #fff !default; 72 | $dropdown-hover-bg-color: #eee !default; 73 | $dropdown-color: $secondary-color !default; 74 | $dropdown-item-height: 50px !default; 75 | 76 | /*** Fonts ***/ 77 | $roboto-font-path: "./fonts/roboto/" !default; 78 | $icons-font-path: "./fonts/material-design-icons/" !default; 79 | 80 | /*** Forms ***/ 81 | // Text Inputs + Textarea 82 | $input-border-color: color("grey", "base") !default; 83 | $input-bg-color: #fff !default; 84 | $input-error-color: $error-color !default; 85 | $input-success-color: $success-color !default; 86 | $input-focus-color: $secondary-color !default; 87 | $label-font-size: .8rem !default; 88 | $input-disabled-color: rgba(0,0,0, .26) !default; 89 | $input-disabled-solid-color: #BDBDBD !default; 90 | 91 | // Radio Buttons 92 | $radio-fill-color: $secondary-color !default; 93 | $radio-empty-color: #5a5a5a !default; 94 | 95 | // Switches 96 | $switch-bg-color: $secondary-color !default; 97 | $switch-checked-lever-bg: desaturate(lighten($secondary-color, 25%), 25%) !default; 98 | $switch-unchecked-bg: #F1F1F1 !default; 99 | $switch-unchecked-lever-bg: #818181 !default; 100 | 101 | 102 | /*** Global ***/ 103 | // Media Query Ranges 104 | $small-screen-up: 601px !default; 105 | $medium-screen-up: 993px !default; 106 | $large-screen-up: 1201px !default; 107 | $small-screen: 600px !default; 108 | $medium-screen: 992px !default; 109 | $large-screen: 1200px !default; 110 | 111 | $medium-and-up: "only screen and (min-width : #{$small-screen-up})" !default; 112 | $large-and-up: "only screen and (min-width : #{$medium-screen-up})" !default; 113 | $small-and-down: "only screen and (max-width : #{$small-screen})" !default; 114 | $medium-and-down: "only screen and (max-width : #{$medium-screen})" !default; 115 | $medium-only: "only screen and (min-width : #{$small-screen-up}) and (max-width : #{$medium-screen})" !default; 116 | 117 | // Grid Variables 118 | $num-cols: 12 !default; 119 | $gutter-width: 1.5rem !default; 120 | $element-top-margin: $gutter-width/3 !default; 121 | $element-bottom-margin: ($gutter-width*2)/3 !default; 122 | 123 | /*** Navbar ***/ 124 | $navbar-height: 64px !default; 125 | $navbar-height-mobile: 56px !default; 126 | $navbar-font-color: #fff !default; 127 | $navbar-brand-font-size: 2.1rem !default; 128 | 129 | /*** SideNav ***/ 130 | $sidenav-bg-color: #fff !default; 131 | $sidenav-padding-right: 15px !default; 132 | $sidenav-item-height: 64px !default; 133 | 134 | /*** Photo Slider ***/ 135 | $slider-bg-color: color('grey', 'base') !default; 136 | $slider-bg-color-light: color('grey', 'lighten-2') !default; 137 | $slider-indicator-color: color('green', 'base') !default; 138 | 139 | /*** Spinners | Loaders ***/ 140 | $spinner-default-color: $secondary-color !default; 141 | 142 | /*** Tabs ***/ 143 | $tabs-underline-color: $primary-color-light !default; 144 | $tabs-text-color: $primary-color !default; 145 | $tabs-bg-color: #fff !default; 146 | 147 | /*** Tables ***/ 148 | $table-border-color: #d0d0d0 !default; 149 | $table-striped-color: #f2f2f2 !default; 150 | 151 | /*** Toasts ***/ 152 | $toast-height: 48px !default; 153 | $toast-color: #323232 !default; 154 | $toast-text-color: #fff !default; 155 | 156 | /*** Typography ***/ 157 | $off-black: rgba(0, 0, 0, 0.87) !default; 158 | // Header Styles 159 | $h1-fontsize: 4.2rem !default; 160 | $h2-fontsize: 3.56rem !default; 161 | $h3-fontsize: 2.92rem !default; 162 | $h4-fontsize: 2.28rem !default; 163 | $h5-fontsize: 1.64rem !default; 164 | $h6-fontsize: 1rem !default; 165 | 166 | // Footer 167 | $footer-bg-color: $primary-color !default; 168 | 169 | // Flowtext 170 | $range : $large-screen - $small-screen !default; 171 | $intervals: 20 !default; 172 | $interval-size: $range / $intervals !default; 173 | 174 | /*** Collections ***/ 175 | $collection-border-color: #e0e0e0 !default; 176 | $collection-bg-color: #fff !default; 177 | $collection-active-bg-color: $secondary-color !default; 178 | $collection-active-color: lighten($secondary-color, 55%) !default; 179 | $collection-hover-bg-color: #ddd !default; 180 | $collection-link-color: $secondary-color !default; 181 | 182 | /* Progress Bar */ 183 | $progress-bar-color: $secondary-color !default; 184 | 185 | @import './node_modules/materialize-css/sass/materialize.scss'; 186 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PTC PORTAL 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "React-Redux-Express-Mongo-Starter", 3 | "version": "1.0.0", 4 | "description": "My awesome starter kit", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "NODE_ENV=development babel-node ./server/server.js", 8 | "start-prod": "node ./dist/server.js", 9 | "build-client": "NODE_ENV=production webpack --config ./webpack.production.config.js --profile", 10 | "build-server": "babel -d ./dist ./server -s", 11 | "lint": "eslint src; exit 0", 12 | "clean": "rimraf dist", 13 | "test": "mocha --compilers js:babel-core/register --require ignore-styles --require ./test/test_helper.js --recursive ./test", 14 | "test:watch": "npm run test -- --watch", 15 | "heroku-postbuild": "npm run clean && npm run build-client && npm run build-server" 16 | }, 17 | "engines": { 18 | "node": "5.11.0", 19 | "npm": "3.8.6" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "git+https://github.com/wunderg/react-redux-starter.git" 24 | }, 25 | "author": "Oleg Umarov", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/wunderg/react-redux-express-mongo-starter" 29 | }, 30 | "homepage": "https://github.com/wunderg/react-redux-express-mongo-starter#readme", 31 | "dependencies": { 32 | "autoprefixer": "^6.3.6", 33 | "axios": "^0.9.1", 34 | "babel-cli": "^6.5.1", 35 | "babel-core": "^6.5.1", 36 | "babel-loader": "^6.2.2", 37 | "babel-plugin-add-module-exports": "^0.1.2", 38 | "babel-plugin-transform-runtime": "^6.5.0", 39 | "babel-polyfill": "^6.5.0", 40 | "babel-preset-es2015": "^6.5.0", 41 | "babel-preset-react": "^6.5.0", 42 | "babel-preset-react-hmre": "^1.1.0", 43 | "babel-preset-stage-0": "^6.5.0", 44 | "babel-register": "^6.5.1", 45 | "babel-runtime": "^6.3.19", 46 | "bcrypt-nodejs": "0.0.3", 47 | "body-parser": "^1.14.1", 48 | "classnames": "^2.2.3", 49 | "css-loader": "^0.23.1", 50 | "express": "^4.13.3", 51 | "file-loader": "^0.8.5", 52 | "font-awesome": "^4.5.0", 53 | "history": "^2.0.0", 54 | "jwt-simple": "^0.5.0", 55 | "material-ui": "^0.14.4", 56 | "materialize-css": "^0.97.5", 57 | "mongoose": "^4.4.5", 58 | "node-sass": "^3.6.0", 59 | "passport": "^0.3.2", 60 | "passport-jwt": "^2.0.0", 61 | "passport-local": "^1.0.0", 62 | "postcss-loader": "^0.8.2", 63 | "precss": "^1.4.0", 64 | "progress-bar-webpack-plugin": "^1.4.1", 65 | "raw-loader": "^0.5.1", 66 | "react": "^0.14.8", 67 | "react-addons-css-transition-group": "^0.14.7", 68 | "react-dom": "^0.14.8", 69 | "react-materialize": "^0.14.3", 70 | "react-redux": "^4.4.0", 71 | "react-router": "^2.0.0", 72 | "react-star-rating": "^1.4.2", 73 | "react-syntax-highlighter": "^1.3.0", 74 | "react-tap-event-plugin": "^0.2.2", 75 | "redux": "^3.5.1", 76 | "redux-form": "^5.1.3", 77 | "redux-logger": "^2.5.2", 78 | "redux-promise": "^0.5.1", 79 | "redux-thunk": "^1.0.3", 80 | "rimraf": "^2.4.3", 81 | "sass-loader": "^3.1.2", 82 | "stats-webpack-plugin": "^0.3.0", 83 | "style-loader": "^0.13.0", 84 | "url-loader": "^0.5.7", 85 | "webpack": "^1.12.9", 86 | "webpack-dev-server": "^1.14.1" 87 | }, 88 | "devDependencies": { 89 | "babel-eslint": "^5.0.0-beta10", 90 | "chai": "^3.5.0", 91 | "chai-jquery": "^2.0.0", 92 | "enzyme": "^2.2.0", 93 | "eslint": "^1.10.3", 94 | "eslint-config-airbnb": "5.0.0", 95 | "eslint-plugin-react": "^3.16.1", 96 | "eslint_d": "^3.1.0", 97 | "ignore-styles": "^1.2.0", 98 | "jquery": "^2.2.3", 99 | "jsdom": "^8.4.0", 100 | "mocha": "^2.4.5", 101 | "react-addons-test-utils": "^15.0.1", 102 | "react-hot-loader": "^1.3.0", 103 | "sinon": "^1.17.4", 104 | "webpack": "^1.12.14" 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /server/controllers/data/dataController.js: -------------------------------------------------------------------------------- 1 | import Data from '../../models/dataModel.js'; 2 | 3 | export default { 4 | get(req, res) { 5 | Data 6 | .find({}) 7 | .exec() 8 | .then(data => res.json(data)) 9 | .catch(err => res.json(err)); 10 | }, 11 | 12 | post(req, res) { 13 | const { name } = req.body; 14 | 15 | new Data({ 16 | name 17 | }) 18 | .save() 19 | .then(result => res.json(result)) 20 | .catch(err => res.json(err)); 21 | }, 22 | 23 | put(req, res) { 24 | const { _id } = req.body; 25 | 26 | Data.findByIdAndUpdate(_id, req.body) 27 | .then(result => res.json(result)) 28 | .catch(err => res.json(err)); 29 | }, 30 | 31 | delete(req, res) { 32 | Data 33 | .findById(req.params.id) 34 | .then(result => { 35 | result.remove(); 36 | res.json({ removed: true }); 37 | }) 38 | .catch(err => res.json(err)); 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /server/controllers/user/userController.js: -------------------------------------------------------------------------------- 1 | import User from '../../models/userModel.js'; 2 | import jwt from 'jwt-simple'; 3 | 4 | const token = (user) => { 5 | const secret = process.env.SECRET || require('../../../secrets.js').jwt; 6 | const timestamp = new Date().getTime(); 7 | return jwt.encode({ sub: user.email, iat: timestamp }, secret); 8 | }; 9 | 10 | export default { 11 | 12 | getNames(req, res) { 13 | User.find({}, 'name') 14 | .then(student => res.json(student)) 15 | .catch(err => res.json(err)); 16 | }, 17 | 18 | tokenLogin(req, res) { 19 | return res.json({ name: req.user.email }); 20 | }, 21 | 22 | signin(req, res) { 23 | const email = req.body.email; 24 | const password = req.body.pass; 25 | 26 | if (!email || !password) { 27 | return res.status(422).send({ error: 'Must provide email and password' }); 28 | } 29 | 30 | res.json({ id_token: token(req.body) }); 31 | }, 32 | 33 | signup(req, res, next) { 34 | const email = req.body.email; 35 | const password = req.body.pass; 36 | const name = req.body.name; 37 | 38 | if (!email || !password) { 39 | return res.status(422).send({ error: 'Must provide email and password' }); 40 | } 41 | 42 | User.findOne({ email }, (err, user) => { 43 | if (err) { 44 | return next(err); 45 | } 46 | 47 | if (user) { 48 | return res.status(422).send({ error: 'User already exist' }); 49 | } 50 | 51 | 52 | var newUser = new User({ 53 | email, 54 | password, 55 | name 56 | }); 57 | 58 | newUser.save(err2 => { 59 | if (err2) { 60 | next(err); 61 | } 62 | 63 | res.json({ id_token: token(req.body) }); 64 | }); 65 | }); 66 | } 67 | }; 68 | -------------------------------------------------------------------------------- /server/models/dataModel.js: -------------------------------------------------------------------------------- 1 | import mongoose from 'mongoose'; 2 | 3 | const dataSchema = new mongoose.Schema({ 4 | name: { 5 | type: String, 6 | required: true 7 | } 8 | }); 9 | 10 | export default mongoose.model('data', dataSchema); 11 | -------------------------------------------------------------------------------- /server/models/userModel.js: -------------------------------------------------------------------------------- 1 | import mongoose from 'mongoose'; 2 | import bcrypt from 'bcrypt-nodejs'; 3 | 4 | const userSchema = new mongoose.Schema({ 5 | email: { 6 | type: String, 7 | unique: true, 8 | lowercase: true 9 | }, 10 | 11 | password: String, 12 | 13 | name: { 14 | type: String, 15 | unique: true 16 | } 17 | }); 18 | 19 | userSchema.pre('save', function hashPassword(next) { 20 | const user = this; 21 | 22 | bcrypt.genSalt(10, (err, salt) => { 23 | if (err) { 24 | return next(err); 25 | } 26 | 27 | bcrypt.hash(user.password, salt, null, (err2, hash) => { 28 | if (err2) { 29 | return next(err); 30 | } 31 | 32 | user.password = hash; 33 | next(); 34 | }); 35 | }); 36 | }); 37 | 38 | userSchema.methods.comparePassword = function comparePass(canditatePassword, callback) { 39 | bcrypt.compare(canditatePassword, this.password, (err, isMatch) => { 40 | if (err) { 41 | return callback(err); 42 | } 43 | callback(null, isMatch); 44 | }); 45 | }; 46 | 47 | export default mongoose.model('user', userSchema); 48 | -------------------------------------------------------------------------------- /server/routes/apiRouter.js: -------------------------------------------------------------------------------- 1 | import passport from 'passport'; 2 | 3 | import DataController from '../controllers/data/dataController.js'; 4 | import UserController from '../controllers/user/userController.js'; 5 | 6 | import '../services/passport.js'; 7 | 8 | const requireAuth = passport.authenticate('jwt', { session: false }); 9 | const requireSignin = passport.authenticate('local', { session: false }); 10 | 11 | module.exports = (app, express) => { 12 | var apiRouter = new express.Router(); 13 | 14 | app.use('/api', apiRouter); 15 | 16 | apiRouter.use((req, res, next) => { 17 | console.log('API CALL'); 18 | next(); 19 | }); 20 | 21 | // apiRouter.param('id', (req, res, next, id) => { 22 | // //validate user or check some data 23 | // next(); 24 | // }); 25 | 26 | apiRouter.post('/login', requireSignin, UserController.signin); 27 | apiRouter.post('/signup', UserController.signup); 28 | apiRouter.post('/data', DataController.post); 29 | apiRouter.get('/tokenlogin', requireAuth, UserController.tokenLogin); 30 | apiRouter.get('/data', requireAuth, DataController.get); 31 | apiRouter.get('/instructors', requireAuth, UserController.getNames); 32 | apiRouter.put('/data', requireAuth, DataController.put); 33 | apiRouter.delete('/data/:id', DataController.delete); 34 | }; 35 | -------------------------------------------------------------------------------- /server/routes/appRouter.js: -------------------------------------------------------------------------------- 1 | module.exports = (app, express, staticPath) => { 2 | var appRouter = new express.Router(); 3 | 4 | app.use('/', appRouter); 5 | 6 | appRouter.get('/about', (req, res) => { 7 | res.sendFile('index.html', { 8 | root: staticPath 9 | }); 10 | }); 11 | 12 | appRouter.get('/login', (req, res) => { 13 | res.sendFile('index.html', { 14 | root: staticPath 15 | }); 16 | }); 17 | 18 | appRouter.get('/signup', (req, res) => { 19 | res.sendFile('index.html', { 20 | root: staticPath 21 | }); 22 | }); 23 | 24 | appRouter.get('/dashboard', (req, res) => { 25 | res.sendFile('index.html', { 26 | root: staticPath 27 | }); 28 | }); 29 | }; 30 | -------------------------------------------------------------------------------- /server/server.js: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import path from 'path'; 3 | import webpack from 'webpack'; 4 | import WebpackDevServer from 'webpack-dev-server'; 5 | import bodyParser from 'body-parser'; 6 | import webpackConfig from '../webpack-config.js'; 7 | 8 | import mongoose from 'mongoose'; 9 | 10 | import appRouter from './routes/appRouter'; 11 | import apiRouter from './routes/apiRouter'; 12 | 13 | const isProduction = process.env.NODE_ENV === 'production'; 14 | const isDeveloping = !isProduction; 15 | const port = isProduction ? (process.env.PORT || 80) : 3000; 16 | 17 | const app = express(); 18 | 19 | const staticPath = path.join(__dirname, '../'); 20 | 21 | const mongoDB = process.env.MONGODB_URI || require('../secrets.js').mongo; 22 | mongoose.connect(mongoDB); 23 | 24 | app.use(bodyParser.json()); 25 | app.use(bodyParser.urlencoded({ extended: false })); 26 | 27 | appRouter(app, express, staticPath); 28 | apiRouter(app, express); 29 | 30 | app.use(express.static(staticPath)); 31 | 32 | app.listen(port, err => { 33 | if (err) { 34 | console.log(err); 35 | } 36 | console.log(`Port 3000 and 3001`); 37 | }); 38 | 39 | if (isDeveloping) { 40 | const devServer = new WebpackDevServer(webpack(webpackConfig), { 41 | publicPath: webpackConfig.output.publicPath, 42 | inline: true, 43 | hot: true, 44 | quiet: true, 45 | noInfo: false, 46 | stats: { colors: true }, 47 | proxy: [ 48 | { 49 | path: '*', 50 | target: 'http://localhost:3000', 51 | ws: true, 52 | } 53 | ] 54 | }); 55 | 56 | devServer.listen(3001, 'localhost', err => { 57 | if (err) { 58 | console.log(err); 59 | } 60 | }); 61 | } 62 | -------------------------------------------------------------------------------- /server/services/passport.js: -------------------------------------------------------------------------------- 1 | import passport from 'passport'; 2 | import LocalStrategy from 'passport-local'; 3 | import { Strategy, ExtractJwt } from 'passport-jwt'; 4 | import User from '../models/userModel.js'; 5 | 6 | const localOptions = { usernameField: 'email', passwordField: 'pass' }; 7 | 8 | const localLogin = new LocalStrategy(localOptions, (email, password, done) => { 9 | console.log(email, 'EMAIL'); 10 | User.findOne({ email }, (err, user) => { 11 | if (err) { 12 | return done(err); 13 | } 14 | if (!user) { 15 | return done(null, false); 16 | } 17 | 18 | user.comparePassword(password, (err2, isMatch) => { 19 | if (err2) { 20 | return done(err2); 21 | } 22 | if (!isMatch) { 23 | return done(null, false); 24 | } 25 | 26 | return done(null, user); 27 | }); 28 | }); 29 | }); 30 | 31 | const jwtOptions = { 32 | jwtFromRequest: ExtractJwt.fromHeader('authorization'), 33 | secretOrKey: process.env.SECRET || require('../../secrets.js').jwt 34 | }; 35 | 36 | const jwtLogin = new Strategy(jwtOptions, (payload, done) => { 37 | console.log(payload.sub, 'payloadSUB'); 38 | User.findOne({ email: payload.sub }, (err, user) => { 39 | if (err) { 40 | return done(err, false); 41 | } 42 | 43 | if (user) { 44 | done(null, user); 45 | } else { 46 | done(null, false); 47 | } 48 | }); 49 | }); 50 | 51 | passport.use(jwtLogin); 52 | passport.use(localLogin); 53 | -------------------------------------------------------------------------------- /src/actions/constants.js: -------------------------------------------------------------------------------- 1 | export const LOGOUT = 'LOGOUT'; 2 | export const LOGIN_REQUEST = 'LOGIN_REQUEST'; 3 | export const LOGIN_SUCCESS = 'LOGIN_SUCCESS'; 4 | export const LOGIN_FAILURE = 'LOGIN_FAILURE'; 5 | export const SIGNUP_REQUEST = 'SIGNUP_REQUEST'; 6 | export const SIGNUP_SUCCESS = 'SIGNUP_SUCCESS'; 7 | export const SIGNUP_FAILURE = 'SIGNUP_FAILURE'; 8 | export const TOKEN_LOGIN_REQUEST = 'TOKEN_LOGIN_REQUEST'; 9 | export const TOKEN_LOGIN_SUCCESS = 'TOKEN_LOGIN_SUCCESS'; 10 | export const TOKEN_LOGIN_FAILURE = 'TOKEN_LOGIN_FAILURE'; 11 | export const FETCH_DATA = 'FETCH_DATA'; 12 | export const FETCH_DATA_REQUEST = 'FETCH_DATA_REQUEST'; 13 | export const FETCH_DATA_SUCCESS = 'FETCH_DATA_SUCCESS'; 14 | export const FETCH_DATA_FAILURE = 'FETCH_DATA_FAILURE'; 15 | -------------------------------------------------------------------------------- /src/actions/index.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | import * as ACTIONS from './constants'; 3 | 4 | export function addData(input) { 5 | const nextId = Math.floor(Math.random() * 100); 6 | const data = { 7 | _id: nextId, 8 | name: input 9 | }; 10 | 11 | axios.post(`api/data`, data) 12 | .then(res => console.log(res)) 13 | .then(err => console.log(err)); 14 | return { 15 | type: ACTIONS.ADD_DATA, 16 | payload: data 17 | }; 18 | } 19 | 20 | export function selectData(data) { 21 | return { 22 | type: ACTIONS.SELECT_DATA, 23 | payload: data 24 | }; 25 | } 26 | 27 | export function updateData(data) { 28 | const token = localStorage.getItem('id_token') || null; 29 | 30 | const config = { 31 | headers: { Authorization: token } 32 | }; 33 | 34 | axios.put(`api/data`, data, config); 35 | return { 36 | type: ACTIONS.UPDATE_DATA, 37 | payload: data 38 | }; 39 | } 40 | 41 | function requestFetchData() { 42 | return { 43 | type: ACTIONS.FETCH_DATA_REQUEST, 44 | }; 45 | } 46 | 47 | function fetchDataSuccess(data) { 48 | return { 49 | type: ACTIONS.FETCH_DATA_SUCCESS, 50 | data 51 | }; 52 | } 53 | 54 | function fetchDataFail(message) { 55 | return { 56 | type: ACTIONS.FETCH_DATA_FAILURE, 57 | message 58 | }; 59 | } 60 | 61 | export function fetchData() { 62 | const token = localStorage.getItem('id_token') || null; 63 | 64 | const config = { 65 | headers: { Authorization: token } 66 | }; 67 | 68 | return dispatch => { 69 | dispatch(requestFetchData()); 70 | return axios.get(`api/data`, config) 71 | .then(res => dispatch(fetchDataSuccess(res))) 72 | .catch(err => dispatch(fetchDataFail(err))); 73 | }; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /src/actions/login.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | import * as ACTIONS from './constants'; 3 | 4 | function saveToLocalStorage(token) { 5 | localStorage.setItem('id_token', token); 6 | } 7 | 8 | function requestSignup(creds) { 9 | return { 10 | type: ACTIONS.SIGNUP_REQUEST, 11 | isFetching: true, 12 | isAuthenticated: false, 13 | creds 14 | }; 15 | } 16 | 17 | function recieveSignup(user) { 18 | saveToLocalStorage(user.data.id_token); 19 | return { 20 | type: ACTIONS.SIGNUP_SUCCESS, 21 | isFetching: false, 22 | isAuthenticated: true, 23 | id_token: user.data.id_token 24 | }; 25 | } 26 | 27 | function signupError(message) { 28 | return { 29 | type: ACTIONS.SIGNUP_FAILURE, 30 | isFetching: false, 31 | isAuthenticated: false, 32 | message 33 | }; 34 | } 35 | 36 | export function signupUser(creds) { 37 | return dispatch => { 38 | dispatch(requestSignup(creds)); 39 | return axios.post('api/signup', creds) 40 | .then(res => dispatch(recieveSignup(res))) 41 | .catch(err => dispatch(signupError(err))); 42 | }; 43 | } 44 | 45 | function requestLogin(creds) { 46 | return { 47 | type: ACTIONS.LOGIN_REQUEST, 48 | isFetching: true, 49 | isAuthenticated: false, 50 | creds 51 | }; 52 | } 53 | 54 | function recieveLogin(user) { 55 | if (user.data && user.data.id_token) { 56 | saveToLocalStorage(user.data.id_token); 57 | } 58 | return { 59 | type: ACTIONS.LOGIN_SUCCESS, 60 | isFetching: false, 61 | isAuthenticated: true, 62 | name: user 63 | }; 64 | } 65 | 66 | function loginError(message) { 67 | return { 68 | type: ACTIONS.LOGIN_FAILURE, 69 | isFetching: false, 70 | isAuthenticated: false, 71 | message 72 | }; 73 | } 74 | 75 | export function loginUser(creds) { 76 | return dispatch => { 77 | dispatch(requestLogin(creds)); 78 | return axios.post('api/login', creds) 79 | .then(res => dispatch(recieveLogin(res))) 80 | .catch(err => dispatch(loginError(err))); 81 | }; 82 | } 83 | 84 | 85 | function requestLoginWithToken() { 86 | return { 87 | type: ACTIONS.TOKEN_LOGIN_REQUEST, 88 | isFetching: true, 89 | isAuthenticated: false, 90 | }; 91 | } 92 | 93 | function recieveTokenLogin(user) { 94 | return { 95 | type: ACTIONS.TOKEN_LOGIN_SUCCESS, 96 | isFetching: false, 97 | isAuthenticated: true, 98 | name: user 99 | }; 100 | } 101 | 102 | function tokenLoginError(message) { 103 | return { 104 | type: ACTIONS.TOKEN_LOGIN_FAILURE, 105 | isFetching: false, 106 | isAuthenticated: false, 107 | message 108 | }; 109 | } 110 | 111 | export function logout() { 112 | localStorage.removeItem('id_token', null); 113 | return { 114 | type: ACTIONS.LOGOUT 115 | }; 116 | } 117 | 118 | export function loginWithToken(token) { 119 | const config = { 120 | headers: { Authorization: token } 121 | }; 122 | return dispatch => { 123 | dispatch(requestLoginWithToken()); 124 | return axios.get('api/tokenlogin', config) 125 | .then(res => dispatch(recieveTokenLogin(res))) 126 | .catch(err => dispatch(tokenLoginError(err))); 127 | }; 128 | } 129 | -------------------------------------------------------------------------------- /src/containers/about/index.js: -------------------------------------------------------------------------------- 1 | import React, {Component, PropTypes} from 'react'; 2 | 3 | 4 | const About = (props) => ( 5 |
6 | about 7 |
8 | ); 9 | 10 | export default About; 11 | -------------------------------------------------------------------------------- /src/containers/app/index.js: -------------------------------------------------------------------------------- 1 | import React, { Component, PropTypes } from 'react'; 2 | import { connect } from 'react-redux'; 3 | import Navbar from '../navbar'; 4 | import Spinner from '../../helpers/spinner.js'; 5 | import '../../../global.scss'; 6 | 7 | import { loginWithToken, logout } from '../../actions/login.js'; 8 | 9 | export class App extends Component { 10 | constructor(props) { 11 | super(props); 12 | } 13 | 14 | componentWillMount() { 15 | const token = window.localStorage.getItem('id_token'); 16 | if (!this.props.user.isAuthenticated && token) { 17 | this.props.loginWithToken(token); 18 | } 19 | } 20 | 21 | render() { 22 | if (this.props.user.isFetching) { 23 | return ; 24 | } 25 | 26 | return ( 27 |
28 |
29 | 30 |
31 | { this.props.children } 32 |
33 |
34 |
35 | ); 36 | } 37 | } 38 | 39 | App.propTypes = { 40 | children: PropTypes.object, 41 | logout: PropTypes.func, 42 | user: PropTypes.object, 43 | loginWithToken: PropTypes.func 44 | }; 45 | 46 | function mapStateToProps(state) { 47 | return { 48 | data: state.slocal, 49 | user: state.user 50 | }; 51 | } 52 | 53 | 54 | export default connect(mapStateToProps, { loginWithToken, logout })(App); 55 | -------------------------------------------------------------------------------- /src/containers/dashboard/index.js: -------------------------------------------------------------------------------- 1 | import React, { Component, PropTypes } from 'react'; 2 | import { connect } from 'react-redux'; 3 | import { bindActionCreators } from 'redux'; 4 | import { fetchData, updateData } from '../../actions'; 5 | 6 | import Spinner from '../../helpers/spinner.js'; 7 | 8 | class Dashboard extends Component { 9 | constructor(props) { 10 | super(props); 11 | } 12 | 13 | componentWillMount() { 14 | if (this.props.user.isAuthenticated) { 15 | this.props.fetchData(); 16 | } 17 | } 18 | 19 | 20 | render() { 21 | if (this.props.data.isFetching) { 22 | return ; 23 | } 24 | return ( 25 |
26 |
27 | Hello world 28 |
29 |
30 | ); 31 | } 32 | } 33 | 34 | Dashboard.contextTypes = { 35 | router: PropTypes.object 36 | }; 37 | 38 | function mapStateToProps(state) { 39 | return { 40 | data: state.main, 41 | user: state.user 42 | }; 43 | } 44 | 45 | function mapDispatchToProps(dispatch) { 46 | return bindActionCreators({ fetchData, updateData }, dispatch); 47 | } 48 | 49 | Dashboard.propTypes = { 50 | user: PropTypes.object, 51 | data: PropTypes.object, 52 | fetchData: PropTypes.func, 53 | updateData: PropTypes.func 54 | }; 55 | 56 | export default connect(mapStateToProps, mapDispatchToProps)(Dashboard); 57 | -------------------------------------------------------------------------------- /src/containers/login/require_auth.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { connect } from 'react-redux'; 3 | 4 | 5 | export default function(ComponentToCompose) { 6 | class Authentication extends Component { 7 | static contextTypes = { 8 | router: React.PropTypes.object 9 | } 10 | 11 | componentWillMount() { 12 | if (!this.props.authenticated) { 13 | this.context.router.push('/'); 14 | } 15 | } 16 | 17 | componentWillReceiveProps(nextProps) { 18 | if (!nextProps.authenticated) { 19 | this.context.router.push('/'); 20 | } 21 | } 22 | 23 | render() { 24 | return ( 25 | 26 | ); 27 | } 28 | } 29 | 30 | function mapStateToProps(state) { 31 | return { authenticated: state.user.isAuthenticated } 32 | } 33 | 34 | return connect(mapStateToProps)(Authentication); 35 | } 36 | -------------------------------------------------------------------------------- /src/containers/login/signin.js: -------------------------------------------------------------------------------- 1 | import React, { Component, PropTypes } from 'react'; 2 | import { reduxForm } from 'redux-form'; 3 | import { loginUser } from '../../actions/login.js'; 4 | import './style.scss'; 5 | 6 | class Login extends Component { 7 | constructor(props) { 8 | super(props); 9 | this.onSubmit = this.onSubmit.bind(this); 10 | } 11 | 12 | componentWillMount() { 13 | if (this.props.user.isAuthenticated) { 14 | this.context.router.push('/dashboard'); 15 | } 16 | } 17 | 18 | componentWillReceiveProps(props) { 19 | if (props.user.isAuthenticated) { 20 | this.context.router.push('/dashboard'); 21 | } 22 | } 23 | 24 | onSubmit(e) { 25 | e.preventDefault(); 26 | const creds = { 27 | email: this.props.data.email.value || null, 28 | pass: this.props.data.pass.value || null 29 | 30 | }; 31 | 32 | this.props.loginUser(creds); 33 | } 34 | 35 | render() { 36 | const { fields: { email, pass }, user, resetForm, submitting } = this.props; 37 | return ( 38 |
39 |
40 |
{user.message} 41 | {email.touched && email.error &&
{email.error}
} 42 | {pass.touched && pass.error &&
{pass.error}
} 43 |
44 |
45 | 46 | 47 |
48 |
49 | 50 | 51 |
52 |
53 | 56 | 59 |
60 |
61 |
62 | ); 63 | } 64 | } 65 | 66 | Login.contextTypes = { 67 | router: PropTypes.object.isRequired 68 | }; 69 | 70 | Login.propTypes = { 71 | fields: PropTypes.object, 72 | data: PropTypes.object, 73 | resetForm: PropTypes.func, 74 | loginUser: PropTypes.func, 75 | signupUser: PropTypes.func, 76 | user: PropTypes.object, 77 | submitting: PropTypes.bool 78 | }; 79 | 80 | const validate = values => { 81 | const errors = {}; 82 | 83 | if (!values.email) { 84 | errors.email = 'Email Required'; 85 | } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) { 86 | errors.email = 'Invalid email address'; 87 | } 88 | 89 | if (!values.pass) { 90 | errors.pass = 'Password Required'; 91 | } else if (values.pass.length < 6) { 92 | errors.pass = 'Has to be atleast 6 characters'; 93 | } 94 | 95 | return errors; 96 | }; 97 | 98 | function mapStateToProps(state) { 99 | return { 100 | data: state.form.login, 101 | user: state.user 102 | }; 103 | } 104 | 105 | export default reduxForm({ 106 | form: 'login', 107 | fields: ['email', 'pass'], 108 | validate 109 | }, mapStateToProps, { loginUser })(Login); 110 | -------------------------------------------------------------------------------- /src/containers/login/signup.js: -------------------------------------------------------------------------------- 1 | import React, { Component, PropTypes } from 'react'; 2 | import { reduxForm } from 'redux-form'; 3 | import './style.scss'; 4 | import { signupUser } from '../../actions/login.js'; 5 | 6 | class Signup extends Component { 7 | constructor(props) { 8 | super(props); 9 | this.onSubmit = this.onSubmit.bind(this); 10 | } 11 | 12 | componentWillMount() { 13 | if (this.props.user.isAuthenticated) { 14 | this.context.router.push('/dashboard'); 15 | } 16 | } 17 | 18 | componentWillReceiveProps(props) { 19 | if (props.user.isAuthenticated) { 20 | this.context.router.push('/dashboard'); 21 | } 22 | } 23 | 24 | onSubmit(e) { 25 | e.preventDefault(); 26 | const creds = { 27 | email: this.props.data.email.value || null, 28 | pass: this.props.data.pass.value || null, 29 | name: this.props.data.name.value || null 30 | }; 31 | 32 | this.props.signupUser(creds); 33 | } 34 | 35 | render() { 36 | const { fields: { email, pass, pass2, name }, user, resetForm, submitting } = this.props; 37 | return ( 38 |
39 |
40 |
{user.message} 41 | {email.touched && email.error &&
{email.error}
} 42 | {pass.touched && pass.error &&
{pass.error}
} 43 |
44 | 45 |
46 | 47 | 48 |
49 | 50 |
51 | 52 | 53 |
54 | 55 |
56 | 57 | 58 |
59 | 60 |
61 | 62 | 63 |
64 |
65 | 68 | 71 |
72 |
73 |
74 | ); 75 | } 76 | } 77 | 78 | Signup.contextTypes = { 79 | router: PropTypes.object.isRequired 80 | }; 81 | 82 | Signup.propTypes = { 83 | fields: PropTypes.object, 84 | data: PropTypes.object, 85 | resetForm: PropTypes.func, 86 | loginUser: PropTypes.func, 87 | dispatch: PropTypes.func, 88 | onSignup: PropTypes.func, 89 | signupUser: PropTypes.func, 90 | user: PropTypes.object, 91 | submitting: PropTypes.bool 92 | }; 93 | 94 | const validate = values => { 95 | const errors = {}; 96 | 97 | if (!values.email) { 98 | errors.email = 'Email Required'; 99 | } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) { 100 | errors.email = 'Invalid email address'; 101 | } 102 | 103 | if (!values.name) { 104 | errors.name = 'name Required'; 105 | } else if (!/([a-zA-Z]+)\w+/g.test(values.name)) { 106 | errors.email = 'Must be a valid name'; 107 | } else if (values.name.length < 3) { 108 | errors.pass = 'Has to be atleast 3 characters'; 109 | } 110 | 111 | if (!values.pass) { 112 | errors.pass = 'Password Required'; 113 | } else if (values.pass.length < 6) { 114 | errors.pass = 'Has to be atleast 6 characters'; 115 | } else if (values.pass !== values.pass2) { 116 | errors.pass = 'Passwords should MATCH'; 117 | } 118 | 119 | return errors; 120 | }; 121 | 122 | function mapStateToProps(state) { 123 | return { 124 | data: state.form.signup, 125 | user: state.user 126 | }; 127 | } 128 | 129 | export default reduxForm({ 130 | form: 'signup', 131 | fields: ['email', 'name', 'pass', 'pass2'], 132 | validate 133 | }, mapStateToProps, { signupUser })(Signup); 134 | -------------------------------------------------------------------------------- /src/containers/login/style.scss: -------------------------------------------------------------------------------- 1 | .middle { 2 | width: 100%; 3 | height: 50%; 4 | display: flex; 5 | justify-content: center; 6 | } 7 | 8 | .login-form { 9 | width: 30%; 10 | } 11 | 12 | .login-buttons button { 13 | margin: 10px 10px; 14 | } 15 | 16 | .error-message { 17 | color: red; 18 | font-size: 1.2rem; 19 | } 20 | -------------------------------------------------------------------------------- /src/containers/navbar/index.js: -------------------------------------------------------------------------------- 1 | import React, { Component, PropTypes } from 'react'; 2 | import { Link } from 'react-router'; 3 | import './style.scss'; 4 | 5 | class Navbar extends Component { 6 | 7 | componentDidMount() { 8 | if (!window.ENV_TEST) { 9 | $(function () { 10 | $('.button-collapse').sideNav({ 11 | menuWidth: 300, // Default is 240 12 | edge: 'right', // Choose the horizontal origin 13 | closeOnClick: true // Closes side-nav on clicks, useful for Angular/Meteor 14 | }); 15 | }); 16 | } 17 | } 18 | 19 | render() { 20 | if (!this.props.isAuthenticated) { 21 | return ( 22 | 38 | ); 39 | } 40 | return ( 41 | 65 | ); 66 | } 67 | } 68 | 69 | Navbar.propTypes = { 70 | logout: PropTypes.func, 71 | isAuthenticated: PropTypes.bool 72 | }; 73 | 74 | export default Navbar; 75 | -------------------------------------------------------------------------------- /src/containers/navbar/style.scss: -------------------------------------------------------------------------------- 1 | nav { 2 | position: fixed; 3 | margin: 0 0 3rem 0; 4 | font-size: 1.3rem; 5 | z-index: 5; 6 | 7 | .brand-logo { 8 | margin-left: 0.5rem; 9 | font-weight: bold; 10 | } 11 | a { 12 | } 13 | 14 | ul{ 15 | margin: 0 2.5rem 0 0; 16 | li { 17 | margin: 0 1rem 1rem 0; 18 | a { 19 | font-size: 1.2rem; 20 | font-weight: bold; 21 | } 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/containers/text-input/index.js: -------------------------------------------------------------------------------- 1 | import React, { Component, PropTypes } from 'react'; 2 | 3 | class TextInput extends Component { 4 | constructor(props) { 5 | super(props); 6 | this.state = { 7 | text: this.props.text || '' 8 | }; 9 | 10 | this.handleChange = this.handleChange.bind(this); 11 | this.handleSubmit = this.handleSubmit.bind(this); 12 | } 13 | 14 | handleChange(e) { 15 | this.setState({ text: e.target.value }); 16 | } 17 | 18 | handleSubmit() { 19 | this.setState({ text: '' }); 20 | } 21 | 22 | render() { 23 | return ( 24 |
25 |
26 |
27 | 28 | 29 |
30 |
31 |
32 | ); 33 | } 34 | } 35 | 36 | Filters.propTypes = { 37 | text: PropTypes.string, 38 | }; 39 | 40 | export default TextInput; 41 | -------------------------------------------------------------------------------- /src/helpers/highlight.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import SyntaxHighlighter from 'react-syntax-highlighter'; 3 | 4 | export default ({ props }) => ( 5 | {props} 6 | ); 7 | -------------------------------------------------------------------------------- /src/helpers/progress.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export default ({ number }) => { 4 | 5 | const width = number || .5; 6 | 7 | const style = { 8 | width: width + '0%' 9 | }; 10 | 11 | return ( 12 |
13 |
14 |
15 |
16 | ); 17 | }; 18 | -------------------------------------------------------------------------------- /src/helpers/spinner.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const style = { 4 | marginTop: '30%' 5 | }; 6 | 7 | export default () => ( 8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | ); 22 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import 'babel-polyfill'; import React from 'react'; 2 | import { render } from 'react-dom'; 3 | import { Provider } from 'react-redux'; 4 | import { Router, Route, IndexRoute, browserHistory } from 'react-router'; 5 | 6 | import storeConfig from './store'; 7 | import requireAuth from './containers/login/require_auth.js'; 8 | 9 | import App from './containers/app'; 10 | import Dashboard from './containers/dashboard'; 11 | import About from './containers/about'; 12 | import Login from './containers/login/signin.js'; 13 | import SignUp from './containers/login/signup.js'; 14 | 15 | 16 | const store = storeConfig(); 17 | 18 | render( 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | , 30 | document.getElementById('root') 31 | ); 32 | -------------------------------------------------------------------------------- /src/middlewares/token.js: -------------------------------------------------------------------------------- 1 | export default function ({ dispatch, getState }) { 2 | return next => action => { 3 | const console = window.console; 4 | const prevState = getState(); 5 | const returnValue = next(action); 6 | const nextState = getState(); 7 | const actionType = String(action.type); 8 | const message = `action ${actionType}`; 9 | 10 | // console.log(`%c prev state`, `color: #9e9e9e`, prevState); 11 | console.log(`%c action`, `color: #03a9f4`, action); 12 | // console.log(`%c next state`, `color: #4caf50`, nextState); 13 | 14 | return returnValue; 15 | }; 16 | }; 17 | -------------------------------------------------------------------------------- /src/reducers/main.js: -------------------------------------------------------------------------------- 1 | import * as ACTIONS from '../actions/constants'; 2 | 3 | export default (state = { isFetching: true, students: [] }, action) => { 4 | switch (action.type) { 5 | case ACTIONS.ADD_DATA: 6 | return {...state, students: state.students.concat(action.payload)}; 7 | case ACTIONS.UPDATE_DATA: 8 | return {...state, selectedStudent: action.payload}; 9 | case ACTIONS.FETCH_DATA_REQUEST: 10 | return {...state, isFetching: true} 11 | case ACTIONS.FETCH_DATA_SUCCESS: 12 | return {...state, isFetching: false, students: action.data.data, source: action.data.data} 13 | case ACTIONS.FETCH_DATA_FAILURE: 14 | return {...state, isFetching: false, message: action.data.message} 15 | default: 16 | return state; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /src/reducers/user.js: -------------------------------------------------------------------------------- 1 | import * as ACTIONS from '../actions/constants.js'; 2 | 3 | export default (state = {}, action) => { 4 | switch (action.type) { 5 | case ACTIONS.LOGIN_REQUEST: 6 | return {...state, isFetching: true, isAuthenticated: false, name: action.creds.email}; 7 | case ACTIONS.LOGIN_SUCCESS: 8 | return {...state, isFetching: false, isAuthenticated: true, message: ''}; 9 | case ACTIONS.LOGIN_FAILURE: 10 | return {...state, isFetching: false, isAuthenticated: false, message: action.message.data}; 11 | case ACTIONS.SIGNUP_REQUEST: 12 | return {...state, isFetching: true, isAuthenticated: false, name: action.creds.email}; 13 | case ACTIONS.SIGNUP_SUCCESS: 14 | return {...state, isFetching: false, isAuthenticated: true, message: ''}; 15 | case ACTIONS.SIGNUP_FAILURE: 16 | return {...state, isFetching: false, isAuthenticated: false, message: action.message.data.error}; 17 | case ACTIONS.TOKEN_LOGIN_REQUEST: 18 | return {...state, isFetching: true, isAuthenticated: false}; 19 | case ACTIONS.TOKEN_LOGIN_SUCCESS: 20 | return {...state, isFetching: false, isAuthenticated: true, message: '', name: action.name.data.name}; 21 | case ACTIONS.TOKEN_LOGIN_FAILURE: 22 | return {...state, isFetching: false, isAuthenticated: false, message: action.message.data}; 23 | case ACTIONS.LOGOUT: 24 | return {...state, isFetching: false, isAuthenticated: false, name: null}; 25 | default: 26 | return state; 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import { createStore, applyMiddleware, combineReducers } from 'redux'; 2 | import thunkMiddleware from 'redux-thunk'; 3 | import createLogger from 'redux-logger'; 4 | import { reducer as formReducer } from 'redux-form'; 5 | import promise from 'redux-promise'; 6 | import main from '../reducers/main.js'; 7 | import user from '../reducers/user.js'; 8 | 9 | // import jwt from '../middlewares/token.js'; 10 | 11 | const logger = createLogger({ 12 | collapsed: () => true, 13 | }); 14 | 15 | export const rootReducer = combineReducers({ 16 | form: formReducer, 17 | main, 18 | user 19 | }); 20 | 21 | const createStoreWithMiddleware = applyMiddleware( 22 | // jwt, 23 | promise, 24 | thunkMiddleware, 25 | logger 26 | )(createStore); 27 | 28 | export default function storeConfig(initialState) { 29 | return createStoreWithMiddleware(rootReducer, initialState); 30 | } 31 | -------------------------------------------------------------------------------- /test/actions/index_spec.js: -------------------------------------------------------------------------------- 1 | import { expect } from '../test_helper.js'; 2 | import * as ACTIONS from '../../src/actions/constants.js'; 3 | import { addStudent } from '../../src/actions/index.js'; 4 | 5 | describe('actions', () => { 6 | describe('add student', () => { 7 | let action; 8 | beforeEach(() => { 9 | let data = { 10 | _id: 5, 11 | lesson: 0, 12 | level: 0, 13 | interview: 'not set', 14 | decision: 'pending', 15 | name: 'John', 16 | email: 'John@student.com' 17 | }; 18 | action = addStudent(data); 19 | }); 20 | it('has to exist', () => { 21 | expect(action.type).to.be.a('string'); 22 | }); 23 | it('has to be correct type', () => { 24 | expect(action.type).to.equal(ACTIONS.ADD_STUDENT); 25 | }); 26 | 27 | it('has to have payload as an object', () => { 28 | expect(action.payload).to.be.an('object'); 29 | }); 30 | it('has to have correct propertins', () => { 31 | expect(action.payload.name).to.be.a('string'); 32 | expect(action.payload._id).to.be.a('number'); 33 | expect(action.payload.email).to.be.a('string'); 34 | expect(action.payload.level).to.be.a('number'); 35 | expect(action.payload.lesson).to.be.a('number'); 36 | expect(action.payload.interview).to.be.a('string'); 37 | expect(action.payload.decision).to.be.a('string'); 38 | }); 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /test/actions/login_spec.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/test/actions/login_spec.js -------------------------------------------------------------------------------- /test/components/app_spec.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { expect } from 'chai'; 3 | import { shallow } from 'enzyme'; 4 | import sinon from 'sinon'; 5 | import { App } from '../../src/containers/app/index.js'; 6 | import Spinner from '../../src/helpers/spinner.js'; 7 | 8 | describe('Main App component ', () => { 9 | let user; 10 | let wrapper; 11 | 12 | it('show spinner while fetching', () => { 13 | user = { 14 | isFetching: true 15 | }; 16 | wrapper = shallow(); 17 | expect(wrapper.find(Spinner)).to.have.length(1); 18 | }); 19 | 20 | describe('Render when user NOT loggin in', () => { 21 | beforeEach(() => { 22 | user = { 23 | isAuthenticated: false 24 | }; 25 | wrapper = shallow(); 26 | }); 27 | 28 | it('shows main component ', () => { 29 | expect(wrapper.find('#main')).to.have.length(1); 30 | }); 31 | 32 | it('have id main ', () => { 33 | expect(wrapper.is('#main')).to.equal(true); 34 | }); 35 | 36 | it('have to have a container ', () => { 37 | expect(wrapper.find('.container').hasClass('container')).to.equal(true); 38 | }); 39 | }); 40 | 41 | describe('Render when user IS loggin in', () => { 42 | beforeEach(() => { 43 | user = { 44 | isAuthenticated: true 45 | }; 46 | wrapper = shallow(); 47 | }); 48 | 49 | it('shows main component ', () => { 50 | expect(wrapper.find('#main')).to.have.length(1); 51 | }); 52 | 53 | it('have id main ', () => { 54 | expect(wrapper.is('#main')).to.equal(true); 55 | }); 56 | 57 | it('have to have a container ', () => { 58 | expect(wrapper.find('.container').hasClass('container')).to.equal(true); 59 | }); 60 | }); 61 | 62 | describe('validate user', () => { 63 | let validate; 64 | beforeEach(() => { 65 | user = { 66 | isAuthenticated: false 67 | }; 68 | global.window.localStorage.clean(); 69 | validate = sinon.spy(); 70 | wrapper = shallow(); 71 | }); 72 | 73 | it('should not validate if user is authenticated', () => { 74 | user = { 75 | isAuthenticated: true 76 | }; 77 | global.window.localStorage.setItem('id_token', 123456789); 78 | wrapper = shallow(); 79 | expect(validate.called).to.equal(false); 80 | }); 81 | 82 | it('should validate if token exist', () => { 83 | global.window.localStorage.setItem('id_token', 123456789); 84 | wrapper = shallow(); 85 | expect(validate.called).to.equal(true); 86 | }); 87 | 88 | it('should not validate if token doesnt exist', () => { 89 | expect(validate.called).to.equal(false); 90 | }); 91 | }); 92 | }); 93 | -------------------------------------------------------------------------------- /test/components/navbar_spec.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { expect } from '../test_helper.js'; 3 | import { shallow } from 'enzyme'; 4 | import sinon from 'sinon'; 5 | import Navbar from '../../src/containers/navbar/index.js'; 6 | 7 | describe('Navbar', () => { 8 | let wrapper; 9 | describe('When user not loged in', () => { 10 | beforeEach(() => { 11 | wrapper = shallow(); 12 | }); 13 | 14 | it('shows ptc portal logo', () => { 15 | expect(wrapper.find('.brand-logo')).to.have.length(1); 16 | }); 17 | 18 | it('shows navbar component', () => { 19 | expect(wrapper.find('.nav-wrapper')).to.have.length(1); 20 | }); 21 | 22 | it('show sidebar nav on small screen', () => { 23 | expect(wrapper.find('.side-nav')).to.have.length(1); 24 | }); 25 | 26 | it('show singin and singup on desktop', () => { 27 | expect(wrapper.find('.right').children()).to.have.length(2); 28 | }); 29 | it('show singin and singup on mobile', () => { 30 | expect(wrapper.find('.side-nav').children()).to.have.length(2); 31 | }); 32 | }); 33 | 34 | 35 | describe('When user is loged in', () => { 36 | beforeEach(() => { 37 | wrapper = shallow(); 38 | }); 39 | 40 | it('shows ptc portal logo', () => { 41 | expect(wrapper.find('.brand-logo')).to.have.length(1); 42 | }); 43 | 44 | it('shows navbar component', () => { 45 | expect(wrapper.find('.nav-wrapper')).to.have.length(1); 46 | }); 47 | 48 | it('show sidebar nav on small screen', () => { 49 | expect(wrapper.find('.side-nav')).to.have.length(1); 50 | }); 51 | 52 | it('show singin and singup on desktop', () => { 53 | expect(wrapper.find('.right').children()).to.have.length(7); 54 | }); 55 | 56 | it('show singin and singup on mobile', () => { 57 | expect(wrapper.find('.side-nav').children()).to.have.length(7); 58 | }); 59 | 60 | it('should be able to logout', () => { 61 | const logout = sinon.spy(); 62 | wrapper = shallow(); 63 | wrapper.find('.logout').simulate('click'); 64 | wrapper.setProps({ isAuthenticated: false }); 65 | expect(logout.called).to.equal(true); 66 | expect(wrapper.find('.right').children()).to.have.length(2); 67 | }); 68 | }); 69 | }); 70 | -------------------------------------------------------------------------------- /test/reducers/students-local_spec.js: -------------------------------------------------------------------------------- 1 | import { expect } from '../test_helper.js'; 2 | import studentReducer from '../../src/reducers/students.local.js'; 3 | import * as ACTIONS from '../../src/actions/constants.js'; 4 | 5 | 6 | describe('Student Reducer', () => { 7 | it('Handles action with unknown type', () => { 8 | expect(studentReducer(undefined, {})).to.be.instanceof(Object); 9 | expect(studentReducer(undefined, {})).to.be.eql({ isFetching: true, students: [] }); 10 | }); 11 | 12 | it('Handles action of type ADD_STUDENT', () => { 13 | const data = { 14 | _id: 5, 15 | lesson: 0, 16 | level: 0, 17 | interview: 'not set', 18 | decision: 'pending', 19 | name: 'John', 20 | email: 'John@student.com' 21 | }; 22 | const state = { isFetching: true, students: [] }; 23 | const action = { type: ACTIONS.ADD_STUDENT, payload: data }; 24 | expect(studentReducer(state, action)).to.be.eql({ isFetching: true, students: [data] }); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /test/reducers/user_spec.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wunderg/react-redux-express-mongo-starter/45a50cd225ef1919f1385ffc7e3b794a5b9397f7/test/reducers/user_spec.js -------------------------------------------------------------------------------- /test/test_helper.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import jquery from 'jquery'; 3 | import jsdom from 'jsdom'; 4 | 5 | const exposedProperties = ['window', 'navigator', 'document']; 6 | 7 | global.document = jsdom.jsdom(''); 8 | global.window = document.defaultView; 9 | Object.keys(document.defaultView).forEach((property) => { 10 | if (typeof global[property] === 'undefined') { 11 | exposedProperties.push(property); 12 | global[property] = document.defaultView[property]; 13 | } 14 | }); 15 | 16 | const $ = jquery(global.window); 17 | $.sideNav = function () {}; 18 | global.window.$ = $; 19 | global.$ = $; 20 | global.window.ENV_TEST = true; 21 | 22 | global.navigator = { 23 | userAgent: 'node.js' 24 | }; 25 | 26 | const createStorage = () => { 27 | let store = {}; 28 | store.getItem = item => store[item]; 29 | store.setItem = (item, value) => store[item] = value; 30 | store.clean = () => store = {}; 31 | return store; 32 | }; 33 | 34 | global.window.localStorage = createStorage(); 35 | global.document.localStorage = createStorage(); 36 | 37 | export { expect }; 38 | -------------------------------------------------------------------------------- /webpack-config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | var ProgressBarPlugin = require('progress-bar-webpack-plugin'); 4 | var chalk = require('chalk'); 5 | var precss = require('precss'); 6 | var autoprefixer = require('autoprefixer'); 7 | 8 | module.exports = { 9 | devtool: 'eval-source-map', 10 | entry: [ 11 | 'webpack-dev-server/client?http://localhost:3001', 12 | // 'webpack/hot/only-dev-server', 13 | 'webpack/hot/dev-server', 14 | './src/index', 15 | 'babel-polyfill', 16 | ], 17 | output: { 18 | path: path.join(__dirname, 'dist'), 19 | filename: 'bundle.js', 20 | publicPath: '/dist' 21 | }, 22 | plugins: [ 23 | new webpack.optimize.OccurenceOrderPlugin(), 24 | new webpack.HotModuleReplacementPlugin(), 25 | // new webpack.NoErrorsPlugin(), 26 | new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('development'), 27 | }), 28 | new ProgressBarPlugin({ 29 | format: chalk.yellow.bold('build [:bar]') + chalk.blue.bold(':percent') + ' (:elapsed seconds)', 30 | clear: false 31 | }) 32 | ], 33 | resolve: { 34 | extensions: ['', '.js', '.jsx'] 35 | }, 36 | module: { 37 | 38 | noParse: [/autoit.js/], 39 | 40 | loaders: [ 41 | { 42 | test: /\.js$/, 43 | loader: 'react-hot!babel-loader', 44 | exclude: /node_modules/, 45 | include: __dirname 46 | }, 47 | 48 | { 49 | test: /\.json?$/, 50 | loader: 'json' 51 | }, 52 | 53 | { 54 | test: /\.css?$/, 55 | loaders: ['style', 'raw', 'postcss'], 56 | include: __dirname 57 | }, 58 | 59 | { 60 | test: /\.scss$/, 61 | loaders: ['style', 'css', 'postcss', 'sass'] 62 | }, 63 | 64 | { 65 | test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/, 66 | loader: 'url-loader?limit=10000&minetype=application/font-woff=./dist/' 67 | }, 68 | 69 | ] 70 | }, 71 | 72 | postcss: function() { 73 | return [precss, autoprefixer]; 74 | }, 75 | 76 | stats: { 77 | colors: true 78 | } 79 | }; 80 | -------------------------------------------------------------------------------- /webpack.production.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path'); 4 | var webpack = require('webpack'); 5 | var StatsPlugin = require('stats-webpack-plugin'); 6 | var precss = require('precss'); 7 | var autoprefixer = require('autoprefixer'); 8 | 9 | module.exports = { 10 | entry: [ 11 | 'babel-polyfill', 12 | path.join(__dirname, 'src/index.js') 13 | ], 14 | output: { 15 | path: path.join(__dirname, '/dist'), 16 | filename: 'bundle.js' 17 | }, 18 | plugins: [ 19 | new webpack.optimize.OccurenceOrderPlugin(), 20 | new webpack.optimize.UglifyJsPlugin({ 21 | compressor: { 22 | warnings: false, 23 | screw_ie8: true 24 | } 25 | }), 26 | new StatsPlugin('webpack.stats.json', { 27 | source: false, 28 | modules: false 29 | }), 30 | new webpack.DefinePlugin({ 31 | 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) 32 | }) 33 | ], 34 | module: { 35 | 36 | noParse: [/autoit.js/], 37 | 38 | loaders: [ 39 | { 40 | test: /\.js$/, 41 | loader: 'babel-loader', 42 | exclude: /node_modules/, 43 | include: __dirname, 44 | query: { 45 | plugins: ['transform-runtime'], 46 | presets: ['es2015', 'stage-0', 'react'], 47 | } 48 | }, 49 | 50 | { 51 | test: /\.json?$/, 52 | loader: 'json' 53 | }, 54 | 55 | { 56 | test: /\.css?$/, 57 | loaders: ['style', 'raw', 'postcss'], 58 | include: __dirname 59 | }, 60 | 61 | { 62 | test: /\.scss$/, 63 | loaders: ['style', 'css', 'postcss', 'sass'] 64 | }, 65 | 66 | { 67 | test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/, 68 | loader: 'url-loader?limit=30000&name=../[hash].[ext]' 69 | } 70 | ] 71 | }, 72 | postcss: function() { 73 | return [precss, autoprefixer]; 74 | } 75 | 76 | }; 77 | --------------------------------------------------------------------------------