File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,18 @@ module.exports = function(app, passport){
5050 return cb ( null , false , { message :"User already registered" } ) ;
5151 }
5252 else {
53- app . db . users . insert ( { username : username , password :password } ) ;
53+ // Must not be the same as admins
54+ app . db . admins . findOne ( { username : username } , function ( err , user ) {
55+ if ( err ) {
56+ return cb ( err ) ;
57+ }
58+ if ( user ) {
59+ return cb ( null , false , { message :"User already registered" } ) ;
60+ }
61+ else {
62+ app . db . users . insert ( { username : username , password :password } ) ;
63+ }
64+ } ) ;
5465 }
5566 } ) ;
5667 } else
Original file line number Diff line number Diff line change @@ -364,7 +364,7 @@ function rescanItem(req) {
364364 app . db . songs . find ( { _id : { $in : items } } , function ( err , songs ) {
365365 if ( ! err && songs )
366366
367- // add the location to the list of songs to scan
367+ // add the location to the list of songs to scan
368368 for ( var i = 0 ; i < songs . length ; i ++ ) {
369369 songLocArr . push ( songs [ i ] . location ) ;
370370 }
@@ -655,3 +655,31 @@ function getYoutubeSongs(req) {
655655 } ) ;
656656 } ) ;
657657}
658+
659+ function isUser ( req , res , next ) {
660+ if ( req . isAuthenticated ( ) ) {
661+ app . db . users . findOne ( { username : req . user . username } , function ( err , user ) {
662+ if ( ! user ) {
663+ res . redirect ( '/login' ) ;
664+ } else {
665+ return next ( ) ;
666+ }
667+ } ) ;
668+ } else {
669+ res . redirect ( '/login?notAuth' ) ;
670+ }
671+ }
672+
673+ function isAdmin ( req , res , next ) {
674+ if ( req . isAuthenticated ( ) ) {
675+ app . db . admin . findOne ( { username : req . user . username } , function ( err , user ) {
676+ if ( ! user ) {
677+ res . redirect ( '/admin' ) ;
678+ } else {
679+ return next ( ) ;
680+ }
681+ } ) ;
682+ } else {
683+ res . redirect ( '/admin?notAuth' ) ;
684+ }
685+ }
You can’t perform that action at this time.
0 commit comments