diff --git a/api/routes/user.js b/api/routes/user.js index 63e5da8f3..ae5c13bbe 100644 --- a/api/routes/user.js +++ b/api/routes/user.js @@ -119,6 +119,7 @@ function authenticate(req, res, next) { } req.user = result; + req.user.password = auth.password; next(); }); @@ -146,16 +147,22 @@ function authenticate(req, res, next) { email: result.email }; + // attach the password in case it was sent via auth headers + var auth = extractCredentialsFromHeaders(req); + if (auth && auth.username === result.username) { + req.user.password = auth.password; + } + next(); }); } - if (req.headers.authorization) { - debug('using login authentication'); - loginAuthenticator(req, res, next); - } else if (req.query.auth_token || req.cookies.token) { + if (req.query.auth_token || req.cookies.token) { debug('using token based authentication'); tokenAuthenticator(req, res, next); + } else if (req.headers.authorization) { + debug('using login authentication'); + loginAuthenticator(req, res, next); } else { next(new HttpError(401, 'No credentials')); } diff --git a/api/routes/volume.js b/api/routes/volume.js index 2228c2291..f94f7ffd9 100644 --- a/api/routes/volume.js +++ b/api/routes/volume.js @@ -1,6 +1,7 @@ 'use strict'; var HttpError = require('../httperror'), + user = require('../user.js'), volume = require('../volume.js'); exports = module.exports = { @@ -46,21 +47,29 @@ function listVolumes(req, res, next) { function createVolume(req, res, next) { if (!req.body.name) { - return next(new HttpError(400, 'volume name not specified')); + return next(new HttpError(400, 'New volume name not specified')); } - if (volume.get(req.body.name, req.user.username, config)) { - return next(new HttpError(409, 'volume already exists')); + if (!req.user.password) { + return next(new HttpError(400, 'Password not specified')); } - // TODO use real password, would help :-) - Johannes - var password = 'foobar1337'; - volume.create(req.body.name, req.user.username, req.user.email, password, config, function (error, result) { + user.verify(req.user.username, req.user.password, function (error, result) { if (error) { - return next(new HttpError(500, 'volume creation failed: ' + error)); + return next(new HttpError(401, 'Wrong password entered')); } - res.send(201); + if (volume.get(req.body.name, req.user.username, config)) { + return next(new HttpError(409, 'Volume already exists')); + } + + volume.create(req.body.name, req.user.username, req.user.email, req.user.password, config, function (error, result) { + if (error) { + return next(new HttpError(500, 'Volume creation failed: ' + error)); + } + + res.send(201); + }); }); } diff --git a/webadmin/dashboard.html b/webadmin/dashboard.html index e2b03c727..5e59b6234 100644 --- a/webadmin/dashboard.html +++ b/webadmin/dashboard.html @@ -70,13 +70,19 @@