Removed buggy login/-out redirects
parent
e249d44cae
commit
6aba3ec9a8
|
@ -1,6 +1,7 @@
|
||||||
# Tracman Server Changelog
|
# Tracman Server Changelog
|
||||||
|
|
||||||
###### v0.8.0
|
###### v0.8.0
|
||||||
|
* Removed buggy login/-out redirects
|
||||||
* [#111](https://github.com/Tracman-org/Server/issues/111) Implemented service worker
|
* [#111](https://github.com/Tracman-org/Server/issues/111) Implemented service worker
|
||||||
* [#116](https://github.com/Tracman-org/Server/issues/116) Switched promises for async/await
|
* [#116](https://github.com/Tracman-org/Server/issues/116) Switched promises for async/await
|
||||||
* [#64](https://github.com/Tracman-org/Server/issues/64) Started using promises in model methods
|
* [#64](https://github.com/Tracman-org/Server/issues/64) Started using promises in model methods
|
||||||
|
|
|
@ -56,6 +56,7 @@ Tracman will be updated according to [this branching model](http://nvie.com/post
|
||||||
[view full changelog](CHANGELOG.md)
|
[view full changelog](CHANGELOG.md)
|
||||||
|
|
||||||
#### v0.8.0
|
#### v0.8.0
|
||||||
|
* Removed buggy login/-out redirects
|
||||||
* [#111](https://github.com/Tracman-org/Server/issues/111) Implemented service worker
|
* [#111](https://github.com/Tracman-org/Server/issues/111) Implemented service worker
|
||||||
* [#116](https://github.com/Tracman-org/Server/issues/116) Switched promises for async/await
|
* [#116](https://github.com/Tracman-org/Server/issues/116) Switched promises for async/await
|
||||||
* [#64](https://github.com/Tracman-org/Server/issues/64) Started using promises in model methods
|
* [#64](https://github.com/Tracman-org/Server/issues/64) Started using promises in model methods
|
||||||
|
|
|
@ -38,7 +38,6 @@ module.exports = (passport) => {
|
||||||
// No user with that email
|
// No user with that email
|
||||||
if (!user) {
|
if (!user) {
|
||||||
debug(`No user with that email`)
|
debug(`No user with that email`)
|
||||||
req.session.next = undefined
|
|
||||||
return done(null, false, req.flash('warning', 'Incorrect email or password.'))
|
return done(null, false, req.flash('warning', 'Incorrect email or password.'))
|
||||||
|
|
||||||
// User exists
|
// User exists
|
||||||
|
@ -51,11 +50,11 @@ module.exports = (passport) => {
|
||||||
// Password incorrect
|
// Password incorrect
|
||||||
if (!res) {
|
if (!res) {
|
||||||
debug(`Incorrect password`)
|
debug(`Incorrect password`)
|
||||||
req.session.next = undefined
|
|
||||||
return done(null, false, req.flash('warning', 'Incorrect email or password.'))
|
return done(null, false, req.flash('warning', 'Incorrect email or password.'))
|
||||||
|
|
||||||
// Successful login
|
// Successful login
|
||||||
} else {
|
} else {
|
||||||
|
if (!user.lastLogin) req.forNewUser = true
|
||||||
user.lastLogin = Date.now()
|
user.lastLogin = Date.now()
|
||||||
user.save()
|
user.save()
|
||||||
return done(null, user)
|
return done(null, user)
|
||||||
|
@ -87,7 +86,7 @@ module.exports = (passport) => {
|
||||||
if (service === 'google') {
|
if (service === 'google') {
|
||||||
try {
|
try {
|
||||||
let user = await User.findOne({ 'googleID': parseInt(profileId, 10) })
|
let user = await User.findOne({ 'googleID': parseInt(profileId, 10) })
|
||||||
|
|
||||||
// User exists with old schema
|
// User exists with old schema
|
||||||
if (user) {
|
if (user) {
|
||||||
debug(`User ${user.id} exists with old schema. Lazily updating...`)
|
debug(`User ${user.id} exists with old schema. Lazily updating...`)
|
||||||
|
|
|
@ -17,11 +17,11 @@ module.exports = (app, passport) => {
|
||||||
failureFlash: true
|
failureFlash: true
|
||||||
}
|
}
|
||||||
const loginCallback = (req, res) => {
|
const loginCallback = (req, res) => {
|
||||||
debug(`Login callback called... redirecting to ${req.session.next}`)
|
debug(`Logged in... redirecting to /map`)
|
||||||
req.flash(req.session.flashType, req.session.flashMessage)
|
req.flash(req.session.flashType, req.session.flashMessage)
|
||||||
req.session.flashType = undefined
|
req.session.flashType = undefined
|
||||||
req.session.flashMessage = undefined
|
req.session.flashMessage = undefined
|
||||||
res.redirect(req.session.next || '/map')
|
res.redirect('/map'+(req.forNewUser)?'/map?new=1':'')
|
||||||
}
|
}
|
||||||
const appLoginCallback = (req, res, next) => {
|
const appLoginCallback = (req, res, next) => {
|
||||||
debug('appLoginCallback called.')
|
debug('appLoginCallback called.')
|
||||||
|
@ -44,8 +44,9 @@ module.exports = (app, passport) => {
|
||||||
.post(passport.authenticate('local', loginOutcome), loginCallback)
|
.post(passport.authenticate('local', loginOutcome), loginCallback)
|
||||||
app.get('/logout', (req, res) => {
|
app.get('/logout', (req, res) => {
|
||||||
req.logout()
|
req.logout()
|
||||||
|
debug(`Logged out, redirecting to /`)
|
||||||
req.flash('success', `You have been logged out.`)
|
req.flash('success', `You have been logged out.`)
|
||||||
res.redirect(req.session.next || '/')
|
res.redirect( '/')
|
||||||
})
|
})
|
||||||
|
|
||||||
// Signup
|
// Signup
|
||||||
|
|
|
@ -65,7 +65,7 @@ module.exports = router
|
||||||
text: req.body.message
|
text: req.body.message
|
||||||
})
|
})
|
||||||
req.flash('success', `Your message has been sent. `)
|
req.flash('success', `Your message has been sent. `)
|
||||||
res.redirect(req.session.next || '/')
|
res.redirect('/')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
mw.throwErr(err, req)
|
mw.throwErr(err, req)
|
||||||
res.redirect('/contact')
|
res.redirect('/contact')
|
||||||
|
|
|
@ -174,7 +174,7 @@ router.get('/email/:token', mw.ensureAuth, async (req, res, next) => {
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
mw.throwErr(err, req)
|
mw.throwErr(err, req)
|
||||||
res.redirect(req.session.next || '/settings')
|
res.redirect('/settings')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invalid token
|
// Invalid token
|
||||||
|
@ -296,7 +296,7 @@ router.route('/password/:token')
|
||||||
} else {
|
} else {
|
||||||
debug('New user created password')
|
debug('New user created password')
|
||||||
req.flash('success', 'Password set. You can use it to log in now. ')
|
req.flash('success', 'Password set. You can use it to log in now. ')
|
||||||
res.redirect('/login?next=/map?new=1')
|
res.redirect('/login')
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
11
server.js
11
server.js
|
@ -82,17 +82,6 @@ let ready_promise_list = []
|
||||||
|
|
||||||
// Default locals available to all views (keep this after static files)
|
// Default locals available to all views (keep this after static files)
|
||||||
app.get('*', (req, res, next) => {
|
app.get('*', (req, res, next) => {
|
||||||
// Path for redirects
|
|
||||||
let nextPath = (
|
|
||||||
(req.query.next) ? req.query.next
|
|
||||||
: req.path.substring(0, req.path.indexOf('#')) || req.path)
|
|
||||||
if (
|
|
||||||
nextPath.substring(0, 6) !== '/login'||'/admin' &&
|
|
||||||
nextPath.substring(0, 7) !== 'signup'||'/logout'||'/static'
|
|
||||||
) {
|
|
||||||
req.session.next = nextPath + '#'
|
|
||||||
debug(`Set redirect path to ${nextPath}#`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// User account
|
// User account
|
||||||
res.locals.user = req.user
|
res.locals.user = req.user
|
||||||
|
|
|
@ -109,7 +109,7 @@ describe('Authentication', () => {
|
||||||
.type('form').send({ 'password':TEST_PASSWORD })
|
.type('form').send({ 'password':TEST_PASSWORD })
|
||||||
|
|
||||||
// Expect redirect
|
// Expect redirect
|
||||||
chai.expect(res).to.redirectTo('/login?next=/map?new=1')
|
chai.expect(res).to.redirectTo('/login')
|
||||||
|
|
||||||
// Retrieve user with password saved
|
// Retrieve user with password saved
|
||||||
let passworded_user = await User.findOne({'email':TEST_EMAIL} )
|
let passworded_user = await User.findOne({'email':TEST_EMAIL} )
|
||||||
|
|
Loading…
Reference in New Issue