@@ -72,7 +72,9 @@ router.route('/poll')
7272 poll . id = makeid ( ) ;
7373 poll . name = req . body . name ; // set the poll name (comes from the request)
7474 poll . multiple = req . body . multiple ;
75+ poll . singleIP = req . body . singleIP ;
7576 poll . answers = req . body . answers ;
77+ poll . IpAddresses = [ ] ;
7678 poll . votes = req . body . votes ;
7779 poll . save ( function ( err , poll ) {
7880 if ( err )
@@ -113,14 +115,33 @@ router.route('/poll/:poll_id')
113115 if ( err ) {
114116 res . send ( err ) ;
115117 }
116-
117- for ( x = 0 ; x < req . body . votes . length ; x ++ ) {
118- if ( req . body . votes [ x ] != null ) {
119- poll . votes [ x ] += req . body . votes [ x ] ;
118+ if ( poll . singleIP == true ) {
119+ var ip = req . headers [ 'x-forwarded-for' ] ||
120+ req . connection . remoteAddress ||
121+ req . socket . remoteAddress ||
122+ req . connection . socket . remoteAddress ;
123+
124+ if ( poll . IpAddresses . indexOf ( ip ) > - 1 ) {
125+ //In the array!
126+ } else {
127+ poll . IpAddresses . push ( ip ) ;
128+ for ( x = 0 ; x < req . body . votes . length ; x ++ ) {
129+ if ( req . body . votes [ x ] != null ) {
130+ poll . votes [ x ] += req . body . votes [ x ] ;
131+ }
132+ }
133+ poll . markModified ( 'IpAddresses' ) ;
134+ poll . markModified ( 'votes' ) ;
135+ }
136+ } else {
137+ for ( x = 0 ; x < req . body . votes . length ; x ++ ) {
138+ if ( req . body . votes [ x ] != null ) {
139+ poll . votes [ x ] += req . body . votes [ x ] ;
140+ }
120141 }
142+ poll . markModified ( 'votes' ) ;
121143 }
122-
123- poll . markModified ( 'votes' ) ;
144+
124145 poll . save ( function ( err ) {
125146 io . emit ( 'chat' + req . params . poll_id , poll ) ;
126147 if ( err ) {
0 commit comments