File tree 4 files changed +111
-20
lines changed
4 files changed +111
-20
lines changed Original file line number Diff line number Diff line change @@ -76,15 +76,15 @@ git clone https://github.com/SystangoTechnologies/Koach.git
76
76
├── src # Source code
77
77
│ ├── modules # Module-specific controllers
78
78
│ │ ├── common # Contains common modules
79
- │ │ │ ├─── home
79
+ │ │ │ ├─── home
80
80
│ │ │ └─ index.js
81
81
│ │ ├── v1 # Version 1 of APIs
82
82
│ │ │ ├─ Auth
83
- │ │ │ ├─ User
84
- │ │ │ └─ index.js
83
+ │ │ │ ├─ User
84
+ │ │ │ └─ index.js
85
85
│ │ └─── v2 # Version 2 of APIs
86
86
│ │ ├─ Auth
87
- │ │ ├─ User
87
+ │ │ ├─ User
88
88
│ │ └─ index.js
89
89
│ ├── models # Mongoose models
90
90
│ └── middleware # Custom middleware
@@ -109,7 +109,7 @@ Prerequisite For Docker Configuration : Docker and docker compose must be instal
109
109
Steps to run app in docker container :
110
110
1 . CD to project dir
111
111
2 . Create build using cmd: $ docker-compose build
112
- 3 . Start the server in daemon thread using cmd: $ docker-compose up -d
112
+ 3 . Start the server in daemon thread using cmd: $ docker-compose up -d
113
113
4 . Stop the server using cmd : $ docker-compose down
114
114
115
115
## Documentation
@@ -135,6 +135,7 @@ The environment for the test cases are following-
135
135
[ Arpit Khandelwal] ( https://github.com/arpit-systango )
136
136
[ Anurag Vikram Singh] ( https://www.linkedin.com/in/anuragvikramsingh/ )
137
137
[ Vikas Patidar] ( https://www.linkedin.com/in/vikas-patidar-0106/ )
138
+ [ Sparsh Pipley] ( https://www.linkedin.com/in/sparsh-pipley-6ab0b1a4/ )
138
139
139
140
## License
140
141
MIT.
Original file line number Diff line number Diff line change @@ -237,3 +237,61 @@ export async function deleteUser(ctx) {
237
237
ctx . status = constants . STATUS_CODE . INTERNAL_SERVER_ERROR_STATUS
238
238
}
239
239
}
240
+
241
+ /**
242
+ * @api {patch } /v1/users/_change-password Upadete password of a user
243
+ * @apiPermission
244
+ * @apiVersion 1.0.0
245
+ * @apiName changePassword
246
+ * @apiGroup Users
247
+ *
248
+ * @apiExample Example usage:
249
+ * curl -H "Content-Type: application/json" -X PATCH -d '{ "oldPassword":"oldPassword", "newPassword": "newPassword" }' localhost:3000/v1/users/_changePassword
250
+ *
251
+ * @apiSuccess {StatusCode} 200
252
+ *
253
+ * @apiSuccessExample {json} Success-Response:
254
+ * HTTP/1.1 200 OK
255
+ * {
256
+ * "success": true
257
+ * }
258
+ *
259
+ * @apiUse TokenError
260
+ */
261
+
262
+ export async function changePassword ( ctx ) {
263
+ try {
264
+ let oldPassword = ctx . request . body . oldPassword
265
+ let newPassword = ctx . request . body . newPassword
266
+
267
+ if ( ! newPassword || ! oldPassword ) {
268
+ ctx . status = constants . STATUS_CODE . BAD_REQUEST_ERROR_STATUS
269
+ return
270
+ }
271
+
272
+ let user = await User . findOne ( {
273
+ _id : mongoose . Types . ObjectId ( ctx . state . user . id )
274
+ } )
275
+
276
+ let isMatch = await user . validatePassword ( oldPassword )
277
+
278
+ if ( isMatch ) {
279
+ user . password = newPassword
280
+ user . save ( ) ;
281
+ ctx . status = constants . STATUS_CODE . SUCCESS_STATUS ;
282
+ ctx . body = {
283
+ success : true
284
+ }
285
+ return
286
+ } else {
287
+ ctx . body = {
288
+ success : false
289
+ }
290
+ ctx . status = constants . STATUS_CODE . UNAUTHORIZED_ERROR_STATUS
291
+ return
292
+ }
293
+ } catch ( error ) {
294
+ ctx . body = error ;
295
+ ctx . status = constants . STATUS_CODE . INTERNAL_SERVER_ERROR_STATUS
296
+ }
297
+ }
Original file line number Diff line number Diff line change @@ -42,5 +42,13 @@ export default [
42
42
ensureUser ,
43
43
user . deleteUser
44
44
]
45
+ } ,
46
+ {
47
+ method : 'PATCH' ,
48
+ route : '/_change-password' ,
49
+ handlers : [
50
+ ensureUser ,
51
+ user . changePassword
52
+ ]
45
53
}
46
54
]
You can’t perform that action at this time.
0 commit comments