@@ -15,18 +15,17 @@ exports.register = (req, res) => {
1515
1616 let resObj = { } ;
1717 let Common = new helperLib . common . common ( ) ;
18-
1918 if ( err ) {
2019 let message = err . code == '11000' ? `${ req . body . email } ${ helperLib . messages . alreadyTaken } ` : 'Registration failed' ;
21- resObj = Common . generateResponses ( 400 , 'failed' , message , err ) ;
20+ resObj = Common . generateResponses ( 400 , 'failed' , message , err . code == '11000' ? null : err ) ;
2221 } else {
2322 saved . password = undefined ;
2423 resObj = Common . generateResponses ( 200 , 'success' , helperLib . messages . accoundCreated , null , saved ) ;
2524 }
2625
2726 res . status ( resObj . statusCode ) . json ( resObj ) ;
2827
29- } )
28+ } ) ;
3029}
3130
3231
@@ -146,26 +145,19 @@ exports.changePassword = (req, res) => {
146145
147146 //@ check new password with confirm password
148147 if ( req . body . confirmPassword != req . body . newPassword ) {
149-
150148 let resObj = Common . generateResponses ( 400 , 'failed' , 'New password and comfirm password are not equal' ) ;
151-
152- cb ( resObj ) ;
153-
149+ cb ( resObj ) ;
154150 } else {
155151 cb ( null ) ;
156152 }
157-
158153 } ,
159154
160155 ( cb ) => {
161156 //@ unauthorized request
162157 //@ if user make a request by stealing another user`s token
163158 if ( req . body . email != req . tokenInfo . email ) {
164-
165159 let resObj = Common . generateResponses ( 401 , 'failed' , `unauthorized request: password can not update` ) ;
166-
167- cb ( resObj ) ;
168-
160+ cb ( resObj ) ;
169161 } else {
170162 cb ( null ) ;
171163 }
@@ -183,24 +175,16 @@ exports.changePassword = (req, res) => {
183175 let isValid = Crypt . compareHash ( req . body . password , user ? user . password : '' )
184176
185177 if ( ! user || err || ! isValid ) {
186-
187178 let message = err ? 'something went wrong when finding user'
188179 : ! user
189180 ? 'user not found'
190- : 'incorrect current password' ;
191-
192- let resObj = Common . generateResponses ( 400 , 'failed' , message , err ) ;
193-
181+ : 'incorrect current password' ;
182+ let resObj = Common . generateResponses ( 400 , 'failed' , message , err ) ;
194183 cb ( resObj ) ;
195-
196184 } else {
197-
198- cb ( null ) ;
199-
185+ cb ( null ) ;
200186 }
201-
202- } )
203-
187+ } ) ;
204188 } ,
205189
206190 ( cb ) => {
@@ -210,29 +194,18 @@ exports.changePassword = (req, res) => {
210194
211195 //@ update user password
212196 UserProfileModel . update ( conditions , update , ( err , update ) => {
213-
214197 if ( update . nModified == 1 ) {
215-
216198 let resObj = Common . generateResponses ( 200 , 'success' , 'password changed successfully' ) ;
217-
218199 cb ( resObj ) ;
219-
220200 } else {
221-
222201 let resObj = Common . generateResponses ( 400 , 'failed' , 'some error occurred in update password' , err ) ;
223-
224202 cb ( resObj ) ;
225203 }
226-
227204 } ) ;
228-
229- }
230- ] , ( err , final ) => {
205+ } ] , ( err , final ) => {
231206
232207 let resObj = err || final ;
233-
234208 res . status ( resObj . statusCode ) . json ( resObj ) ;
235-
236209 } )
237210}
238211
0 commit comments