diff --git a/README.md b/README.md index dfa9036..0f93acc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Tracman -###### v 0.1.2 +###### v 0.1.3 node.js application to display a map with user's location. Live at [tracman.org](https://tracman.org/). The github for the associated android app is [Tracman-org/Android](https://github.com/tracman-org/android). diff --git a/config/mail/invite/html.nunjucks b/config/mail/invite/html.nunjucks index 8b1e7b6..f3c1676 100644 --- a/config/mail/invite/html.nunjucks +++ b/config/mail/invite/html.nunjucks @@ -16,6 +16,7 @@

After carefully reviewing your credentials over a glass of malt liquor, it has been determined that you are qualified to use Tracman during the super-exclusive, invite-only beta stage.

Feel free to use this link to create an account. Note that you will need a google account to continue. You will also need an android phone to update your location. 

http://tracman.org/invited/{{id}}

+

You will be asked to sign into google and authorize the Tracman app. 

Please keep in mind that this is experimental software, and I am not responsible for it actually working properly, or anything else for that matter. You have read the disclaimer, haven't you? 

Regards,
Keith

diff --git a/config/mail/invite/text.nunjucks b/config/mail/invite/text.nunjucks index e138982..1c8e76e 100644 --- a/config/mail/invite/text.nunjucks +++ b/config/mail/invite/text.nunjucks @@ -4,7 +4,9 @@ After carefully reviewing your credentials over a glass of malt liquor, it has b Feel free to use this link to create an account. Note that you will need a google account to continue. You will also need an android phone to update your location.  -http://tracman.org/invited/{{id}} +https://tracman.org/invited/{{id}} + +You will be asked to sign into google and authorize the Tracman app. Please keep in mind that this is experimental software, and I am not responsible for it actually working properly, or anything else for that matter.  diff --git a/config/middleware.js b/config/middleware.js index 2a0f64b..549886a 100644 --- a/config/middleware.js +++ b/config/middleware.js @@ -17,6 +17,7 @@ module.exports = { if (req.isAuthenticated()) { return next(); } else { req.session.returnTo = req.path; + console.log('mw.ensureAuth: redirect to '+req.path+' after login.'); req.flash('error', 'You must be signed in to do that. Click here to log in. '); res.redirect('/'); } diff --git a/config/routes/invite.js b/config/routes/invite.js index 776b0b8..c31f03d 100644 --- a/config/routes/invite.js +++ b/config/routes/invite.js @@ -5,61 +5,68 @@ var router = require('express').Router(), Request = require('../models/request.js'); router.get('/:invite', function(req,res,next){ + function associateUser(request,user){ + request.userId = user._id; + request.save(function(err, raw){ + if (err){ mw.throwErr(req,err); } + }); + req.logIn(user, function(err) { + if (err) { mw.throwErr(req,err); } + user.lastLogin = Date.now(); + user.save(function(err, raw) { + if (err) { mw.throwErr(req,err); } + res.redirect('/login'); + }); + }); + } User.findOne({requestId:req.params.invite}, function(err, existingUser) { // User already accepted invite - if (err) { console.log('Could not find invited user: '+err); } - if (existingUser) { res.redirect('/login'); } + if (err) { console.log('Could not find existing user: '+err); } + if (existingUser && existingUser.gooogleID) { res.redirect('/login'); } else { Request.findById(req.params.invite, function(err, request) { // Check for granted invite if (err) { mw.throwErr(req,err); } if (!request) { next(); } else { - (function checkSlug(s,cb) { - console.log('checking ',s); - User.findOne({slug:s}, function(err, existingUser){ - if (err) { console.log('Slug check error for ',slug(request.name),+':',err); } - if (existingUser){ - s = ''; - while (s.length<6) { - s+='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.charAt(Math.floor(Math.random()*62)); + if (existingUser) { // associate existing user with google account + associateUser(request,existingUser); + } else { // create new user + (function checkSlug(s,cb) { + console.log('checking ',s); + User.findOne({slug:s}, function(err, existingUser){ + if (err) { console.log('Slug check error for ',slug(request.name),+':',err); } + if (existingUser){ + s = ''; + while (s.length<6) { + s+='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.charAt(Math.floor(Math.random()*62)); + } + checkSlug(s,cb); + } else { cb(s); } + }); + })(slug(request.name), function(newSlug){ + new User({ // Create new user + requestId: request._id, + email: '', + slug: newSlug, + name: request.name, + created: Date.now(), + settings: { + units: 'imperial', + showSpeed: false, + showTemp: false, + showAlt: false, + showStreetview: true } - checkSlug(s,cb); - } else { cb(s); } - }); - })(slug(request.name), function(newSlug){ - new User({ // Create new user - requestId: request._id, - email: '', - slug: newSlug, - name: request.name, - created: Date.now(), - settings: { - units: 'imperial', - showSpeed: false, - showTemp: false, - showAlt: false, - showStreetview: true - } - }).save(function(err) { - if (err) { mw.throwErr(req,err); } - User.findOne({requestId:request._id}, function(err, user) { + }).save(function(err) { if (err) { mw.throwErr(req,err); } - if (user) { - request.userId = user._id; - request.save(function(err, raw){ - if (err){ mw.throwErr(req,err); } - }); - req.logIn(user, function(err) { - if (err) { mw.throwErr(req,err); } - user.lastLogin = Date.now(); - user.save(function(err, raw) { - if (err) { mw.throwErr(req,err); } - res.redirect('/login'); - }); - }); - } + User.findOne({requestId:request._id}, function(err, user) { + if (err) { mw.throwErr(req,err); } + if (user) { + associateUser(request,user); + } + }); }); }); - }); + } } }); } diff --git a/package.json b/package.json index 9f65d53..4afc539 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tracman", - "version": "0.1.2", + "version": "0.1.3", "description": "Tracks user's GPS location", "main": "server.js", "dependencies": { diff --git a/views/admin/requests.html b/views/admin/requests.html index d76a508..fb8e9b5 100644 --- a/views/admin/requests.html +++ b/views/admin/requests.html @@ -40,7 +40,7 @@ {% if request.userId %} - User: {{request.userId}} + {{request.userId}} {% endif %} diff --git a/views/index.html b/views/index.html index 08759ca..5a9d3e7 100644 --- a/views/index.html +++ b/views/index.html @@ -100,7 +100,9 @@

Warning!

-

There are a lot of reasons why publishing your location online could be a bad idea. I assume no responsibility whatsoever. 

+

This is beta software, so there are still kinks to be worked out…

+

Also keep in mind that there are a lot of reasons why publishing your location online could be a bad idea. 

+

I assume no responsibility whatsoever.