various updates, including fix of #13

master
Keith Irwin 2016-05-07 20:33:00 +00:00
parent 8e81015557
commit c4d47d38b5
5 changed files with 60 additions and 47 deletions

View File

@ -16,6 +16,7 @@
<p>After carefully reviewing your credentials over a glass of malt liquor, it has been determined that you are qualified to use <a href="https://tracman.org/">Tracman</a> during the super-exclusive, invite-only beta stage. </p>
<p>Feel free to use this link to create an account.&ensp;Note that you will need a google account to continue.&ensp;You will also need an android phone to update your location.&ensp;</p>
<p class='invite'><a href="https://tracman.org/invited/{{id}}">http://tracman.org/invited/{{id}}</a></p>
<p>You will be asked to sign into google and authorize the Tracman app.&ensp;</p>
<p>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.&ensp;You have read the <a href="https://tracman.org/#disclaimer">disclaimer</a>, haven't you?&ensp;</p>
<p>Regards,
<br>Keith</p>

View File

@ -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.&ensp;Note that you will need a google account to continue.&ensp;You will also need an android phone to update your location.&ensp;
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.&ensp;

View File

@ -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. <a href="/login">Click here to log in</a>. ');
res.redirect('/');
}

View File

@ -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);
}
});
});
});
});
}
}
});
}

View File

@ -100,7 +100,9 @@
<section class='disclaimer light' id='disclaimer'>
<div class='container'>
<h2>Warning! </h2>
<p>There are a lot of reasons why publishing your location online could be a bad idea.&ensp;I assume no responsibility whatsoever.&ensp;</p>
<p>This is beta software, so there are still kinks to be worked out&hellip; </p>
<p>Also keep in mind that there are a lot of reasons why publishing your location online could be a bad idea.&ensp;</p>
<p>I assume no responsibility whatsoever.&ensp;</p>
</div>
</section>