Merge branch 'hotfix-0.6.2'

master
Keith Irwin 2017-05-02 09:46:05 -04:00
commit 48366c15af
No known key found for this signature in database
GPG Key ID: 378933C743E2BBC0
8 changed files with 85 additions and 69 deletions

View File

@ -1,5 +1,10 @@
# Tracman Server Changelog
###### v 0.6.1
###### v 0.6.2
#### v0.6.2
* [#76](https://github.com/Tracman-org/Server/issues/76) Prevented users with no password from deleting google social login
* Fixed error when creating user
#### v0.6.1

View File

@ -1,13 +1,17 @@
# <img align="left" src="/static/img/icon/by/48.png" alt="[]" title="The Tracman Logo">Tracman
###### v 0.6.1
###### v 0.6.2
node.js application to display a sharable map with user's location.
## Installation
On unix-based systems:
```sh
$ git clone https://github.com/Tracman-org/Server.git && (cd Server && exec npm install)
git clone https://github.com/Tracman-org/Server.git &&\
mv Server tracman-server && cd tracman-server &&\
exec npm install
```
You will need to set up a configuration file at `config/env/env.js`. Use `config/env/sample.js` for an example. You can get API keys at the [google developer's console](https://console.developers.google.com/apis/credentials). You will need to set up approved hosts and auth callbacks. There is more information in [their documentation](https://support.google.com/googleapi/answer/6158857?hl=en).
@ -15,8 +19,8 @@ You will need to set up a configuration file at `config/env/env.js`. Use `confi
A good method is to simply copy the sample configuration and point `config/env/env.js` to the new version:
```sh
$ cp config/env/sample.js config/env/my-config.js
$ printf "'use strict';\n\nmodule.exports = require('./my-config.js');" > config/env/env.js
cp config/env/sample.js config/env/my-config.js
printf "'use strict';\n\nmodule.exports = require('./my-config.js');" > config/env/env.js
```
Then edit `config/env/my-config.js` to match your local environment.
@ -27,13 +31,13 @@ Then edit `config/env/my-config.js` to match your local environment.
Run Tracman with npm:
```sh
$ npm run minify && npm start
npm run minify && npm start
```
...or with [nodemon](https://nodemon.io/):
```sh
$ npm run nodemon
npm run nodemon
```
Nodemon will automatically minify files and restart the app when you make changes. Check out the `nodemon.json` configuration.
@ -48,6 +52,11 @@ Tracman will be updated according to [this branching model](http://nvie.com/post
[view full changelog](CHANGELOG.md)
#### v0.6.2
* [#76](https://github.com/Tracman-org/Server/issues/76) Prevented users with no password from deleting google social login
* Fixed error when creating user
#### v0.6.1
* [#77](https://github.com/Tracman-org/Server/issues/77) Fixed 500 after password change, swapped `bcrypt` for `bcrypt-nodejs`

View File

@ -6,6 +6,7 @@ const
User = require('../models.js').user,
crypto = require('crypto'),
moment = require('moment'),
slugify = require('slug'),
env = require('../env/env.js');
module.exports = (app, passport) => {
@ -62,7 +63,7 @@ module.exports = (app, passport) => {
function sendToken(user){
// Create a password token
user.createPassToken((err,token,expires)=>{
user.createPassToken( (err,token,expires)=>{
if (err){
mw.throwErr(err,req);
res.redirect('/login#signup');
@ -76,12 +77,12 @@ module.exports = (app, passport) => {
// Email the instructions to continue
mail.send({
from: mail.from,
to: `<${user.email}>`,
subject: 'Complete your Tracman registration',
text: mail.text(`Welcome to Tracman! \n\nTo complete your registration, follow this link and set your password:\n${env.url}/settings/password/${token}\n\nThis link will expire at ${expirationTimeString}. `),
html: mail.html(`<p>Welcome to Tracman! </p><p>To complete your registration, follow this link and set your password:<br><a href="${env.url}/settings/password/${token}">${env.url}/settings/password/${token}</a></p><p>This link will expire at ${expirationTimeString}. </p>`)
})
from: mail.from,
to: `<${user.email}>`,
subject: 'Complete your Tracman registration',
text: mail.text(`Welcome to Tracman! \n\nTo complete your registration, follow this link and set your password:\n${env.url}/settings/password/${token}\n\nThis link will expire at ${expirationTimeString}. `),
html: mail.html(`<p>Welcome to Tracman! </p><p>To complete your registration, follow this link and set your password:<br><a href="${env.url}/settings/password/${token}">${env.url}/settings/password/${token}</a></p><p>This link will expire at ${expirationTimeString}. </p>`)
})
.then(()=>{
req.flash('success', `An email has been sent to <u>${user.email}</u>. Check your inbox and follow the link to complete your registration. (Your registration link will expire in one hour). `);
res.redirect('/login');
@ -123,7 +124,7 @@ module.exports = (app, passport) => {
user = new User();
user.created = Date.now();
user.email = req.body.email;
user.slug = slug(user.email.substring(0, user.email.indexOf('@')));
user.slug = slugify(user.email.substring(0, user.email.indexOf('@')));
// Generate unique slug
const slug = new Promise((resolve,reject) => {
@ -134,14 +135,14 @@ module.exports = (app, passport) => {
// Slug in use: generate a random one and retry
if (existingUser){
crypto.randomBytes(6)
.then( (buf)=>{
s = buf.toString('hex');
checkSlug(s,cb);
})
.catch( (err)=>{
mw.throwErr(err,req);
reject();
crypto.randomBytes(6, (err,buf)=>{
if (err) {
mw.throwErr(err,req);
reject();
}
if (buf) {
checkSlug(buf.toString('hex'),cb);
}
});
}
@ -162,14 +163,15 @@ module.exports = (app, passport) => {
// Generate sk32
const sk32 = new Promise((resolve,reject) => {
crypto.randomBytes(32)
.then( (buf)=>{
user.sk32 = buf.toString('hex');
resolve();
})
.catch( (err)=>{
mw.throwErr(err,req);
reject();
crypto.randomBytes(32, (err,buf)=>{
if (err) {
mw.throwErr(err,req);
reject();
}
if (buf) {
user.sk32 = buf.toString('hex');
resolve();
}
});
});
@ -278,16 +280,28 @@ module.exports = (app, passport) => {
// Disconnect social account
else {
//console.log(`Attempting to disconnect ${service} account...`);
req.user.auth[service] = undefined;
req.user.save()
.then(()=>{
req.flash('success', `${mw.capitalize(service)} account disconnected. `);
// Make sure the user has a password before they disconnect their google login account
// This is because login used to only be through google, and some people might not have
// set passwords yet...
if (!req.user.auth.password && service==='google') {
req.flash('warning',`Hey, you need to <a href="/settings/password">set a password</a> before you can disconnect your google account. Otherwise, you won't be able to log in! `);
res.redirect('/settings');
})
.catch((err)=>{
mw.throwErr(err,req);
res.redirect('/settings');
});
}
else {
req.user.auth[service] = undefined;
req.user.save()
.then(()=>{
req.flash('success', `${mw.capitalize(service)} account disconnected. `);
res.redirect('/settings');
})
.catch((err)=>{
mw.throwErr(err,req);
res.redirect('/settings');
});
}
}
});

View File

@ -137,14 +137,14 @@ router.route('/')
// Set values
req.user.name = xss(req.body.name);
req.user.settings = {
units: req.body.units,
defaultMap: req.body.map,
defaultZoom: req.body.zoom,
showScale: (req.body.showScale)?true:false,
showSpeed: (req.body.showSpeed)?true:false,
showAlt: (req.body.showAlt)?true:false,
showStreetview: (req.body.showStreet)?true:false
};
units: req.body.units,
defaultMap: req.body.map,
defaultZoom: req.body.zoom,
showScale: (req.body.showScale)?true:false,
showSpeed: (req.body.showSpeed)?true:false,
showAlt: (req.body.showAlt)?true:false,
showStreetview: (req.body.showStreet)?true:false
};
// Save user and send response
//console.log(`Saving new settings for user ${req.user.name}...`);
@ -316,7 +316,7 @@ router.route('/password/:token')
// New user created password
else {
req.flash('success', 'Password set. You can use it to log in now. ');
res.redirect('/login#login');
res.redirect('/login?next=/settings');
}
} );

View File

@ -8,14 +8,7 @@ function checkForUsers(io, user) {
//console.log(`Checking for clients receiving updates for ${user}`);
// Checks if any sockets are getting updates for this user
//TODO: Use Object.values() after upgrading to node v7
/* if (Object.values(io.sockets.connected).some( (socket)=>{
* return socket.gets==user;
* })) {
*/
if (Object.keys(io.sockets.connected).map( (key)=>{
return io.sockets.connected[key];
}).some( (socket)=>{
if (Object.values(io.sockets.connected).some( (socket)=>{
return socket.gets===user;
})) {
//console.log(`Activating updates for ${user}.`);

View File

@ -1,6 +1,6 @@
{
"name": "tracman",
"version": "0.6.1",
"version": "0.6.2",
"description": "Tracks user's GPS location",
"main": "server.js",
"dependencies": {
@ -13,6 +13,7 @@
"express-validator": "^3.1.3",
"kerberos": "0.0.17",
"mellt": "^1.0.0",
"minifier": "^0.8.1",
"moment": "^2.12.0",
"mongodb": "^2.2.26",
"mongoose": "^4.9.0",
@ -39,7 +40,6 @@
"karma-chrome-launcher": "^1.0.1",
"karma-firefox-launcher": "^1.0.0",
"karma-mocha": "^1.1.1",
"minifier": "^0.8.1",
"mocha": "^2.5.3",
"nodemon": "^1.10.2",
"supertest": "^1.2.0"
@ -51,10 +51,7 @@
"minify": "minify --template .{{filename}}.min.{{ext}} --clean static",
"update": "sudo n stable && sudo npm update --save && sudo npm prune"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tracman-org/server.git"
},
"repository": "Tracman-org/Server",
"keywords": [
"gps",
"tracking",
@ -64,8 +61,6 @@
"author": "Keith Irwin",
"license": "GPL-3.0",
"README": "README.md",
"bugs": {
"url": "https://github.com/Tracman-org/Server/issues"
},
"bugs": "https://github.com/Tracman-org/Server/issues",
"homepage": "https://tracman.org/"
}

View File

@ -77,7 +77,7 @@ const
app.get( '*', (req,res,next)=>{
// Path for redirects
let nextPath = ( req.path.substring(0, req.path.indexOf('#')) || req.path );
let nextPath = ((req.query.next)?req.query.next: req.path.substring(0,req.path.indexOf('#')) || req.path );
if ( nextPath.substring(0,6)!=='/login' && nextPath.substring(0,7)!=='/logout' ){
req.session.next = nextPath+'#';
//console.log(`Set redirect path to ${nextPath}#`);

View File

@ -12,14 +12,14 @@
<!-- Navigation -->
<nav id='navigation'><ul>
<li><a href="/">About</a></li>
{% if user %}
<li><a href="/map">Map</a></li>
<li><a href="/settings">Settings</a></li>
{% if user.isAdmin %}<li><a href="/admin">Admin</a></li>{% endif %}
{% endif %}
<li><a href="/">About</a></li>
<li><a href="/help">Help</a></li>
{% if user %}
{% if user.isAdmin %}<li><a href="/admin">Admin</a></li>{% endif %}
<li><a href="/logout">Logout</a></li>
{% else %}
<li><a href="/map/keith">Demo</a></li>