@@ -10,19 +10,12 @@ var mongoose = require('mongoose'),
1010exports . create = function ( req , res , next ) {
1111 var newUser = new User ( req . body ) ;
1212 newUser . provider = 'local' ;
13-
1413 newUser . save ( function ( err ) {
15- if ( err ) {
16- // Manually provide our own message for 'unique' validation errors, can't do it from schema
17- if ( err . errors . email . type === 'Value is not unique.' ) {
18- err . errors . email . type = 'The specified email address is already in use.' ;
19- }
20- return res . json ( 400 , err ) ;
21- }
22-
14+ if ( err ) return next ( err ) ;
15+
2316 req . logIn ( newUser , function ( err ) {
2417 if ( err ) return next ( err ) ;
25-
18+
2619 return res . json ( req . user . userInfo ) ;
2720 } ) ;
2821 } ) ;
@@ -35,13 +28,10 @@ exports.show = function (req, res, next) {
3528 var userId = req . params . id ;
3629
3730 User . findById ( userId , function ( err , user ) {
38- if ( err ) return next ( new Error ( 'Failed to load User' ) ) ;
39-
40- if ( user ) {
41- res . send ( { profile : user . profile } ) ;
42- } else {
43- res . send ( 404 , 'USER_NOT_FOUND' ) ;
44- }
31+ if ( err ) return next ( err ) ;
32+ if ( ! user ) return res . send ( 404 ) ;
33+
34+ res . send ( { profile : user . profile } ) ;
4535 } ) ;
4636} ;
4737
@@ -55,17 +45,14 @@ exports.changePassword = function(req, res, next) {
5545
5646 User . findById ( userId , function ( err , user ) {
5747 if ( user . authenticate ( oldPass ) ) {
58-
5948 user . password = newPass ;
6049 user . save ( function ( err ) {
61- if ( err ) {
62- res . send ( 500 , err ) ;
63- } else {
64- res . send ( 200 ) ;
65- }
50+ if ( err ) return res . send ( 400 ) ;
51+
52+ res . send ( 200 ) ;
6653 } ) ;
6754 } else {
68- res . send ( 400 ) ;
55+ res . send ( 403 ) ;
6956 }
7057 } ) ;
7158} ;
0 commit comments