Skip to content

Commit bd9ca2a

Browse files
Merge pull request #113 from unknowndomain/master
Polishing for code review
2 parents 4b9f92d + 85d537a commit bd9ca2a

61 files changed

Lines changed: 2241 additions & 415 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/activate/app.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,22 @@ app.get( '/:activation_code' , function( req, res ) {
4040
} );
4141

4242
app.post( '/', function( req, res ) {
43-
if ( req.body.activation_code === undefined || req.body.password === undefined ) {
43+
if ( ! req.body.activation_code || ! req.body.password ) {
4444
req.flash( 'danger', messages['information-ommited'] );
4545
res.redirect( '/activate' );
4646
return;
4747
}
4848
if ( req.user ) {
4949
req.flash( 'warning', messages['already-logged-in'] );
5050
res.redirect( '/profile' );
51-
} else if ( req.body.activation_code.match( /^\w{20}$/ ) === null ) {
51+
} else if ( ! req.body.activation_code.match( /^\w{20}$/ ) ) {
5252
req.flash( 'danger', messages['activation-error'] );
5353
res.redirect( '/activate' );
5454
} else {
5555
Members.findOne( {
5656
activation_code: req.body.activation_code,
5757
}, function ( err, user ) {
58-
59-
if ( user === null ) {
58+
if ( ! user ) {
6059
req.flash( 'danger', messages['activation-error'] );
6160
res.redirect( app.mountpath + '/' + req.body.activation_code );
6261
return;

apps/activate/views/index.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ block contents
1313
.form-group
1414
label( for="activation_code" ).col-md-2 Activation code:
1515
.col-md-4
16-
input( name="activation_code", type="text", value=activation_code, ( activation_code ? readonly : null ) )#activation_code.form-control
16+
input( name="activation_code", type="text", value=activation_code, readonly=( activation_code ? true : false ) )#activation_code.form-control
1717
.form-group
1818
label( for="password" ).col-md-2 Password:
1919
.col-md-4

apps/api/app.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var app_config = {};
2323
app.get( '/permission/:slug/:tag', auth.isAPIAuthenticated, function( req, res ) {
2424
Members.findOne( { 'tag.hashed': req.params.tag } ).populate( 'permissions.permission' ).exec( function( err, member ) {
2525
var grantAccess = false;
26-
if ( member !== null ) {
26+
if ( member ) {
2727
var hasMembership = false;
2828
var hasPermission = false;
2929
var isSuperAdmin = false;
@@ -65,7 +65,7 @@ app.get( '/permission/:slug/:tag', auth.isAPIAuthenticated, function( req, res )
6565

6666
app.get( '/event/:slug', auth.isAPIAuthenticated, function( req, res ) {
6767
Activities.findOne( { slug: req.params.slug }, function ( err, activity ) {
68-
if ( activity !== null ) {
68+
if ( activity ) {
6969
new Events( {
7070
activity: activity._id,
7171
action: ( req.query.action ? req.query.action : '' )
@@ -115,9 +115,7 @@ app.get( '/events', auth.isAPIAuthenticated, function( req, res ) {
115115
results: events.length,
116116
events: []
117117
};
118-
console.log( events.length );
119118
for ( var e in events ) {
120-
console.log( e );
121119
var event = events[e];
122120
var output_event = {
123121
date: event.happened

apps/events/app.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ app.get( '/', auth.isMember, function( req, res ) {
3939
startDate.setSeconds( 0 );
4040
startDate.setMilliseconds( 0 );
4141

42-
if ( req.query.month !== undefined && req.query.year !== undefined ) {
42+
if ( req.query.month && req.query.year ) {
4343
startDate.setMonth( req.query.month - 1 );
4444
startDate.setYear( req.query.year );
4545
}
@@ -52,26 +52,26 @@ app.get( '/', auth.isMember, function( req, res ) {
5252
}
5353
};
5454
// FILTER: Permission Success
55-
if ( req.query.successful && req.query.unsuccessful === undefined ) search.successful = { $ne: false };
56-
if ( req.query.unsuccessful && req.query.successful === undefined ) search.successful = false;
55+
if ( req.query.successful && ! req.query.unsuccessful ) search.successful = { $ne: false };
56+
if ( req.query.unsuccessful && ! req.query.successful ) search.successful = false;
5757

5858
// FILTER: Permission
5959
Permissions.findOne( { slug: req.query.permission }, function( err, permission ) {
60-
if ( permission !== null ) {
60+
if ( permission ) {
6161
search.permission = permission._id;
6262
}
6363

6464
// FILTER: Activities
6565
Activities.findOne( { slug: req.query.activity }, function( err, activity ) {
66-
if ( activity !== null ) {
66+
if ( activity ) {
6767
search.activity = activity._id;
6868
}
6969

7070
// Find event
7171
Events.find( search ).populate( 'member' ).populate( 'permission' ).populate( 'activity' ).sort( [ [ "happened", -1 ] ] ).exec( function( err, events ) {
7272
if ( res.locals.access.indexOf( 'admin' ) == -1 ) {
7373
events = events.filter( function( e ) {
74-
if ( e.activity !== undefined )
74+
if ( e.activity )
7575
return ! e.activity.admin_only;
7676
return true;
7777
} );
@@ -95,15 +95,11 @@ app.get( '/', auth.isMember, function( req, res ) {
9595
selected.admin_only = '';
9696
}
9797

98-
if ( auth.canAdmin( req ) && req.query.admin_only !== undefined && req.query.admin_only == 'on' ) {
98+
if ( auth.canAdmin( req ) && req.query.admin_only && req.query.admin_only == 'on' ) {
9999
events = events.filter( function ( event ) {
100-
if ( event.activity !== undefined ) {
101-
if ( event.activity.admin_only !== undefined ) {
102-
if ( event.activity.admin_only === true ) {
103-
return true;
104-
} else {
105-
return false;
106-
}
100+
if ( event.activity ) {
101+
if ( event.activity.admin_only ) {
102+
return true;
107103
} else {
108104
return false;
109105
}

apps/events/views/partials/event.pug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if event.successful || ( ! event.successful && event.permission.event_unauthoris
2828

2929
if relative
3030
span.badge
31-
time( datetime=moment( event.happened, moment.ISO_8601 ), title=moment( event.happened ).format( 'HH:mm:ss d/m/Y' ) ) #{ moment( event.happened ).fromNow() }
31+
time( datetime=moment( event.happened, moment.ISO_8601 ), title=moment( event.happened ).format( 'HH:mm:ss D/M/Y' ) ) #{ moment( event.happened ).fromNow() }
3232
else
3333
span.badge
34-
time( datetime=moment( event.happened, moment.ISO_8601 ), title=moment( event.happened ).format( 'HH:mm:ss d/M/Y' ) ) #{ moment( event.happened ).format( 'HH:mm' ) }
34+
time( datetime=moment( event.happened, moment.ISO_8601 ), title=moment( event.happened ).format( 'HH:mm:ss D/M/Y' ) ) #{ moment( event.happened ).format( 'HH:mm' ) }

apps/home/views/index.pug

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
extends ../../../src/views/base.pug
22

33
block navbar
4-
.jumbotron
5-
h1 Welcome...
6-
p #{ config.about.text }
7-
p: a( href=config.about.link.url, target="_blank").btn.btn-primary #{ config.about.link.text }
8-
.bg
94

105
block contents
6+
.row
7+
.col-md-12
8+
h2
9+
strong #{ config.organisation }
10+
br
11+
| #{ config.title }
12+
h4 #{ config.about.text }
13+
p: a( href=config.about.link.url, target="_blank").btn #{ config.about.link.text }
14+
.bg
1115
.row
1216
.col-md-6
1317
.page-header
14-
h2 Join
15-
p: a( href="/join" ).btn.btn-primary.btn-block Join Now
18+
h3 New member
19+
p Becoming a new member is straightforward, click below to get started.
20+
a( href="/join" ).btn.btn-primary Join
1621
.col-md-6
1722
.page-header
18-
h2 Login
23+
h3 Existing member
1924
include ../../login/views/partials/form.pug
25+

apps/join/app.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ app.get( '/' , function( req, res ) {
4444
} );
4545

4646
app.post( '/', function( req, res ) {
47-
if ( req.body.firstname === undefined ||
48-
req.body.lastname === undefined ||
49-
req.body.password === undefined ||
50-
req.body.verify === undefined ||
51-
req.body.email === undefined ||
52-
req.body.address === undefined ) {
53-
req.flash( 'danger', messages['information-ommited'] );
54-
res.redirect( app.mountpath );
55-
return;
56-
}
57-
5847
if ( req.user ) {
5948
req.flash( 'warning', messages['already-logged-in'] );
6049
res.redirect( '/profile' );
@@ -66,17 +55,19 @@ app.post( '/', function( req, res ) {
6655
address: req.body.address,
6756
};
6857

69-
if ( req.body.firstname === '' ) {
58+
if ( ! req.body.firstname ) {
7059
req.flash( 'danger', messages['user-firstname'] );
7160
res.render( 'index', { user: user } );
7261
return;
7362
}
74-
if ( req.body.lastname === '' ) {
63+
64+
if ( ! req.body.lastname ) {
7565
req.flash( 'danger', messages['user-lastname'] );
7666
res.render( 'index', { user: user } );
7767
return;
7868
}
79-
if ( req.body.address === '' ) {
69+
70+
if ( ! req.body.address ) {
8071
req.flash( 'danger', messages['user-address'] );
8172
res.render( 'index', { user: user } );
8273
return;
@@ -98,11 +89,11 @@ app.post( '/', function( req, res ) {
9889
var postcode = '';
9990
var results = req.body.address.match( /([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)/ );
10091

101-
if ( results !== undefined ) {
92+
if ( results ) {
10293
postcode = results[0];
10394
}
10495
postcodes.lookup( postcode, function( err, data ) {
105-
if ( data !== undefined ) {
96+
if ( data ) {
10697
user.postcode_coordinates = {
10798
lat: data.latitude,
10899
lng: data.longitude,
@@ -120,8 +111,8 @@ app.post( '/', function( req, res ) {
120111

121112
// Store new member
122113
new Members( user ).save( function( status ) {
123-
if ( status !== null ) {
124-
if ( status.errors !== undefined ) {
114+
if ( status ) {
115+
if ( status.errors ) {
125116
var keys = Object.keys( status.errors );
126117
for ( var k in keys ) {
127118
var key = keys[k];

apps/join/views/index.pug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ block contents
5252
.form-group
5353
label( for="address" ).col-md-3 Address
5454
.col-md-5
55-
textarea( name="address" )#address.form-control #{ user.address }
55+
textarea( name="address", rows=4 )#address.form-control #{ user.address }
5656
hr
5757
.form-group
5858
.col-md-12
5959
button.btn.btn-primary.pull-right Next
6060
span.glyphicon.glyphicon-chevron-right
6161
.col-md-4
6262
.page-header
63-
h2 Already a member?
63+
h2 Existing member
6464
p If you are already a member you can just login...
6565
include ../../login/views/partials/form.pug

apps/login/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ app.post( '/', passport.authenticate( 'local', {
3333
successFlash: true
3434
} ), function ( req, res ) {
3535
req.session.method = 'plain';
36-
if ( req.session.requestedUrl !== undefined ) {
36+
if ( req.session.requestedUrl ) {
3737
res.redirect( req.session.requestedUrl );
3838
delete req.session.requestedUrl;
3939
} else {

apps/login/views/partials/form.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ form( method="post", action="/login" )
99
.form-group
1010
button( role="button" ).btn.btn-primary Login
1111
|  
12-
a( href="/password-reset" ).btn.btn-default Reset Password
12+
a( href="/password-reset" ).btn.btn-default Forgotten Password

0 commit comments

Comments
 (0)