mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
tweaking messages and status codes for user login
This commit is contained in:
parent
a528811e35
commit
490340fbb0
38
lib/index.js
38
lib/index.js
@ -205,21 +205,31 @@ module.exports = function(config_hash) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
app.put('/-/user/:org_couchdb_user', function(req, res, next) {
|
app.put('/-/user/:org_couchdb_user/:_rev?/:revision?', function(req, res, next) {
|
||||||
if (req.remoteUser != null) {
|
if (req.remoteUser != null) {
|
||||||
res.status(200)
|
res.status(201)
|
||||||
return res.send({
|
return res.send({
|
||||||
ok: 'you are authenticated as "' + req.remoteUser + '"',
|
ok: 'you are authenticated as "' + req.remoteUser + '"',
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (typeof(req.body.name) !== 'string' || typeof(req.body.password) !== 'string') {
|
if (typeof(req.body.name) !== 'string' || typeof(req.body.password) !== 'string') {
|
||||||
res.status(409)
|
return next(new UError({
|
||||||
return res.send({
|
status: 400,
|
||||||
ok: 'user/password is not found in request (npm issue?)',
|
message: 'user/password is not found in request (npm issue?)',
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
config.add_user(req.body.name, req.body.password, function(err) {
|
config.add_user(req.body.name, req.body.password, function(err) {
|
||||||
if (err) return next(err)
|
if (err) {
|
||||||
|
if (err.status < 500 && err.message === 'this user already exists') {
|
||||||
|
// with npm registering is the same as logging in
|
||||||
|
// so we replace message in case of conflict
|
||||||
|
return next(new UError({
|
||||||
|
status: 409,
|
||||||
|
message: 'bad username/password, access denied'
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
return next(err)
|
||||||
|
}
|
||||||
|
|
||||||
res.status(201)
|
res.status(201)
|
||||||
return res.send({
|
return res.send({
|
||||||
@ -229,20 +239,6 @@ module.exports = function(config_hash) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.put('/-/user/:org_couchdb_user/-rev/*', function(req, res, next) {
|
|
||||||
if (req.remoteUser == null) {
|
|
||||||
res.status(403)
|
|
||||||
return res.send({
|
|
||||||
error: 'bad username/password, access denied',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
res.status(201)
|
|
||||||
return res.send({
|
|
||||||
ok: 'you are authenticated as "' + req.remoteUser + '"',
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// tagging a package
|
// tagging a package
|
||||||
app.put('/:package/:tag', can('publish'), media('application/json'), function(req, res, next) {
|
app.put('/:package/:tag', can('publish'), media('application/json'), function(req, res, next) {
|
||||||
if (typeof(req.body) !== 'string') return next('route')
|
if (typeof(req.body) !== 'string') return next('route')
|
||||||
|
Loading…
Reference in New Issue
Block a user