@@ -22,7 +22,7 @@ var options = require('./utils/options')();
2222// For any other GET request, proxy it on to MarkLogic.
2323router . get ( '*' , function ( req , res ) {
2424 noCache ( res ) ;
25- if ( ! options . guestAccess && req . session . user === undefined ) {
25+ if ( ! options . guestAccess && ( req . session . user === undefined ) ) {
2626 res . status ( 401 ) . send ( 'Unauthorized' ) ;
2727 } else {
2828 proxy ( req , res ) ;
@@ -35,24 +35,21 @@ router.put('*', function(req, res) {
3535 // For PUT requests, require authentication
3636 if ( req . session . user === undefined ) {
3737 res . status ( 401 ) . send ( 'Unauthorized' ) ;
38- } else if ( options . disallowUpdates || ( req . path === '/v1/ documents' &&
38+ } else if ( options . disallowUpdates || ( ( req . path === '/documents' ) &&
3939 req . query . uri . match ( '/api/users/' ) &&
40- req . query . uri . match ( new RegExp ( '/api/users/[^( ' + req . session . user . username + ')]+ .json' ) ) ) ) {
40+ ! req . query . uri . match ( '/api/users/' + req . session . user . username + '.json' ) ) ) {
4141 // The user is trying to PUT to a profile document other than his/her own. Not allowed.
4242 res . status ( 403 ) . send ( 'Forbidden' ) ;
4343 } else {
44- if ( req . path === '/v1/documents' && req . query . uri . match ( '/users/' ) ) {
45- var json = req . body . user ? req . body : JSON . parse ( req . body ) ;
46- req . session . user . profile = json . user ;
47- }
44+ // proxy original request
4845 proxy ( req , res ) ;
4946 }
5047} ) ;
5148
5249// Require authentication for POST requests
5350router . post ( / ^ \/ ( a l e r t \/ m a t c h | s e a r c h | s u g g e s t | v a l u e s \/ .* ) $ / , function ( req , res ) {
5451 noCache ( res ) ;
55- if ( ! options . guestAccess && req . session . user === undefined ) {
52+ if ( ! options . guestAccess && ( req . session . user === undefined ) ) {
5653 res . status ( 401 ) . send ( 'Unauthorized' ) ;
5754 } else {
5855 proxy ( req , res ) ;
@@ -83,7 +80,8 @@ router.delete('*', function(req, res) {
8380
8481function getAuth ( options , session ) {
8582 var auth = null ;
86- if ( session . user !== undefined && session . user . username !== undefined ) {
83+
84+ if ( ( session . user !== undefined ) && ( session . user . username !== undefined ) ) {
8785 auth = session . user . username + ':' + session . user . password ;
8886 }
8987 else {
0 commit comments