| 
									
										
										
										
											2015-08-11 13:22:16 -07:00
										 |  |  | import { defaultProfileImage } from '../../common/utils/constantStrings.json'; | 
					
						
							| 
									
										
										
										
											2016-06-17 12:35:10 -07:00
										 |  |  | import supportedLanguages from '../../common/utils/supported-languages'; | 
					
						
							| 
									
										
										
										
											2015-08-11 13:22:16 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const message = | 
					
						
							| 
									
										
										
										
											2015-10-31 02:59:09 -07:00
										 |  |  |   'Learn to Code and Help Nonprofits'; | 
					
						
							| 
									
										
										
										
											2014-01-13 04:34:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 16:19:23 -07:00
										 |  |  | module.exports = function(app) { | 
					
						
							| 
									
										
										
										
											2015-06-03 16:31:42 -07:00
										 |  |  |   var router = app.loopback.Router(); | 
					
						
							| 
									
										
										
										
											2015-08-11 13:22:16 -07:00
										 |  |  |   router.get('/', addDefaultImage, index); | 
					
						
							| 
									
										
										
										
											2016-06-17 12:35:10 -07:00
										 |  |  |   app.use( | 
					
						
							| 
									
										
										
										
											2018-01-09 17:12:58 -08:00
										 |  |  |     '/:lang', | 
					
						
							|  |  |  |     (req, res, next) => { | 
					
						
							|  |  |  |       // add url language to request for all routers
 | 
					
						
							|  |  |  |       req._urlLang = req.params.lang; | 
					
						
							|  |  |  |       next(); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     router | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-03 16:31:42 -07:00
										 |  |  |   app.use(router); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-11 13:22:16 -07:00
										 |  |  |   function addDefaultImage(req, res, next) { | 
					
						
							|  |  |  |     if (!req.user || req.user.picture) { | 
					
						
							|  |  |  |       return next(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-17 12:35:10 -07:00
										 |  |  |     return req.user.update$({ picture: defaultProfileImage }) | 
					
						
							|  |  |  |       .subscribe( | 
					
						
							|  |  |  |         () => next(), | 
					
						
							|  |  |  |         next | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2015-08-11 13:22:16 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-05-21 11:07:40 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 12:35:10 -07:00
										 |  |  |   function index(req, res, next) { | 
					
						
							|  |  |  |     if (!supportedLanguages[req._urlLang]) { | 
					
						
							|  |  |  |       return next(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-11 13:22:16 -07:00
										 |  |  |     if (req.user) { | 
					
						
							| 
									
										
										
										
											2018-01-12 11:10:17 -08:00
										 |  |  |       return res.redirect('/challenges/current-challenge'); | 
					
						
							| 
									
										
										
										
											2015-06-03 16:19:23 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-17 12:35:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-02 20:54:14 -08:00
										 |  |  |     return res.render('home', { title: message }); | 
					
						
							| 
									
										
										
										
											2015-05-01 21:32:24 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-06-03 16:19:23 -07:00
										 |  |  | }; |