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){
50
50
return cb ( null , false , { message :"User already registered" } ) ;
51
51
}
52
52
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
+ } ) ;
54
65
}
55
66
} ) ;
56
67
} else
Original file line number Diff line number Diff line change @@ -364,7 +364,7 @@ function rescanItem(req) {
364
364
app . db . songs . find ( { _id : { $in : items } } , function ( err , songs ) {
365
365
if ( ! err && songs )
366
366
367
- // add the location to the list of songs to scan
367
+ // add the location to the list of songs to scan
368
368
for ( var i = 0 ; i < songs . length ; i ++ ) {
369
369
songLocArr . push ( songs [ i ] . location ) ;
370
370
}
@@ -655,3 +655,31 @@ function getYoutubeSongs(req) {
655
655
} ) ;
656
656
} ) ;
657
657
}
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